parser

package
v0.16.1-0...-73375fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 2 Imported by: 0

README

Go port

NOTE: To use the Go version you MUST make some tweaks to the grammar files manually in order to have no compiler errors.

  • In the JavaScriptLexer.g4 file, replace all occurrences of this with:
    • l inside actions (i.e., next to ProcessOpenBrace, ProcessCloseBrace, ProcessStringLiteral).
    • p inside predicates (i.e., all other).
  • In the JavaScriptParser.g4 file:
    • Replace all occurrences of this with p.
    • Replace all occurrences of emptyStatement parser rule with emptyStatement_.

WARNING: After generating both the parser and the lexer, there will be 1 runtime error.

The runtime error is caused by a nil pointer dereference, to fix this go to the generated file javascript_lexer.go and replace use of *JavaScriptLexerBase with JavaScriptLexerBase (i.e., remove *).

The cause for this is that ANTLR4 automatically adds a pointer to the embedded superClass inside [GrammarName]Lexer (JavaScriptLexer in this case) for the Go language. This behaviour is expected for single-file grammars (i.e. Both lexer and parser are inside the same file). But it does not work for multi-file settings where the superClass option is set on the lexer grammar.

For more information how to use Go target, see documentation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JavaScriptLexerBase

type JavaScriptLexerBase struct {
	*antlr.BaseLexer
	// contains filtered or unexported fields
}

JavaScriptLexerBase state

func (*JavaScriptLexerBase) IsRegexPossible

func (l *JavaScriptLexerBase) IsRegexPossible() bool

IsRegexPossible returns true if the lexer can match a regex literal.

func (*JavaScriptLexerBase) IsStartOfFile

func (l *JavaScriptLexerBase) IsStartOfFile() bool

func (*JavaScriptLexerBase) IsStrictMode

func (l *JavaScriptLexerBase) IsStrictMode() bool

IsStrictMode is self explanatory.

func (*JavaScriptLexerBase) NextToken

func (l *JavaScriptLexerBase) NextToken() antlr.Token

NextToken from the character stream.

func (*JavaScriptLexerBase) ProcessCloseBrace

func (l *JavaScriptLexerBase) ProcessCloseBrace()

ProcessCloseBrace is called when a } is encountered during lexing, we pop a scope unless we're inside global scope.

func (*JavaScriptLexerBase) ProcessOpenBrace

func (l *JavaScriptLexerBase) ProcessOpenBrace()

ProcessOpenBrace is called when a { is encountered during lexing, we push a new scope everytime.

func (*JavaScriptLexerBase) ProcessStringLiteral

func (l *JavaScriptLexerBase) ProcessStringLiteral()

ProcessStringLiteral is called when lexing a string literal.

type JavaScriptParserBase

type JavaScriptParserBase struct {
	*antlr.BaseParser
}

JavaScriptParserBase implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL