2008-04-27 23:13:42 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								! Copyright (C) 2008 James Cash
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								! See http://factorcode.org/license.txt for BSD license.
							 | 
						
					
						
							
								
									
										
										
										
											2008-09-08 02:09:52 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								USING: kernel peg peg.ebnf math.parser sequences arrays strings
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-24 14:47:54 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								combinators.lib math fry accessors lists combinators.short-circuit ;
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-26 15:55:39 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								IN: lisp.parser
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								TUPLE: lisp-symbol name ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								C: <lisp-symbol> lisp-symbol
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								EBNF: lisp-expr
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								_            = (" " | "\t" | "\n")*
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								LPAREN       = "("
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								RPAREN       = ")"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								dquote       = '"'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								squote       = "'"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								digit        = [0-9]
							 | 
						
					
						
							
								
									
										
										
										
											2008-05-14 02:19:21 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								integer      = ("-")? (digit)+                           => [[ first2 append string>number ]]
							 | 
						
					
						
							
								
									
										
										
										
											2008-05-23 23:48:58 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								float        = integer "." (digit)*                      => [[ first3 >string [ number>string ] 2dip 3append string>number ]]
							 | 
						
					
						
							
								
									
										
										
										
											2008-05-14 02:19:21 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								rational     = integer "/" (digit)+                      => [[ first3 nip string>number / ]]
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-26 15:55:39 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								number       = float
							 | 
						
					
						
							
								
									
										
										
										
											2008-05-14 02:19:21 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								              | rational
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-26 15:55:39 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              | integer
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-01 18:50:22 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								id-specials  = "!" | "$" | "%" | "&" | "*" | "/" | ":"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              | "<" | "#" | " =" | ">" | "?" | "^" | "_"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              | "~" | "+" | "-" | "." | "@"
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-30 17:00:20 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								letters      = [a-zA-Z]                                  => [[ 1array >string ]]
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-26 15:55:39 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								initials     = letters | id-specials
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-30 17:00:20 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								numbers      = [0-9]                                     => [[ 1array >string ]]
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-26 15:55:39 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								subsequents  = initials | numbers
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-30 17:00:20 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								identifier   = initials (subsequents)*                   => [[ first2 concat append <lisp-symbol> ]]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								escaped      = "\" .                                     => [[ second ]]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								string       = dquote ( escaped | !(dquote) . )*  dquote => [[ second >string ]]
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-26 15:55:39 -04:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								atom         = number
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              | identifier
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								              | string
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-01 18:50:22 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								s-expression = LPAREN (list-item)* RPAREN                => [[ second seq>cons ]]
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-10 01:44:38 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								list-item    = _ ( atom | s-expression ) _               => [[ second ]]
							 | 
						
					
						
							
								
									
										
										
										
											2008-04-27 03:03:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								;EBNF
							 |