lexer: skip #! as a single token at front of line

Fixes #370
db4
Joe Groff 2011-11-27 14:59:54 -08:00
parent 26226d460e
commit 2cf8b32bda
2 changed files with 21 additions and 1 deletions

View File

@ -58,9 +58,23 @@ M: lexer skip-blank ( lexer -- )
GENERIC: skip-word ( lexer -- ) GENERIC: skip-word ( lexer -- )
<PRIVATE
: quote? ( column text -- ? )
nth CHAR: " eq? ; inline
: shebang? ( column text -- ? )
swap zero? [ "#!" head? ] [ drop f ] if ; inline
PRIVATE>
M: lexer skip-word ( lexer -- ) M: lexer skip-word ( lexer -- )
[ [
2dup nth CHAR: " eq? [ drop 1 + ] [ f skip ] if {
{ [ 2dup quote? ] [ drop 1 + ] }
{ [ 2dup shebang? ] [ drop 2 + ] }
[ f skip ]
} cond
] change-lexer-column ; ] change-lexer-column ;
: still-parsing? ( lexer -- ? ) : still-parsing? ( lexer -- ? )

View File

@ -23,6 +23,12 @@ unit-test
[ "\"\\n\\r\\t\\\\\"" eval( -- string ) ] [ "\"\\n\\r\\t\\\\\"" eval( -- string ) ]
unit-test unit-test
[ "hello world" ]
[
"""#!/usr/bin/env factor
"hello world" """ eval( -- string )
] unit-test
[ "hello world" ] [ "hello world" ]
[ [
"IN: parser.tests : hello ( -- str ) \"hello world\" ;" "IN: parser.tests : hello ( -- str ) \"hello world\" ;"