lexer: support universal comments.
parent
cba0a96c10
commit
52a3f6f309
|
@ -8,7 +8,6 @@ IN: bootstrap.syntax
|
||||||
"syntax" create-vocab drop
|
"syntax" create-vocab drop
|
||||||
|
|
||||||
{
|
{
|
||||||
"!"
|
|
||||||
"\""
|
"\""
|
||||||
"("
|
"("
|
||||||
":"
|
":"
|
||||||
|
|
|
@ -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." } ;
|
{ $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
|
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." } ;
|
{ $description "Applies a quotation to the current column and line text to produce a new column, and moves the lexer position." } ;
|
||||||
|
|
||||||
HELP: skip-blank
|
HELP: skip-blank
|
||||||
|
|
|
@ -57,7 +57,7 @@ ERROR: unexpected want got ;
|
||||||
[ swap forbid-tab CHAR: \s eq? xor ] curry find-from drop
|
[ swap forbid-tab CHAR: \s eq? xor ] curry find-from drop
|
||||||
] dip or ; inline
|
] 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
|
[ check-lexer [ column>> ] [ line-text>> ] bi ] prepose
|
||||||
keep column<< ; inline
|
keep column<< ; inline
|
||||||
|
|
||||||
|
@ -94,13 +94,26 @@ M: lexer skip-word
|
||||||
: still-parsing-line? ( lexer -- ? )
|
: still-parsing-line? ( lexer -- ? )
|
||||||
check-lexer [ column>> ] [ line-length>> ] bi < ;
|
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 )
|
: (parse-token) ( lexer -- str )
|
||||||
check-lexer {
|
dup check-lexer {
|
||||||
[ column>> ]
|
[ column>> ]
|
||||||
[ skip-word ]
|
[ skip-word ]
|
||||||
[ column>> ]
|
[ column>> ]
|
||||||
[ line-text>> ]
|
[ line-text>> ]
|
||||||
} cleave subseq ;
|
} cleave subseq skip-comments ;
|
||||||
|
|
||||||
: parse-token ( lexer -- str/f )
|
: parse-token ( lexer -- str/f )
|
||||||
dup still-parsing? [
|
dup still-parsing? [
|
||||||
|
|
|
@ -26,11 +26,6 @@ $nl
|
||||||
$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." ;
|
"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"
|
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."
|
"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
|
{ $subsections
|
||||||
|
@ -658,11 +653,6 @@ HELP: (
|
||||||
{ $see-also "effects" }
|
{ $see-also "effects" }
|
||||||
;
|
;
|
||||||
|
|
||||||
HELP: !
|
|
||||||
{ $syntax "! comment..." }
|
|
||||||
{ $values { "comment" "characters" } }
|
|
||||||
{ $description "Discards all input until the end of the line." } ;
|
|
||||||
|
|
||||||
HELP: NAN:
|
HELP: NAN:
|
||||||
{ $syntax "NAN: payload" }
|
{ $syntax "NAN: payload" }
|
||||||
{ $values { "payload" "64-bit hexadecimal integer" } }
|
{ $values { "payload" "64-bit hexadecimal integer" } }
|
||||||
|
|
|
@ -48,8 +48,6 @@ IN: bootstrap.syntax
|
||||||
"Call stack literals are not supported" throw
|
"Call stack literals are not supported" throw
|
||||||
] define-core-syntax
|
] define-core-syntax
|
||||||
|
|
||||||
"!" [ lexer get next-line ] define-core-syntax
|
|
||||||
|
|
||||||
"IN:" [ scan-token set-current-vocab ] define-core-syntax
|
"IN:" [ scan-token set-current-vocab ] define-core-syntax
|
||||||
|
|
||||||
"<PRIVATE" [ begin-private ] define-core-syntax
|
"<PRIVATE" [ begin-private ] define-core-syntax
|
||||||
|
|
Loading…
Reference in New Issue