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

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

  • 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>

  • Executes only the first stage of the parser, i.e., the production of a parse tree. Usually, you'll want to use the [parse] method, that returns an AST which is simpler to use and query.

    Parameters

    • inputStream: CharStream
    • measureLexingTime: boolean = false

    Returns FirstStageParsingResult<C>

  • Transforms a parse tree into an AST (second parsing stage).

    Parameters

    • parseTreeRoot: C
    • considerPosition: boolean
    • issues: Issue[]
    • Optional source: Source

    Returns undefined | 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