Module rsast¶
Require: require("rsast")
Index¶
Function
Sets the maximum call limit for the parser state. |
|
Sets whether information for more error details should be collected. |
Class
A PEG parser |
|
A matching pair of rsast.Token and everything between them |
|
An iterator over rsast.Pair |
|
Api reference¶
-
class rsast.Node:
table¶ -
start:
integer¶
-
stop:
integer¶
-
rule:
string¶
-
node_tag:
string?¶
-
pairs:
rsast.Tree?¶
-
start:
-
class rsast.Tree:
table¶ -
start:
integer¶
-
stop:
integer¶
-
pairs:
rsast.Node[]¶
-
start:
-
class rsast.Pair:
userdata¶ A matching pair of
rsast.Tokenand everything between them-
start: fun(
self):integer¶
-
stop: fun(
self):integer¶
-
as_rule: fun(
self):string¶
-
as_str: fun(
self):string¶
-
as_node_tag: fun(
self):string?¶
-
get_input: fun(
self):string¶
-
line_col: fun(
self): (integer,integer)¶
-
dump: fun(
self):rsast.Node¶
-
pairs(self):
rsast.Pairs?¶ Returns any inner nodes as an
rsast.PairsIf there are no inner nodes, returns
nil
-
start: fun(
- class rsast.Pairs¶
An iterator over
rsast.Pair-
as_str: fun(
self):string¶
-
get_input: fun(
self):string¶
-
is_empty: fun(
self):boolean¶
-
dump: fun(
self):rsast.Tree¶
-
peek(self):
rsast.Pair?¶ Get the next pair without advancing the iterator.
Returns
nilif the iterator is exhausted
-
next(self):
rsast.Pair?¶ Get the next pair.
Returns
nilif the iterator is exhausted
-
next_back(self):
rsast.Pair?¶ Get the next pair from the end.
Returns
nilif the iterator is exhausted
-
iter(self): fun():
rsast.Pair¶ Iterate over the pairs
-
reviter(self): fun():
rsast.Pair¶ Iterate over the pairs in reverse order
-
flatten(self):
rsast.Pairs¶ Flatten nested nodes into a single iterator
-
find_tagged(self, tag:
string):rsast.Pair[]¶ Searches through the top level nodes for all nodes marked with
tagIf you would like to search through all nodes, including inner nodes, call
rsast.Pairs:flatten()first.
-
as_str: fun(
-
class rsast.Ast:
userdata¶ A PEG parser
-
staticmethod new(grammar:
string): (ast?:rsast.Ast, errors?:string[])¶ Load a grammar from a string for parsing.
Returns
rsast.Ast, nilif the grammar was loaded successfully, ornil, string[], wherestring[]is a list of errors encountered while loading the grammar.- Parameters:
grammar (
string) – The grammar to load- Returns:
ast? (
rsast.Ast) – A parser for the provided grammar, returns nil of it could not be loadederrors? (
string[]) – Errors encountered while loading the grammar, or nil if there were none.
-
set_error_formatter(
self,
rule_handler?: fun(rule:string):string,
ws_handler: fun(text:string):boolean
)¶ Set callbacks to handle error formatting.
rule_handleris a callback which receives the name of a rule and returns a string to write in its place.ws_handleris a callback which receives a text and returns a boolean as to whether the text should be considered whitespace- Parameters:
rule_handler? (fun(rule:
string):string) – Formatter for rule namesws_handler (fun(text:
string):boolean) – Formatter for whitespace
-
validate(self, rule:
string, input:string): (valid:boolean, errors?:string)¶ Validate in input against the grammar
- Parameters:
rule (
string) – The rule to parseinput (
string) – The input to parse
- Returns:
valid (
boolean) – Whether the input was valid, and any errors if it was not.errors? (
string) – Any errors encountered when parsing
-
parse<R>(
self,
rule:string,
input:string,
callback: fun(pairs:rsast.Pairs):R...
):R...¶ Parse an input with the loaded grammar.
callbackis called with anrsast.Pairsiterator as the first argument, and the return value of the function is returned fromparse.- Parameters:
rule (
string) – The rule to parseinput (
string) – The input to parse
- Returns:
_1 (
R...) – Returns the result ofcallback
-
staticmethod new(grammar:
-
rsast.set_call_limit(limit?:
integer)¶ Sets the maximum call limit for the parser state.
If set, the calls are tracked as a running total over all non-terminal rules that can nest closures (which are passed to transform the parser state).
This can help prevent stack overflows or excessive execution times in some grammars.
Passing
limitas0ornildisables any call limit.
-
rsast.set_error_detail(enable:
boolean)¶ Sets whether information for more error details should be collected.
This can have a performance impact, so it is disabled by default.