Class EcoreEnabledParser<R, P, C, T>Abstract

A parser that supports exporting AST's to EMF/Ecore. In particular, this parser can generate the metamodel. We can then use toEObject(node) to translate a tree into its EMF representation.

Type Parameters

  • R extends Node
  • P extends ANTLRParser
  • C extends ParserRuleContext
  • T extends TylasuToken

Hierarchy (view full)

Implements

Constructors

Properties

tokenFactory: TokenFactory<T>

Methods

  • Traverses the AST to ensure that parent nodes are correctly assigned.

    If you assign the parents correctly when you build the AST, or you're not interested in tracking child-parent relationships, you can override this method to do nothing to improve performance.

    Parameters

    • ast: R

    Returns void

  • Implement this method to tell the parser how to generate the metamodel. See [MetamodelBuilder].

    Parameters

    • resource: Resource

    Returns void

  • Invokes the parser's root rule, i.e., the method which is responsible of parsing the entire input. Usually this is the topmost rule, the one with index 0 (as also assumed by other libraries such as antlr4-c3), so this method invokes that rule. If your grammar/parser is structured differently, or if you're using this to parse only a portion of the input or a subset of the language, you have to override this method to invoke the correct entry point.

    Parameters

    • parser: P

    Returns C

  • Parses source code, returning a result that includes an AST and a collection of parse issues (errors, warnings). The parsing is done in accordance to the StarLasu methodology i.e. a first-stage parser builds a parse tree which is then mapped onto a higher-level tree called the AST.

    Parameters

    • code: string | CharStream

      the source code.

    • considerPosition: boolean = true

      if true (the default), parsed AST nodes record their position in the input text.

    • measureLexingTime: boolean = true

      if true, the result will include a measurement of the time spent in lexing i.e. breaking

    • Optional source: Source

      the optional Source to associate to node positions. the input stream into tokens.

    Returns ParsingResult<R>

  • Checks the parse tree for correctness. If you're concerned about performance, you may want to override this to do nothing.

    Parameters

    • parser: Parser
    • issues: Issue[]
    • root: ParserRuleContext

    Returns void

Generated using TypeDoc