TSParser#

Qualified name: rsm.tsparser.TSParser

class rsm.tsparser.TSParser[source]#

Bases: None

Parse RSM source into an abstract syntax tree.

Examples

>>> src = """
... :manuscript:
... 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 (1, 0) - (4, 0)
  (manuscript (1, 0) - (1, 12))
  (paragraph (2, 0) - (3, 0)
    (text (2, 0) - (2, 11) "Hello, RSM!")
    (paragraph_end (3, 0) - (3, 0)))
  (:: (3, 0) - (3, 2)))

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[source]#

The abstract manuscript tree generated from the concrete syntax tree.

cst[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:

Union[Tree, Manuscript]

Notes

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