]> gitweb.factorcode.org Git - factor.git/commitdiff
lexer: change shebang handling to be in skip-blank.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 11 Sep 2015 00:53:04 +0000 (17:53 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 11 Sep 2015 00:53:04 +0000 (17:53 -0700)
It previously required "#!" to be defined like "!", now it doesn't.

core/lexer/lexer.factor

index 55ae061633b9e3d3eaf0da6dc5aa20d078ebe01c..7ded3662f64dec493de27ec0351d2dedd8cad96f 100644 (file)
@@ -63,33 +63,29 @@ ERROR: unexpected want got ;
 
 GENERIC: skip-blank ( lexer -- )
 
-M: lexer skip-blank
-    [ t skip ] change-lexer-column ;
-
-GENERIC: skip-word ( lexer -- )
-
 <PRIVATE
 
-: quote? ( column text -- ? )
-    { fixnum string } declare nth CHAR: " eq? ;
-
-: shebang? ( column text -- ? )
-    { fixnum string } declare swap zero? [
-        dup length 1 > [
-            dup first-unsafe CHAR: # =
-            [ second-unsafe CHAR: ! = ] [ drop f ] if
-        ] [ drop f ] if
-    ] [ drop f ] if ;
+: shebang? ( lexer -- lexer ? )
+    dup line>> 1 = [
+        dup column>> zero? [
+            dup line-text>> "#!" head?
+        ] [ f ] if
+    ] [ f ] if ; inline
 
 PRIVATE>
 
+M: lexer skip-blank
+    shebang? [
+        [ nip length ] change-lexer-column
+    ] [
+        [ t skip ] change-lexer-column
+    ] if ;
+
+GENERIC: skip-word ( lexer -- )
+
 M: lexer skip-word
     [
-        {
-            { [ 2dup quote? ] [ drop 1 + ] }
-            { [ 2dup shebang? ] [ drop 2 + ] }
-            [ f skip ]
-        } cond
+        2dup nth CHAR: " eq? [ drop 1 + ] [ f skip ] if
     ] change-lexer-column ;
 
 : still-parsing? ( lexer -- ? )