added test parsers, fixed doc links

db4
Sam Anklesaria 2009-03-10 18:22:31 -05:00
parent 995d28fb2f
commit 8eee229655
3 changed files with 22 additions and 6 deletions

View File

@ -8,4 +8,7 @@ HELP: ON-BNF:
HELP: create-bnf HELP: create-bnf
{ $values { "word" string } { "parser" parser } } { $values { "word" string } { "parser" parser } }
{ $description "Runtime equivalent of ON-BNF- also useful with manually constructed parsers." } ; { $description "Runtime equivalent of " { $link POSTPONE: ON-BNF: } " also useful with manually constructed parsers." } ;
HELP: factor
{ $description "Tokenizer that acts like standard factor lexer, separating tokens by whitespace." } ;

View File

@ -30,15 +30,11 @@ M: lex-hash at* swap {
H{ } clone \ packrat set ] f make-assoc <lex-hash> H{ } clone \ packrat set ] f make-assoc <lex-hash>
swap bind ; inline swap bind ; inline
! Usage:
! ON-BNF: word expr= [1-9] ;ON-BNF
! << name parser create-bnf >>
: parse* ( parser -- ast ) compile : parse* ( parser -- ast ) compile
[ execute [ error-stack get first throw ] unless* ] with-global-lexer [ execute [ error-stack get first throw ] unless* ] with-global-lexer
ast>> ; ast>> ;
: create-bnf ( name parser -- ) reset-tokenizer [ lexer get skip-blank parse* dup V{ } = [ parsed ] unless ] curry : create-bnf ( name parser -- ) reset-tokenizer [ lexer get skip-blank parse* parsed ] curry
define word make-parsing ; define word make-parsing ;
: ON-BNF: CREATE-WORD reset-tokenizer ";ON-BNF" parse-multiline-string parse-ebnf : ON-BNF: CREATE-WORD reset-tokenizer ";ON-BNF" parse-multiline-string parse-ebnf

View File

@ -0,0 +1,17 @@
USING: peg-lexer math.parser strings ;
IN: peg-lexer.test-parsers
ON-BNF: test1
num = [1-4]* => [[ >string ]]
expr = num ( "-end" | "-done" )
;ON-BNF
ON-BNF: test2
num = [1-4]* => [[ >string string>number ]]
expr= num [5-9]
;ON-BNF
ON-BNF: test3
tokenizer = <foreign factor>
expr= "heavy" "duty" "testing"
;ON-BNF