text
Parsers for working specifically with string data. Assume stream input. Provide better error messages and more flexibility vs regular parsers.
Parser that consumes character 'c'. Does a string equality compare, converting both 'c' and found value to strings before comparing them.
var p = parse_text.character('a');
parse.run(p, ''); // Error! UnexpectError eof
parse.run(p, 'b'); // Error! ExpectError expected 'a' found 'b'
parse.run(p, 'a'); // 'a'
parse.run(p, 'abc'); // 'a'
var p = parse_text.character('1');
parse.run(p, stream.from[1, 2, 3]); // 1
Parser that consumes any character in chars
.
var p = parse_text.oneOf('abc');
parse.run(p, ''); // Error! UnexpectError eof
parse.run(p, 'b'); // 'b'
parse.run(p, 'a'); // 'a'
parse.run(p, 'abc'); // 'a'
parse.run(p, 'z'); // Error!
Parser that consumes any character except those in chars
.
var p = parse_text.noneOf('abc');
parse.run(p, ''); // Error! Unexpected eof
parse.run(p, 'x'); // 'x'
parse.run(p, 'a'); // Error!
parse.run(p, 'c'); // Error
Parser that consumes string 'str'. Does a string equality compare, converting characters of 'str' and found value to strings before comparing them.
var p = parse_text.string('abc');
parse.run(p, ''); // Error! UnexpectError eof
parse.run(p, 'ab'); // Error! UnexpectError eof
parse.run(p, 'azbc'); // Error! ExpectError expected 'b' found 'z'
parse.run(p, 'abc'); // 'abc'
parse.run(p, 'abcdef'); // 'abc'
Parser that constructs a trie parser for an array of strings 'strs'. This has the same behavior as a choice parser of 'strs', but for large arrays with overlaps, will be more efficient.
var p = parse_text.trie(['ab', 'abc', 'abd']);
parse.run(p, ''); // Error! UnexpectError eof
parse.run(p, 'a'); // Error! UnexpectError eof
parse.run(p, 'ab'); // 'ab'
parse.run(p, 'abc'); // 'abc'
parse.run(p, 'abd'); // 'abd'
Parser that consumes any character.
var p = parse_text.anyChar;
parse.run(p, ''); // Error! UnexpectError eof
parse.run(p, 'a'); // 'a'
parse.run(p, 'z'); // 'z'
parse.run(p, '!'); // '!'
parse.run(p, 'abc'); // 'a'
parse.run(p, ' '); // Error!
Parser that consumes any letter.
var p = parse_text.anyLetter;
parse.run(p, ''); // Error! UnexpectError eof
parse.run(p, 'a'); // 'a'
parse.run(p, 'z'); // 'z'
parse.run(p, '!'); // Error!
parse.run(p, '2'); // Error!
parse.run(p, ' '); // Error!
Parser that consumes any space character.
var p = parse_text.space;
parse.run(p, ''); // Error! UnexpectError eof
parse.run(p, 'a'); // Error!
parse.run(p, ' '); // ' '
Parser that consumes any digit character.
var p = parse_text.digit;
parse.run(p, ''); // Error! UnexpectError eof
parse.run(p, 'a'); // Error!
parse.run(p, ' '); // Error!
parse.run(p, '2'); // '2'
parse.run(p, '7'); // '7'