Handbook
Glossary
parse ( input parser -- list )
Vocabulary
parser-combinators
Inputs
input
an
object
parser
an
object
Outputs
list
an
object
Definition
IN:
parser-combinators
GENERIC:
parse
( input parser -- list )
Methods
USING:
accessors
kernel
lazy
parser-combinators
sequences
;
M:
and-parser
parse
parsers>>
unclip
swapd
parse
[
[
and-parser-parse
]
reduce
]
2curry
<lazy>
;
USING:
accessors
kernel
lists.lazy
parser-combinators
;
M:
apply-parser
parse
[
p1>>
]
[
quot>>
]
bi
-rot
parse
[
[
parsed>>
swap
call
]
keep
unparsed>>
<parse-result>
]
with
lmap-lazy
;
USING:
accessors
kernel
lists
parser-combinators
;
M:
ensure-not-parser
parse
2dup
test>>
parse
nil?
[
drop
t
swap
<parse-results>
]
[
2drop
nil
]
if
;
USING:
accessors
kernel
lists
parser-combinators
;
M:
ensure-parser
parse
2dup
test>>
parse
nil?
[
2drop
nil
]
[
drop
t
swap
<parse-results>
]
if
;
USING:
kernel
parser-combinators
;
M:
epsilon-parser
parse
drop
""
swap
<parse-results>
;
USING:
kernel
lists
parser-combinators
;
M:
fail-parser
parse
2drop
nil
;
USING:
accessors
lists.lazy
parser-combinators
sequences
;
M:
just-parser
parse
p1>>
parse
[
unparsed>>
empty?
]
lfilter
;
USING:
lazy
parser-combinators
;
M:
lazy
parse
force
parse
;
USING:
accessors
lists.lazy
parser-combinators
;
M:
only-first-parser
parse
p1>>
parse
1
ltake
;
USING:
accessors
kernel
lists
lists.lazy
parser-combinators
;
M:
or-parser
parse
parsers>>
sequence>list
[
parse
]
with
lmap-lazy
lconcat
;
USING:
accessors
combinators
kernel
lists
parser-combinators
sequences
;
M:
satisfy-parser
parse
over
empty?
[
2drop
nil
]
[
quot>>
[
unclip-slice
dup
]
dip
( char -- ? )
call-effect
[
swap
<parse-results>
]
[
2drop
nil
]
if
]
if
;
USING:
accessors
parser-combinators
;
M:
some-parser
parse
p1>>
just
parse-1
;
USING:
accessors
kernel
parser-combinators
;
M:
sp-parser
parse
[
trim-head-slice
]
dip
p1>>
parse
;
USING:
accessors
kernel
parser-combinators
;
M:
succeed-parser
parse
result>>
swap
<parse-results>
;
USING:
accessors
kernel
lists
parser-combinators
;
M::
token-parser
parse
( input parser -- list )
parser
string>>
:>
str parser
ignore-case?>>
:>
case? str
input str case?
?string-head
[
<parse-results>
]
[
2drop
nil
]
if
;