]> gitweb.factorcode.org Git - factor.git/commitdiff
lexer: support universal comments.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 31 Mar 2016 04:08:41 +0000 (21:08 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 31 Mar 2016 04:09:08 +0000 (21:09 -0700)
core/bootstrap/syntax.factor
core/lexer/lexer-docs.factor
core/lexer/lexer.factor
core/syntax/syntax-docs.factor
core/syntax/syntax.factor

index fea500de49e5866421d822dcddf808b5b1c64e29..eccd30c4a1999c69da3c76356a22cfc3e56d4c32 100644 (file)
@@ -8,7 +8,6 @@ IN: bootstrap.syntax
     "syntax" create-vocab drop
 
     {
-        "!"
         "\""
         "("
         ":"
index 96adc0816aa3b53620ea909149c37836e8b3e2f4..951fb72335a2c95fee9aa20e9687c861d482289e 100644 (file)
@@ -32,7 +32,7 @@ HELP: skip
 { $description "Skips to the first space character (if " { $snippet "boolean" } " is " { $link f } ") or the first non-space character (otherwise). Tabulations used as separators instead of spaces will be flagged as an error." } ;
 
 HELP: change-lexer-column
-{ $values { "lexer" lexer } { "quot" { $quotation ( col line -- newcol ) } } }
+{ $values { "lexer" lexer } { "quot" { $quotation ( ..a col line -- ..b newcol ) } } }
 { $description "Applies a quotation to the current column and line text to produce a new column, and moves the lexer position." } ;
 
 HELP: skip-blank
index 7ded3662f64dec493de27ec0351d2dedd8cad96f..36ea984b2f7d5897a05ba38300ea42ddae9da4ad 100644 (file)
@@ -57,7 +57,7 @@ ERROR: unexpected want got ;
         [ swap forbid-tab CHAR: \s eq? xor ] curry find-from drop
     ] dip or ; inline
 
-: change-lexer-column ( lexer quot -- )
+: change-lexer-column ( ..a lexer quot: ( ..a col line -- ..b newcol ) -- ..b )
     [ check-lexer [ column>> ] [ line-text>> ] bi ] prepose
     keep column<< ; inline
 
@@ -94,13 +94,26 @@ M: lexer skip-word
 : still-parsing-line? ( lexer -- ? )
     check-lexer [ column>> ] [ line-length>> ] bi < ;
 
+DEFER: parse-token
+
+<PRIVATE
+
+: skip-comments ( lexer str -- str' )
+    dup "!" = [
+        drop [ next-line ] keep parse-token
+    ] [
+        nip
+    ] if ;
+
+PRIVATE>
+
 : (parse-token) ( lexer -- str )
-    check-lexer {
+    dup check-lexer {
         [ column>> ]
         [ skip-word ]
         [ column>> ]
         [ line-text>> ]
-    } cleave subseq ;
+    } cleave subseq skip-comments ;
 
 : parse-token ( lexer -- str/f )
     dup still-parsing? [
index e3e285d11d82f13b2f909b3c8c6ca644275f3f04..752f667d119da54dae21482dac21f8341222cf1d 100644 (file)
@@ -26,11 +26,6 @@ $nl
 $nl
 "While parsing words supporting arbitrary syntax can be defined, the default set is found in the " { $vocab-link "syntax" } " vocabulary and provides the basis for all further syntactic interaction with Factor." ;
 
-ARTICLE: "syntax-comments" "Comments"
-{ $subsections
-    POSTPONE: !
-} ;
-
 ARTICLE: "syntax-immediate" "Parse time evaluation"
 "Code can be evaluated at parse time. This is a rarely-used feature; one use-case is " { $link "loading-libs" } ", where you want to execute some code before the words in a source file are compiled."
 { $subsections
@@ -658,11 +653,6 @@ HELP: (
 { $see-also "effects" }
 ;
 
-HELP: !
-{ $syntax "! comment..." }
-{ $values { "comment" "characters" } }
-{ $description "Discards all input until the end of the line." } ;
-
 HELP: NAN:
 { $syntax "NAN: payload" }
 { $values { "payload" "64-bit hexadecimal integer" } }
index 8641345c54c819baa6f7ba4c6f23cf1fca072c74..78b41e211660f63e6cd0ae5001d344fdb6b91c03 100644 (file)
@@ -48,8 +48,6 @@ IN: bootstrap.syntax
         "Call stack literals are not supported" throw
     ] define-core-syntax
 
-    "!" [ lexer get next-line ] define-core-syntax
-
     "IN:" [ scan-token set-current-vocab ] define-core-syntax
 
     "<PRIVATE" [ begin-private ] define-core-syntax