2008-04-27 23:13:42 -04:00
|
|
|
! Copyright (C) 2008 James Cash
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-04-26 15:55:39 -04:00
|
|
|
USING: kernel peg.ebnf peg.expr math.parser sequences arrays strings
|
|
|
|
combinators.lib ;
|
|
|
|
|
|
|
|
IN: lisp.parser
|
|
|
|
|
|
|
|
TUPLE: lisp-symbol name ;
|
|
|
|
C: <lisp-symbol> lisp-symbol
|
|
|
|
|
2008-04-27 03:03:49 -04:00
|
|
|
TUPLE: s-exp body ;
|
|
|
|
C: <s-exp> s-exp
|
|
|
|
|
2008-04-26 15:55:39 -04:00
|
|
|
EBNF: lisp-expr
|
|
|
|
_ = (" " | "\t" | "\n")*
|
|
|
|
LPAREN = "("
|
|
|
|
RPAREN = ")"
|
|
|
|
dquote = '"'
|
|
|
|
squote = "'"
|
|
|
|
digit = [0-9]
|
2008-05-02 03:11:10 -04:00
|
|
|
integer = (digit)+ => [[ string>number ]]
|
|
|
|
float = (digit)+ "." (digit)* => [[ first3 >string [ >string ] dipd 3append string>number ]]
|
2008-04-26 15:55:39 -04:00
|
|
|
number = float
|
|
|
|
| integer
|
|
|
|
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-04-30 17:00:20 -04:00
|
|
|
list-item = _ (atom|s-expression) _ => [[ second ]]
|
|
|
|
s-expression = LPAREN (list-item)* RPAREN => [[ second <s-exp> ]]
|
2008-04-27 03:03:49 -04:00
|
|
|
;EBNF
|