Merge branch 'master' of git://factorcode.org/git/jamesnvc

db4
Slava Pestov 2008-05-14 02:38:05 -05:00
commit 1a835ba2da
3 changed files with 19 additions and 9 deletions

View File

@ -26,14 +26,14 @@ DEFER: funcall
unclip convert-form swap convert-body [ , % funcall ] bake ; unclip convert-form swap convert-body [ , % funcall ] bake ;
<PRIVATE <PRIVATE
: localize-body ( vars body -- newbody ) : localize-body ( assoc body -- assoc newbody )
[ dup lisp-symbol? [ tuck name>> swap member? [ name>> make-local ] [ ] if ] [ dup lisp-symbol? [ over dupd [ name>> ] dip at swap or ]
[ dup s-exp? [ body>> localize-body <s-exp> ] [ nip ] if ] if [ dup s-exp? [ body>> localize-body <s-exp> ] when ] if
] with map ; ] map ;
: localize-lambda ( body vars -- newbody newvars ) : localize-lambda ( body vars -- newbody newvars )
dup make-locals dup push-locals [ swap localize-body <s-exp> convert-form ] dipd make-locals dup push-locals swap
pop-locals swap ; [ swap localize-body <s-exp> convert-form swap pop-locals ] dip swap ;
PRIVATE> PRIVATE>

View File

@ -8,6 +8,14 @@ IN: lisp.parser.tests
"1234" "atom" \ lisp-expr rule parse parse-result-ast "1234" "atom" \ lisp-expr rule parse parse-result-ast
] unit-test ] unit-test
{ -42 } [
"-42" "atom" \ lisp-expr rule parse parse-result-ast
] unit-test
{ 37/52 } [
"37/52" "atom" \ lisp-expr rule parse parse-result-ast
] unit-test
{ 123.98 } [ { 123.98 } [
"123.98" "atom" \ lisp-expr rule parse parse-result-ast "123.98" "atom" \ lisp-expr rule parse parse-result-ast
] unit-test ] unit-test

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 James Cash ! Copyright (C) 2008 James Cash
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel peg.ebnf peg.expr math.parser sequences arrays strings USING: kernel peg.ebnf peg.expr math.parser sequences arrays strings
combinators.lib ; combinators.lib math ;
IN: lisp.parser IN: lisp.parser
@ -18,9 +18,11 @@ RPAREN = ")"
dquote = '"' dquote = '"'
squote = "'" squote = "'"
digit = [0-9] digit = [0-9]
integer = (digit)+ => [[ string>number ]] integer = ("-")? (digit)+ => [[ first2 append string>number ]]
float = (digit)+ "." (digit)* => [[ first3 >string [ >string ] dipd 3append string>number ]] float = integer "." (digit)* => [[ first3 >string [ number>string ] dipd 3append string>number ]]
rational = integer "/" (digit)+ => [[ first3 nip string>number / ]]
number = float number = float
| rational
| integer | integer
id-specials = "!" | "$" | "%" | "&" | "*" | "/" | ":" | "<" id-specials = "!" | "$" | "%" | "&" | "*" | "/" | ":" | "<"
| " =" | ">" | "?" | "^" | "_" | "~" | "+" | "-" | "." | "@" | " =" | ">" | "?" | "^" | "_" | "~" | "+" | "-" | "." | "@"