4f: Parsing (Rule-Builders)
+bass
+bassParser modifier: LSB ordered +list as $atom of a $base.
Accepts
.wuc is an $atom.
.tyd is a $rule.
Produces
A $rule.
Source
++ bass
|* [wuc=@ tyd=rule]
%+ cook
|= waq=(list @)
%+ roll
waq
=|([p=@ q=@] |.((add p (mul wuc q))))
tydExamples
+boss
+bossParser modifier, LSB.
Ordered +list as $atom of a $base.
Accepts
.wuc is an $atom.
.tyd is a $rule.
Produces
A $rule.
Source
Examples
+cold
+coldReplace with constant.
Parser modifier. Accepts a $rule .sef and produces a parser that produces a constant .cus, assuming .sef is successful.
Accepts
.cus is a constant $noun.
.sef is a $rule.
Produces
An $edge.
Source
Examples
+cook
+cookApply gate.
Parser modifier. Produces a parser that takes a (successful) result of a $rule .sef and slams it through .poq.
Accepts
.poq is a gate.
.sef is a $rule.
Produces
A $rule.
Source
Examples
+easy
+easyAlways parse.
Parser generator. Produces a parser that succeeds with given $noun +huf without consuming any text.
Accepts
.huf is a $noun.
Produces
A $rule.
Source
Examples
+fuss
+fussHas A or B?
If string .sic is parsed: %.y. If string .non is parsed: %.n. Otherwise, fail.
Accepts
.sic is a @t.
.non is a @t.
Produces
A $rule.
Source
Examples
+full
+fullParse to end.
Parser modifier. Accepts a $rule .sef, and produces a parser that succeeds only when the $tape of .tub is fully consumed using .sef.
Accepts
.sef is a $rule.
Produces
A $rule.
Source
Examples
+funk
+funkAdd to tape.
Parser modifier: prepend text to $tape before applying parser.
Accepts
.pre is a $tape.
.sef is a $rule.
Produces
A $rule.
Source
Examples
+here
+herePlace-based apply.
Parser modifier. Similar to +cook in that it produces a parser that takes a (successful) result of .sef and slams it through .hez. .hez accepts a $pint .a and a $noun .b, which is what the parser parsed.
Accepts
.hez is a gate.
.sef is a $rule.
Produces
A $rule.
Source
Examples
+inde
+indeIndentation block.
Apply $rule to indented block starting at current column number, omitting the leading whitespace.
Accepts
.sef is a $rule.
Produces
A $rule.
Source
Examples
Discussion
Note the amount of indentation whitespace to be stripped from the beginning of each line is determined by the value of .q (the column) in the $hair when +inde is first called. This means something like the +pfix expression in the example above is necessary to set the level of indentation. Additionally, the $rule given to +inde must consume the whole line including the line ending.
+ifix
+ifixInfix.
Parser modifier: surround with pair of $rules, the output of which is discarded.
Accepts
.fel is a pair of $rules.
.hof is a $rule.
Produces
A $rule.
Source
Examples
+jest
+jestMatch a cord.
Match and consume a cord.
Accepts
.daf is a @t.
Produces
A $rule.
Source
Examples
+just
+justMatch a char.
Match and consume a single character.
Accepts
.daf is a $char
Produces
A $rule.
Source
Examples
+knee
+kneeRecursive parsers.
Used for recursive parsers, which would otherwise be infinite when compiled.
Accepts
+gar is a $noun.
.sef is a gate that accepts a $rule
Produces
A $rule.
Source
Examples
+mask
+maskMatch char.
Parser generator. Matches the next character if it is in a list of characters.
Accepts
.bud is a list of $char.
Produces
A $rule.
Source
Examples
+more
+moreParse list with delimiter.
Parser modifier: Parse a list of matches using a delimiter $rule.
Accepts
.bus is a $rule.
.fel is a $rule.
Produces
A $rule.
Source
Examples
+most
+mostParse list of at least one match.
Parser modifier: parse a +list of at least one match using a delimiter $rule.
Accepts
.bus is a $rule.
.fel is a $rule.
Produces
A $rule.
Source
Examples
+next
+nextConsume char.
Consume any character, producing it as a result.
Accepts
.tub is a $nail.
Produces
An $edge.
Source
Examples
+perk
+perkParse cube fork.
Given .a, a list of @tas, match any one in the list and produce it. Note the list should not be a +list type, but just a null-terminated cell like ~[%foo %bar %baz]. The type produced will be a union of the items in the given list, so you can use a ?- expression on the output.
Accepts
.a is a (pole @tas).
Produces
A $rule.
Source
Examples
+plus
+plusList of at least one match.
Parser modifier: parse +list of at least one match.
Accepts
.fel is a $rule.
Produces
A $rule.
Source
Examples
+punt
+puntUnitized parse.
Either successfully apply $rule .a and produce a +unit of the result, or produce ~.
Accepts
.a is a $rule.
Produces
A $rule.
Source
Example
+sear
+searConditional +cook.
Conditional +cook. Slams the result through a gate that produces a unit; if that unit is empty, fail.
Accepts
.pyq is a gate that produces a +unit.
.sef is a $rule.
Produces
A $rule.
Source
Examples
+shim
+shimChar in range.
Match characters ($char) within a range.
Accepts
.les is an $atom.
.mos is an $atom.
Produces
A $rule.
Source
Examples
+slug
+slugUse gate to parse delimited list.
Parser modifier: By composing with a gate, parse a delimited +list of matches.
Accepts
.raq is a binary gate.
.bus is a $rule.
.fel is a $rule.
Produces
A $rule.
Source
Examples
+stag
+stagAdd label.
Add a label to an $edge parsed by a $rule.
Accepts
.gob is a $noun.
.sef is a rule.
Produces
A $rule.
Source
Examples
+star
+starList of matches.
Parser modifier: parse +list of matches.
Accepts
.fel is a $rule.
Produces
A $rule.
Source
Examples
+stet
+stetAdd faces.
Add faces [p q] to range-parser pairs in a list. Typically used in combination with +stew.
Accepts
.leh is a list of range-parsers.
Produces
A (list [p=?(@ [@ @]) q=rule]).
Source
Examples
+stew
+stewSwitch by first char.
Parser generator. From an associative +list of characters or character ranges to $rules, construct a +map, and parse $tapes only with $rules associated with a range that the $tape's first character falls in.
Accepts
.leh is a (list [p=?(@ [@ @]) q=rule]), where .p is a $char or $char range.
Produces
A $rule.
Source
Examples
+stir
+stirParse repeatedly.
Parse with $rule as many times as possible, and fold over results with a binary gate.
Accepts
.rud is a $noun.
.raq is a gate that takes two $nouns and produces a cell.
.fel is a $rule.
Produces
A $rule.
Source
Examples
+stun
+stunParse several times.
Parse bounded number of times.
Accepts
.lig is a cell of $atoms ([@ @]) indicating the bounds.
.fel is a $rule.
Produces
A $rule.
Source
Examples
Last updated