TSParser#

Qualified name: rsm.tsparser.TSParser

class rsm.tsparser.TSParser[source]#

Bases: None

Parse 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

Parse RSM source into a syntax tree.

Attributes

cst

The concrete syntax tree generated from the source.

ast

The abstract manuscript tree generated from the concrete syntax tree.

ast: Manuscript | None[source]#

The abstract manuscript tree generated from the concrete syntax tree.

cst: Tree | None[source]#

The concrete syntax tree generated from the source.

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 is False).

Return type:

Tree | Manuscript

Notes

Populates the attributes cst and ast with the concrete and abstract syntax trees, respectively.