Location-annotated abstract syntax: module venture.parser.ast¶
Location-annotated VentureScript abstract syntax, as produced by parsers.
Is you are writing a parser for a VentureScript sublanguage, produce
Located
objects as described here.
The bare abstract syntax of Venture is a recursive structure described
in venture.value.dicts
. Parsers emit abstract syntax trees
annotated with location information. Each node in the returned syntax
tree is a Located
object, carrying the raw abstract syntax and the
location (as a 2-list of the starting and ending character index,
inclusive on both sides). For example, the parse for 1 + 2
would be
constructed as:
import venture.value.dicts as e
one = Located([0, 0], e.number(1))
plus = Located([2, 2], e.symbol("+"))
two = Located([4, 4], e.number(2))
Located([0, 4], e.app(plus, one, two))
-
class
venture.parser.ast.
Located
(loc, value)¶ Bases:
tuple
-
loc
¶ Alias for field number 0
-
value
¶ Alias for field number 1
-
-
venture.parser.ast.
as_legacy_dict
(located)¶ Convert
Located
object to legacy Python dict representation.New code should not use this.
-
venture.parser.ast.
loclist
(items)¶ Create
Located
list ofLocated
items.The list spans the items’ total extent.
Assumes the items are in ascending order of location.
-
venture.parser.ast.
locmerge
(lv0, lv1, v)¶ Create
Located
object with given value spanning two located items.The extent the result spans the extent of the two given
Located
objects, which must be in location order.