lexer: support universal comments.

locals-and-roots
John Benediktsson 2016-03-30 21:08:41 -07:00
parent cba0a96c10
commit 52a3f6f309
5 changed files with 17 additions and 17 deletions

View File

@ -8,7 +8,6 @@ IN: bootstrap.syntax
"syntax" create-vocab drop
{
"!"
"\""
"("
":"

View 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

View 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? [

View 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" } }

View 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