factor/extra/parser-combinators/simple/simple.factor

29 lines
732 B
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2006 Chris Double.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel strings math sequences lazy-lists words
math.parser promises ;
IN: parser-combinators
: 'digit' ( -- parser )
[ digit? ] satisfy [ digit> ] <@ ;
: 'integer' ( -- parser )
2007-11-15 04:40:35 -05:00
'digit' <!+> [ 10 swap digits>integer ] <@ ;
2007-09-20 18:09:08 -04:00
: 'string' ( -- parser )
[ CHAR: " = ] satisfy
[ CHAR: " = not ] satisfy <*> &>
[ CHAR: " = ] satisfy <& [ >string ] <@ ;
: 'bold' ( -- parser )
"*" token
[ CHAR: * = not ] satisfy <*> [ >string ] <@ &>
"*" token <& ;
: 'italic' ( -- parser )
"_" token
[ CHAR: _ = not ] satisfy <*> [ >string ] <@ &>
"_" token <& ;
: comma-list ( element -- parser )
"," token list-of ;