Documentation ¶
Overview ¶
Example ¶
package main import ( "bramp.net/antlr4/json" "fmt" "github.com/antlr/antlr4/runtime/Go/antlr" ) type exampleListener struct { *json.BaseJSONListener } func (l *exampleListener) EnterEveryRule(ctx antlr.ParserRuleContext) { fmt.Println(ctx.GetText()) } func main() { // Setup the input is := antlr.NewInputStream("...some text to parse...") // Create the Lexer lexer := json.NewJSONLexer(is) stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel) // Create the Parser p := json.NewJSONParser(stream) p.BuildParseTrees = true p.AddErrorListener(antlr.NewDiagnosticErrorListener(true)) // Finally walk the tree tree := p.Json() antlr.ParseTreeWalkerDefault.Walk(&exampleListener{}, tree) }
Output:
Index ¶
- Constants
- type ArrayContext
- func (s *ArrayContext) AllValue() []IValueContext
- func (s *ArrayContext) EnterRule(listener antlr.ParseTreeListener)
- func (s *ArrayContext) ExitRule(listener antlr.ParseTreeListener)
- func (s *ArrayContext) GetParser() antlr.Parser
- func (s *ArrayContext) GetRuleContext() antlr.RuleContext
- func (*ArrayContext) IsArrayContext()
- func (s *ArrayContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string
- func (s *ArrayContext) Value(i int) IValueContext
- type BaseJSONListener
- func (s *BaseJSONListener) EnterArray(ctx *ArrayContext)
- func (s *BaseJSONListener) EnterEveryRule(ctx antlr.ParserRuleContext)
- func (s *BaseJSONListener) EnterJson(ctx *JsonContext)
- func (s *BaseJSONListener) EnterObj(ctx *ObjContext)
- func (s *BaseJSONListener) EnterPair(ctx *PairContext)
- func (s *BaseJSONListener) EnterValue(ctx *ValueContext)
- func (s *BaseJSONListener) ExitArray(ctx *ArrayContext)
- func (s *BaseJSONListener) ExitEveryRule(ctx antlr.ParserRuleContext)
- func (s *BaseJSONListener) ExitJson(ctx *JsonContext)
- func (s *BaseJSONListener) ExitObj(ctx *ObjContext)
- func (s *BaseJSONListener) ExitPair(ctx *PairContext)
- func (s *BaseJSONListener) ExitValue(ctx *ValueContext)
- func (s *BaseJSONListener) VisitErrorNode(node antlr.ErrorNode)
- func (s *BaseJSONListener) VisitTerminal(node antlr.TerminalNode)
- type IArrayContext
- type IJsonContext
- type IObjContext
- type IPairContext
- type IValueContext
- type JSONLexer
- type JSONListener
- type JSONParser
- type JsonContext
- func (s *JsonContext) EnterRule(listener antlr.ParseTreeListener)
- func (s *JsonContext) ExitRule(listener antlr.ParseTreeListener)
- func (s *JsonContext) GetParser() antlr.Parser
- func (s *JsonContext) GetRuleContext() antlr.RuleContext
- func (*JsonContext) IsJsonContext()
- func (s *JsonContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string
- func (s *JsonContext) Value() IValueContext
- type ObjContext
- func (s *ObjContext) AllPair() []IPairContext
- func (s *ObjContext) EnterRule(listener antlr.ParseTreeListener)
- func (s *ObjContext) ExitRule(listener antlr.ParseTreeListener)
- func (s *ObjContext) GetParser() antlr.Parser
- func (s *ObjContext) GetRuleContext() antlr.RuleContext
- func (*ObjContext) IsObjContext()
- func (s *ObjContext) Pair(i int) IPairContext
- func (s *ObjContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string
- type PairContext
- func (s *PairContext) EnterRule(listener antlr.ParseTreeListener)
- func (s *PairContext) ExitRule(listener antlr.ParseTreeListener)
- func (s *PairContext) GetParser() antlr.Parser
- func (s *PairContext) GetRuleContext() antlr.RuleContext
- func (*PairContext) IsPairContext()
- func (s *PairContext) STRING() antlr.TerminalNode
- func (s *PairContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string
- func (s *PairContext) Value() IValueContext
- type ValueContext
- func (s *ValueContext) Array() IArrayContext
- func (s *ValueContext) EnterRule(listener antlr.ParseTreeListener)
- func (s *ValueContext) ExitRule(listener antlr.ParseTreeListener)
- func (s *ValueContext) GetParser() antlr.Parser
- func (s *ValueContext) GetRuleContext() antlr.RuleContext
- func (*ValueContext) IsValueContext()
- func (s *ValueContext) NUMBER() antlr.TerminalNode
- func (s *ValueContext) Obj() IObjContext
- func (s *ValueContext) STRING() antlr.TerminalNode
- func (s *ValueContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string
Examples ¶
Constants ¶
const ( JSONLexerT__0 = 1 JSONLexerT__1 = 2 JSONLexerT__2 = 3 JSONLexerT__3 = 4 JSONLexerT__4 = 5 JSONLexerT__5 = 6 JSONLexerT__6 = 7 JSONLexerT__7 = 8 JSONLexerT__8 = 9 JSONLexerSTRING = 10 JSONLexerNUMBER = 11 JSONLexerWS = 12 )
JSONLexer tokens.
const ( JSONParserEOF = antlr.TokenEOF JSONParserT__0 = 1 JSONParserT__1 = 2 JSONParserT__2 = 3 JSONParserT__3 = 4 JSONParserT__4 = 5 JSONParserT__5 = 6 JSONParserT__6 = 7 JSONParserT__7 = 8 JSONParserT__8 = 9 JSONParserSTRING = 10 JSONParserNUMBER = 11 JSONParserWS = 12 )
JSONParser tokens.
const ( JSONParserRULE_json = 0 JSONParserRULE_obj = 1 JSONParserRULE_pair = 2 JSONParserRULE_array = 3 JSONParserRULE_value = 4 )
JSONParser rules.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayContext ¶
type ArrayContext struct { *antlr.BaseParserRuleContext // contains filtered or unexported fields }
func NewArrayContext ¶
func NewArrayContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ArrayContext
func NewEmptyArrayContext ¶
func NewEmptyArrayContext() *ArrayContext
func (*ArrayContext) AllValue ¶
func (s *ArrayContext) AllValue() []IValueContext
func (*ArrayContext) EnterRule ¶
func (s *ArrayContext) EnterRule(listener antlr.ParseTreeListener)
func (*ArrayContext) ExitRule ¶
func (s *ArrayContext) ExitRule(listener antlr.ParseTreeListener)
func (*ArrayContext) GetParser ¶
func (s *ArrayContext) GetParser() antlr.Parser
func (*ArrayContext) GetRuleContext ¶
func (s *ArrayContext) GetRuleContext() antlr.RuleContext
func (*ArrayContext) IsArrayContext ¶
func (*ArrayContext) IsArrayContext()
func (*ArrayContext) ToStringTree ¶
func (s *ArrayContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string
func (*ArrayContext) Value ¶
func (s *ArrayContext) Value(i int) IValueContext
type BaseJSONListener ¶
type BaseJSONListener struct{}
BaseJSONListener is a complete listener for a parse tree produced by JSONParser.
func (*BaseJSONListener) EnterArray ¶
func (s *BaseJSONListener) EnterArray(ctx *ArrayContext)
EnterArray is called when production array is entered.
func (*BaseJSONListener) EnterEveryRule ¶
func (s *BaseJSONListener) EnterEveryRule(ctx antlr.ParserRuleContext)
EnterEveryRule is called when any rule is entered.
func (*BaseJSONListener) EnterJson ¶
func (s *BaseJSONListener) EnterJson(ctx *JsonContext)
EnterJson is called when production json is entered.
func (*BaseJSONListener) EnterObj ¶
func (s *BaseJSONListener) EnterObj(ctx *ObjContext)
EnterObj is called when production obj is entered.
func (*BaseJSONListener) EnterPair ¶
func (s *BaseJSONListener) EnterPair(ctx *PairContext)
EnterPair is called when production pair is entered.
func (*BaseJSONListener) EnterValue ¶
func (s *BaseJSONListener) EnterValue(ctx *ValueContext)
EnterValue is called when production value is entered.
func (*BaseJSONListener) ExitArray ¶
func (s *BaseJSONListener) ExitArray(ctx *ArrayContext)
ExitArray is called when production array is exited.
func (*BaseJSONListener) ExitEveryRule ¶
func (s *BaseJSONListener) ExitEveryRule(ctx antlr.ParserRuleContext)
ExitEveryRule is called when any rule is exited.
func (*BaseJSONListener) ExitJson ¶
func (s *BaseJSONListener) ExitJson(ctx *JsonContext)
ExitJson is called when production json is exited.
func (*BaseJSONListener) ExitObj ¶
func (s *BaseJSONListener) ExitObj(ctx *ObjContext)
ExitObj is called when production obj is exited.
func (*BaseJSONListener) ExitPair ¶
func (s *BaseJSONListener) ExitPair(ctx *PairContext)
ExitPair is called when production pair is exited.
func (*BaseJSONListener) ExitValue ¶
func (s *BaseJSONListener) ExitValue(ctx *ValueContext)
ExitValue is called when production value is exited.
func (*BaseJSONListener) VisitErrorNode ¶
func (s *BaseJSONListener) VisitErrorNode(node antlr.ErrorNode)
VisitErrorNode is called when an error node is visited.
func (*BaseJSONListener) VisitTerminal ¶
func (s *BaseJSONListener) VisitTerminal(node antlr.TerminalNode)
VisitTerminal is called when a terminal node is visited.
type IArrayContext ¶
type IArrayContext interface { antlr.ParserRuleContext // GetParser returns the parser. GetParser() antlr.Parser // IsArrayContext differentiates from other interfaces. IsArrayContext() }
IArrayContext is an interface to support dynamic dispatch.
type IJsonContext ¶
type IJsonContext interface { antlr.ParserRuleContext // GetParser returns the parser. GetParser() antlr.Parser // IsJsonContext differentiates from other interfaces. IsJsonContext() }
IJsonContext is an interface to support dynamic dispatch.
type IObjContext ¶
type IObjContext interface { antlr.ParserRuleContext // GetParser returns the parser. GetParser() antlr.Parser // IsObjContext differentiates from other interfaces. IsObjContext() }
IObjContext is an interface to support dynamic dispatch.
type IPairContext ¶
type IPairContext interface { antlr.ParserRuleContext // GetParser returns the parser. GetParser() antlr.Parser // IsPairContext differentiates from other interfaces. IsPairContext() }
IPairContext is an interface to support dynamic dispatch.
type IValueContext ¶
type IValueContext interface { antlr.ParserRuleContext // GetParser returns the parser. GetParser() antlr.Parser // IsValueContext differentiates from other interfaces. IsValueContext() }
IValueContext is an interface to support dynamic dispatch.
type JSONLexer ¶
func NewJSONLexer ¶
func NewJSONLexer(input antlr.CharStream) *JSONLexer
type JSONListener ¶
type JSONListener interface { antlr.ParseTreeListener // EnterJson is called when entering the json production. EnterJson(c *JsonContext) // EnterObj is called when entering the obj production. EnterObj(c *ObjContext) // EnterPair is called when entering the pair production. EnterPair(c *PairContext) // EnterArray is called when entering the array production. EnterArray(c *ArrayContext) // EnterValue is called when entering the value production. EnterValue(c *ValueContext) // ExitJson is called when exiting the json production. ExitJson(c *JsonContext) // ExitObj is called when exiting the obj production. ExitObj(c *ObjContext) // ExitPair is called when exiting the pair production. ExitPair(c *PairContext) // ExitArray is called when exiting the array production. ExitArray(c *ArrayContext) // ExitValue is called when exiting the value production. ExitValue(c *ValueContext) }
JSONListener is a complete listener for a parse tree produced by JSONParser.
type JSONParser ¶
type JSONParser struct {
*antlr.BaseParser
}
func NewJSONParser ¶
func NewJSONParser(input antlr.TokenStream) *JSONParser
func (*JSONParser) Array ¶
func (p *JSONParser) Array() (localctx IArrayContext)
func (*JSONParser) Json ¶
func (p *JSONParser) Json() (localctx IJsonContext)
func (*JSONParser) Obj ¶
func (p *JSONParser) Obj() (localctx IObjContext)
func (*JSONParser) Pair ¶
func (p *JSONParser) Pair() (localctx IPairContext)
func (*JSONParser) Value ¶
func (p *JSONParser) Value() (localctx IValueContext)
type JsonContext ¶
type JsonContext struct { *antlr.BaseParserRuleContext // contains filtered or unexported fields }
func NewEmptyJsonContext ¶
func NewEmptyJsonContext() *JsonContext
func NewJsonContext ¶
func NewJsonContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *JsonContext
func (*JsonContext) EnterRule ¶
func (s *JsonContext) EnterRule(listener antlr.ParseTreeListener)
func (*JsonContext) ExitRule ¶
func (s *JsonContext) ExitRule(listener antlr.ParseTreeListener)
func (*JsonContext) GetParser ¶
func (s *JsonContext) GetParser() antlr.Parser
func (*JsonContext) GetRuleContext ¶
func (s *JsonContext) GetRuleContext() antlr.RuleContext
func (*JsonContext) IsJsonContext ¶
func (*JsonContext) IsJsonContext()
func (*JsonContext) ToStringTree ¶
func (s *JsonContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string
func (*JsonContext) Value ¶
func (s *JsonContext) Value() IValueContext
type ObjContext ¶
type ObjContext struct { *antlr.BaseParserRuleContext // contains filtered or unexported fields }
func NewEmptyObjContext ¶
func NewEmptyObjContext() *ObjContext
func NewObjContext ¶
func NewObjContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ObjContext
func (*ObjContext) AllPair ¶
func (s *ObjContext) AllPair() []IPairContext
func (*ObjContext) EnterRule ¶
func (s *ObjContext) EnterRule(listener antlr.ParseTreeListener)
func (*ObjContext) ExitRule ¶
func (s *ObjContext) ExitRule(listener antlr.ParseTreeListener)
func (*ObjContext) GetParser ¶
func (s *ObjContext) GetParser() antlr.Parser
func (*ObjContext) GetRuleContext ¶
func (s *ObjContext) GetRuleContext() antlr.RuleContext
func (*ObjContext) IsObjContext ¶
func (*ObjContext) IsObjContext()
func (*ObjContext) Pair ¶
func (s *ObjContext) Pair(i int) IPairContext
func (*ObjContext) ToStringTree ¶
func (s *ObjContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string
type PairContext ¶
type PairContext struct { *antlr.BaseParserRuleContext // contains filtered or unexported fields }
func NewEmptyPairContext ¶
func NewEmptyPairContext() *PairContext
func NewPairContext ¶
func NewPairContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *PairContext
func (*PairContext) EnterRule ¶
func (s *PairContext) EnterRule(listener antlr.ParseTreeListener)
func (*PairContext) ExitRule ¶
func (s *PairContext) ExitRule(listener antlr.ParseTreeListener)
func (*PairContext) GetParser ¶
func (s *PairContext) GetParser() antlr.Parser
func (*PairContext) GetRuleContext ¶
func (s *PairContext) GetRuleContext() antlr.RuleContext
func (*PairContext) IsPairContext ¶
func (*PairContext) IsPairContext()
func (*PairContext) STRING ¶
func (s *PairContext) STRING() antlr.TerminalNode
func (*PairContext) ToStringTree ¶
func (s *PairContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string
func (*PairContext) Value ¶
func (s *PairContext) Value() IValueContext
type ValueContext ¶
type ValueContext struct { *antlr.BaseParserRuleContext // contains filtered or unexported fields }
func NewEmptyValueContext ¶
func NewEmptyValueContext() *ValueContext
func NewValueContext ¶
func NewValueContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ValueContext
func (*ValueContext) Array ¶
func (s *ValueContext) Array() IArrayContext
func (*ValueContext) EnterRule ¶
func (s *ValueContext) EnterRule(listener antlr.ParseTreeListener)
func (*ValueContext) ExitRule ¶
func (s *ValueContext) ExitRule(listener antlr.ParseTreeListener)
func (*ValueContext) GetParser ¶
func (s *ValueContext) GetParser() antlr.Parser
func (*ValueContext) GetRuleContext ¶
func (s *ValueContext) GetRuleContext() antlr.RuleContext
func (*ValueContext) IsValueContext ¶
func (*ValueContext) IsValueContext()
func (*ValueContext) NUMBER ¶
func (s *ValueContext) NUMBER() antlr.TerminalNode
func (*ValueContext) Obj ¶
func (s *ValueContext) Obj() IObjContext
func (*ValueContext) STRING ¶
func (s *ValueContext) STRING() antlr.TerminalNode
func (*ValueContext) ToStringTree ¶
func (s *ValueContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string