1 ! Copyright (C) 2008 Chris Double, Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.markup help.syntax peg peg.parsers.private
10 { "parser" "a parser" }
12 "Calls 1string on a character and returns a parser that matches that character."
14 { $example "USING: peg peg.parsers prettyprint ;" "\"a\" CHAR: a 1token parse ." "\"a\"" }
15 } { $see-also 'string' } ;
19 { "items" "a sequence" }
20 { "separator" "a parser" }
21 { "repeat1?" "a boolean" }
22 { "parser" "a parser" }
24 "Returns a parser that returns a list of items separated by the separator parser. Does not hide the separators."
25 } { $see-also list-of list-of-many } ;
29 { "items" "a sequence" }
30 { "separator" "a parser" }
31 { "parser" "a parser" }
33 "Returns a parser that returns a list of items separated by the separator parser. Hides the separators and matches a list of one or more items."
34 } { $notes "Use " { $link list-of-many } " to ensure a list contains two or more items." }
36 { $example "USING: peg peg.parsers prettyprint ;" "\"a\" \"a\" token \",\" token list-of parse ." "V{ \"a\" }" }
37 { $example "USING: peg peg.parsers prettyprint ;" "\"a,a,a,a\" \"a\" token \",\" token list-of parse ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
38 } { $see-also list-of-many } ;
42 { "items" "a sequence" }
43 { "separator" "a parser" }
44 { "parser" "a parser" }
46 "Returns a parser that returns a list of items separated by the separator parser. Hides the separators and matches a list of two or more items."
47 } { $notes "Use " { $link list-of } " to return a list of only one item."
49 { $code "USING: peg peg.parsers prettyprint ;" "\"a\" \"a\" token \",\" token list-of-many parse => exception" }
50 { $example "USING: peg peg.parsers prettyprint ;" "\"a,a,a,a\" \"a\" token \",\" token list-of-many parse ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
51 } { $see-also list-of } ;
55 { "parser" "a parser" }
57 "Returns a parser that matches the empty sequence."
62 { "parser" "a parser" }
64 "Returns a parser that matches the any single character."
69 { "parser" "a parser" }
71 { "parser'" "a parser" }
73 "Returns a parser that matches an exact repetition of the input parser."
75 { $code "USING: peg peg.parsers prettyprint ;" "\"aaa\" \"a\" token 4 exactly-n parse => exception" }
76 { $example "USING: peg peg.parsers prettyprint ;" "\"aaaa\" \"a\" token 4 exactly-n parse ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
77 } { $see-also at-least-n at-most-n from-m-to-n } ;
81 { "parser" "a parser" }
83 { "parser'" "a parser" }
85 "Returns a parser that matches n or more repetitions of the input parser."
87 { $code "USING: peg peg.parsers prettyprint ;" "\"aaa\" \"a\" token 4 at-least-n parse => exception"}
88 { $example "USING: peg peg.parsers prettyprint ;" "\"aaaa\" \"a\" token 4 at-least-n parse ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
89 { $example "USING: peg peg.parsers prettyprint ;" "\"aaaaa\" \"a\" token 4 at-least-n parse ." "V{ \"a\" \"a\" \"a\" \"a\" \"a\" }" }
90 } { $see-also exactly-n at-most-n from-m-to-n } ;
94 { "parser" "a parser" }
96 { "parser'" "a parser" }
98 "Returns a parser that matches n or fewer repetitions of the input parser."
100 { $example "USING: peg peg.parsers prettyprint ;" "\"aaaa\" \"a\" token 4 at-most-n parse ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
101 { $example "USING: peg peg.parsers prettyprint ;" "\"aaaaa\" \"a\" token 4 at-most-n parse ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
102 } { $see-also exactly-n at-least-n from-m-to-n } ;
106 { "parser" "a parser" }
109 { "parser'" "a parser" }
111 "Returns a parser that matches between and including m to n repetitions of the input parser."
113 { $example "USING: peg peg.parsers prettyprint ;" "\"aaa\" \"a\" token 3 4 from-m-to-n parse ." "V{ \"a\" \"a\" \"a\" }" }
114 { $example "USING: peg peg.parsers prettyprint ;" "\"aaaa\" \"a\" token 3 4 from-m-to-n parse ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
115 { $example "USING: peg peg.parsers prettyprint ;" "\"aaaaa\" \"a\" token 3 4 from-m-to-n parse ." "V{ \"a\" \"a\" \"a\" \"a\" }" }
116 } { $see-also exactly-n at-most-n at-least-n } ;
120 { "begin" "a parser" }
121 { "body" "a parser" }
123 { "parser" "a parser" }
125 "Returns a parser that parses the begin, body, and end parsers in order. The begin and end parsers are hidden."
127 { $example "USING: peg peg.parsers prettyprint ;" "\"hi123bye\" \"hi\" token 'integer' \"bye\" token pack parse ." "123" }
128 } { $see-also surrounded-by } ;
132 { "parser" "a parser" }
133 { "begin" "a string" }
135 { "parser'" "a parser" }
137 "Calls token on begin and end to make them into string parsers. Returns a parser that parses the begin, body, and end parsers in order. The begin and end parsers are hidden."
139 { $example "USING: peg peg.parsers prettyprint ;" "\"hi123bye\" 'integer' \"hi\" \"bye\" surrounded-by parse ." "123" }
140 } { $see-also pack } ;
144 { "parser" "a parser" }
146 "Returns a parser that matches a single digit as defined by the " { $link digit? } " word."
147 } { $see-also 'integer' } ;
151 { "parser" "a parser" }
153 "Returns a parser that matches an integer composed of digits, as defined by the " { $link 'digit' } " word."
154 } { $see-also 'digit' 'string' } ;
158 { "parser" "a parser" }
160 "Returns a parser that matches an string composed of a \", anything that is not \", and another \"."
161 } { $see-also 'integer' } ;
165 { "pattern" "a string" }
166 { "parser" "a parser" }
168 "Returns a parser that matches a single character based on the set "
169 "of characters in the pattern string."
170 "Any single character in the pattern matches that character. "
171 "If the pattern begins with a ^ then the set is negated "
172 "(the element matches any character not in the set). Any pair "
173 "of characters separated with a dash (-) represents the "
174 "range of characters from the first to the second, inclusive."
176 { $example "USING: peg peg.parsers prettyprint strings ;" "\"a\" \"_a-zA-Z\" range-pattern parse 1string ." "\"a\"" }
177 { $code "USING: peg peg.parsers prettyprint ;\n\"0\" \"^0-9\" range-pattern parse => exception"}