]> gitweb.factorcode.org Git - factor.git/commitdiff
lexer: skip #! as a single token at front of line
authorJoe Groff <arcata@gmail.com>
Sun, 27 Nov 2011 22:59:54 +0000 (14:59 -0800)
committerJoe Groff <arcata@gmail.com>
Sun, 27 Nov 2011 22:59:54 +0000 (14:59 -0800)
Fixes #370

core/lexer/lexer.factor
core/parser/parser-tests.factor

index af3d7813c6bfed0a7697ba23830c61c75a3bb37e..123f2a5a71b1c7a82b7a1e2bdc3946e0a74a65db 100644 (file)
@@ -58,9 +58,23 @@ M: lexer skip-blank ( 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 -- )
     [
-        2dup nth CHAR: " eq? [ drop 1 + ] [ f skip ] if
+        {
+            { [ 2dup quote? ] [ drop 1 + ] }
+            { [ 2dup shebang? ] [ drop 2 + ] }
+            [ f skip ]
+        } cond
     ] change-lexer-column ;
 
 : still-parsing? ( lexer -- ? )
index 57f060e9371ffaa7abe32297b753e3113643e953..9507403791cc2e6001e554a9872dcfeb4ebe0f4e 100644 (file)
@@ -23,6 +23,12 @@ unit-test
 [ "\"\\n\\r\\t\\\\\"" eval( -- string ) ]
 unit-test
 
+[ "hello world" ]
+[
+"""#!/usr/bin/env factor
+"hello world" """ eval( -- string )
+] unit-test
+
 [ "hello world" ]
 [
     "IN: parser.tests : hello ( -- str ) \"hello world\" ;"