lexer: cleanup a bit.

db4
John Benediktsson 2014-02-21 01:10:21 -08:00
parent 550118e608
commit d3acf4d482
1 changed files with 15 additions and 18 deletions

View File

@ -23,12 +23,9 @@ TUPLE: lexer-parsing-word word line line-text column ;
drop ; drop ;
: push-parsing-word ( word -- ) : push-parsing-word ( word -- )
lexer-parsing-word new
swap >>word
lexer get [ lexer get [
[ line>> >>line ] [ line>> ] [ line-text>> ] [ column>> ] tri
[ line-text>> >>line-text ] lexer-parsing-word boa
[ column>> >>column ] tri
] [ parsing-words>> push ] bi ; ] [ parsing-words>> push ] bi ;
: pop-parsing-word ( -- ) : pop-parsing-word ( -- )
@ -50,8 +47,9 @@ ERROR: unexpected want got ;
[ CHAR: \t eq? [ "[space]" "[tab]" unexpected ] when ] keep ; inline [ CHAR: \t eq? [ "[space]" "[tab]" unexpected ] when ] keep ; inline
: skip ( i seq ? -- n ) : skip ( i seq ? -- n )
over length over length [
[ [ swap forbid-tab CHAR: \s eq? xor ] curry find-from drop ] dip or ; [ swap forbid-tab CHAR: \s eq? xor ] curry find-from drop
] dip or ;
: change-lexer-column ( lexer quot -- ) : change-lexer-column ( lexer quot -- )
[ [ column>> ] [ line-text>> ] bi ] prepose keep [ [ column>> ] [ line-text>> ] bi ] prepose keep
@ -133,19 +131,18 @@ M: lexer-error error-file error>> error-file ;
M: lexer-error error-line [ error>> error-line ] [ line>> ] bi or ; M: lexer-error error-line [ error>> error-line ] [ line>> ] bi or ;
: <lexer-error> ( msg -- error ) : <lexer-error> ( msg -- error )
\ lexer-error new [
lexer get [ lexer get {
[ line>> >>line ] [ line>> ]
[ column>> >>column ] bi [ column>> ]
] [ [ line-text>> ]
[ line-text>> >>line-text ] [ parsing-words>> clone ]
[ parsing-words>> clone >>parsing-words ] bi } cleave
] bi ] dip lexer-error boa ;
swap >>error ;
: simple-lexer-dump ( error -- ) : simple-lexer-dump ( error -- )
[ line>> number>string ": " append ] [ line>> number>string ": " append ]
[ line-text>> dup string? [ drop "" ] unless ] [ line-text>> "" or ]
[ column>> 0 or ] tri [ column>> 0 or ] tri
pick length + CHAR: \s <string> pick length + CHAR: \s <string>
[ write ] [ print ] [ write "^" print ] tri* ; [ write ] [ print ] [ write "^" print ] tri* ;
@ -156,7 +153,7 @@ M: lexer-error error-line [ error>> error-line ] [ line>> ] bi or ;
over line>> number>string length over line>> number>string length
CHAR: \s pad-head CHAR: \s pad-head
": " append write ": " append write
] [ line-text>> dup string? [ drop "" ] unless print ] bi ] [ line-text>> "" or print ] bi
simple-lexer-dump ; simple-lexer-dump ;
: parsing-word-lexer-dump ( error parsing-word -- ) : parsing-word-lexer-dump ( error parsing-word -- )