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

30 lines
771 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 lists.lazy words
math.parser promises parser-combinators unicode.categories ;
2007-12-19 22:48:58 -05:00
IN: parser-combinators.simple
2007-09-20 18:09:08 -04:00
: 'digit' ( -- parser )
[ digit? ] satisfy [ digit> ] <@ ;
: 'integer' ( -- parser )
[ digit? ] satisfy <*> [ string>number ] <@ ;
2007-09-20 18:09:08 -04:00
: 'string' ( -- parser )
[ CHAR: " = ] satisfy
2007-09-20 18:09:08 -04:00
[ CHAR: " = not ] satisfy <*> &>
[ CHAR: " = ] satisfy <& [ >string ] <@ ;
2007-09-20 18:09:08 -04:00
: 'bold' ( -- parser )
"*" token
[ CHAR: * = not ] satisfy <*> [ >string ] <@ &>
2007-09-20 18:09:08 -04:00
"*" token <& ;
: 'italic' ( -- parser )
"_" token
[ CHAR: _ = not ] satisfy <*> [ >string ] <@ &>
2007-09-20 18:09:08 -04:00
"_" token <& ;
: comma-list ( element -- parser )
"," token list-of ;