TSParser#
Qualified name: rsm.tsparser.TSParser
- class rsm.tsparser.TSParser[source]#
Bases:
NoneParse RSM source into an abstract syntax tree.
Examples
>>> src = "Hello, RSM!"
The abstractify step is run by default.
>>> parser = rsm.tsparser.TSParser() >>> ast = parser.parse(src) >>> print(ast.sexp()) (Manuscript (Paragraph (Text)))
The concrete syntax tree is also available.
>>> cst = parser.parse(src, abstractify=False) >>> rsm.tsparser.print_cst(cst) (source_file Point(row=0, column=0) - Point(row=0, column=11) (paragraph Point(row=0, column=0) - Point(row=0, column=11) (text Point(row=0, column=0) - Point(row=0, column=11) "Hello, RSM!") (paragraph_end Point(row=0, column=11) - Point(row=0, column=11))))
Methods
Parse RSM source into a syntax tree.
Attributes
The concrete syntax tree generated from the source.
The abstract manuscript tree generated from the concrete syntax tree.
- ast: Manuscript | None[source]#
The abstract manuscript tree generated from the concrete syntax tree.
- parse(src, abstractify=True)[source]#
Parse RSM source into a syntax tree.
For examples see class docstring.
- Parameters:
src (str) – String containing RSM source.
abstractify (bool) – Whether to run the abstractify step.
- Returns:
tree – Either an abstract syntax tree (if abstractify is
True) or a concrete syntax tree (if abstractify isFalse).- Return type:
Tree | Manuscript
Notes
Populates the attributes
cstandastwith the concrete and abstract syntax trees, respectively.