xml

package
v0.0.0-...-4c43aeb Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Example
package main

import (
	"bramp.net/antlr4/xml"

	"fmt"
	"github.com/antlr/antlr4/runtime/Go/antlr"
)

type exampleListener struct {
	*xml.BaseXMLParserListener
}

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 := xml.NewXMLLexer(is)
	stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel)

	// Create the Parser
	p := xml.NewXMLParser(stream)
	p.BuildParseTrees = true
	p.AddErrorListener(antlr.NewDiagnosticErrorListener(true))

	// Finally walk the tree
	tree := p.Document()
	antlr.ParseTreeWalkerDefault.Walk(&exampleListener{}, tree)
}
Output:

Index

Examples

Constants

View Source
const (
	XMLLexerCOMMENT       = 1
	XMLLexerCDATA         = 2
	XMLLexerDTD           = 3
	XMLLexerEntityRef     = 4
	XMLLexerCharRef       = 5
	XMLLexerSEA_WS        = 6
	XMLLexerOPEN          = 7
	XMLLexerXMLDeclOpen   = 8
	XMLLexerTEXT          = 9
	XMLLexerCLOSE         = 10
	XMLLexerSPECIAL_CLOSE = 11
	XMLLexerSLASH_CLOSE   = 12
	XMLLexerSLASH         = 13
	XMLLexerEQUALS        = 14
	XMLLexerSTRING        = 15
	XMLLexerName          = 16
	XMLLexerS             = 17
	XMLLexerPI            = 18
)

XMLLexer tokens.

View Source
const (
	XMLLexerINSIDE = iota + 1
	XMLLexerPROC_INSTR
)

XMLLexer modes.

View Source
const (
	XMLParserEOF           = antlr.TokenEOF
	XMLParserCOMMENT       = 1
	XMLParserCDATA         = 2
	XMLParserDTD           = 3
	XMLParserEntityRef     = 4
	XMLParserCharRef       = 5
	XMLParserSEA_WS        = 6
	XMLParserOPEN          = 7
	XMLParserXMLDeclOpen   = 8
	XMLParserTEXT          = 9
	XMLParserCLOSE         = 10
	XMLParserSPECIAL_CLOSE = 11
	XMLParserSLASH_CLOSE   = 12
	XMLParserSLASH         = 13
	XMLParserEQUALS        = 14
	XMLParserSTRING        = 15
	XMLParserName          = 16
	XMLParserS             = 17
	XMLParserPI            = 18
)

XMLParser tokens.

View Source
const (
	XMLParserRULE_document  = 0
	XMLParserRULE_prolog    = 1
	XMLParserRULE_content   = 2
	XMLParserRULE_element   = 3
	XMLParserRULE_reference = 4
	XMLParserRULE_attribute = 5
	XMLParserRULE_chardata  = 6
	XMLParserRULE_misc      = 7
)

XMLParser rules.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttributeContext

type AttributeContext struct {
	*antlr.BaseParserRuleContext
	// contains filtered or unexported fields
}

func NewAttributeContext

func NewAttributeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AttributeContext

func NewEmptyAttributeContext

func NewEmptyAttributeContext() *AttributeContext

func (*AttributeContext) EQUALS

func (s *AttributeContext) EQUALS() antlr.TerminalNode

func (*AttributeContext) EnterRule

func (s *AttributeContext) EnterRule(listener antlr.ParseTreeListener)

func (*AttributeContext) ExitRule

func (s *AttributeContext) ExitRule(listener antlr.ParseTreeListener)

func (*AttributeContext) GetParser

func (s *AttributeContext) GetParser() antlr.Parser

func (*AttributeContext) GetRuleContext

func (s *AttributeContext) GetRuleContext() antlr.RuleContext

func (*AttributeContext) IsAttributeContext

func (*AttributeContext) IsAttributeContext()

func (*AttributeContext) Name

func (*AttributeContext) STRING

func (s *AttributeContext) STRING() antlr.TerminalNode

func (*AttributeContext) ToStringTree

func (s *AttributeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string

type BaseXMLParserListener

type BaseXMLParserListener struct{}

BaseXMLParserListener is a complete listener for a parse tree produced by XMLParser.

func (*BaseXMLParserListener) EnterAttribute

func (s *BaseXMLParserListener) EnterAttribute(ctx *AttributeContext)

EnterAttribute is called when production attribute is entered.

func (*BaseXMLParserListener) EnterChardata

func (s *BaseXMLParserListener) EnterChardata(ctx *ChardataContext)

EnterChardata is called when production chardata is entered.

func (*BaseXMLParserListener) EnterContent

func (s *BaseXMLParserListener) EnterContent(ctx *ContentContext)

EnterContent is called when production content is entered.

func (*BaseXMLParserListener) EnterDocument

func (s *BaseXMLParserListener) EnterDocument(ctx *DocumentContext)

EnterDocument is called when production document is entered.

func (*BaseXMLParserListener) EnterElement

func (s *BaseXMLParserListener) EnterElement(ctx *ElementContext)

EnterElement is called when production element is entered.

func (*BaseXMLParserListener) EnterEveryRule

func (s *BaseXMLParserListener) EnterEveryRule(ctx antlr.ParserRuleContext)

EnterEveryRule is called when any rule is entered.

func (*BaseXMLParserListener) EnterMisc

func (s *BaseXMLParserListener) EnterMisc(ctx *MiscContext)

EnterMisc is called when production misc is entered.

func (*BaseXMLParserListener) EnterProlog

func (s *BaseXMLParserListener) EnterProlog(ctx *PrologContext)

EnterProlog is called when production prolog is entered.

func (*BaseXMLParserListener) EnterReference

func (s *BaseXMLParserListener) EnterReference(ctx *ReferenceContext)

EnterReference is called when production reference is entered.

func (*BaseXMLParserListener) ExitAttribute

func (s *BaseXMLParserListener) ExitAttribute(ctx *AttributeContext)

ExitAttribute is called when production attribute is exited.

func (*BaseXMLParserListener) ExitChardata

func (s *BaseXMLParserListener) ExitChardata(ctx *ChardataContext)

ExitChardata is called when production chardata is exited.

func (*BaseXMLParserListener) ExitContent

func (s *BaseXMLParserListener) ExitContent(ctx *ContentContext)

ExitContent is called when production content is exited.

func (*BaseXMLParserListener) ExitDocument

func (s *BaseXMLParserListener) ExitDocument(ctx *DocumentContext)

ExitDocument is called when production document is exited.

func (*BaseXMLParserListener) ExitElement

func (s *BaseXMLParserListener) ExitElement(ctx *ElementContext)

ExitElement is called when production element is exited.

func (*BaseXMLParserListener) ExitEveryRule

func (s *BaseXMLParserListener) ExitEveryRule(ctx antlr.ParserRuleContext)

ExitEveryRule is called when any rule is exited.

func (*BaseXMLParserListener) ExitMisc

func (s *BaseXMLParserListener) ExitMisc(ctx *MiscContext)

ExitMisc is called when production misc is exited.

func (*BaseXMLParserListener) ExitProlog

func (s *BaseXMLParserListener) ExitProlog(ctx *PrologContext)

ExitProlog is called when production prolog is exited.

func (*BaseXMLParserListener) ExitReference

func (s *BaseXMLParserListener) ExitReference(ctx *ReferenceContext)

ExitReference is called when production reference is exited.

func (*BaseXMLParserListener) VisitErrorNode

func (s *BaseXMLParserListener) VisitErrorNode(node antlr.ErrorNode)

VisitErrorNode is called when an error node is visited.

func (*BaseXMLParserListener) VisitTerminal

func (s *BaseXMLParserListener) VisitTerminal(node antlr.TerminalNode)

VisitTerminal is called when a terminal node is visited.

type ChardataContext

type ChardataContext struct {
	*antlr.BaseParserRuleContext
	// contains filtered or unexported fields
}

func NewChardataContext

func NewChardataContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ChardataContext

func NewEmptyChardataContext

func NewEmptyChardataContext() *ChardataContext

func (*ChardataContext) EnterRule

func (s *ChardataContext) EnterRule(listener antlr.ParseTreeListener)

func (*ChardataContext) ExitRule

func (s *ChardataContext) ExitRule(listener antlr.ParseTreeListener)

func (*ChardataContext) GetParser

func (s *ChardataContext) GetParser() antlr.Parser

func (*ChardataContext) GetRuleContext

func (s *ChardataContext) GetRuleContext() antlr.RuleContext

func (*ChardataContext) IsChardataContext

func (*ChardataContext) IsChardataContext()

func (*ChardataContext) SEA_WS

func (s *ChardataContext) SEA_WS() antlr.TerminalNode

func (*ChardataContext) TEXT

func (*ChardataContext) ToStringTree

func (s *ChardataContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string

type ContentContext

type ContentContext struct {
	*antlr.BaseParserRuleContext
	// contains filtered or unexported fields
}

func NewContentContext

func NewContentContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ContentContext

func NewEmptyContentContext

func NewEmptyContentContext() *ContentContext

func (*ContentContext) AllCDATA

func (s *ContentContext) AllCDATA() []antlr.TerminalNode

func (*ContentContext) AllCOMMENT

func (s *ContentContext) AllCOMMENT() []antlr.TerminalNode

func (*ContentContext) AllChardata

func (s *ContentContext) AllChardata() []IChardataContext

func (*ContentContext) AllElement

func (s *ContentContext) AllElement() []IElementContext

func (*ContentContext) AllPI

func (s *ContentContext) AllPI() []antlr.TerminalNode

func (*ContentContext) AllReference

func (s *ContentContext) AllReference() []IReferenceContext

func (*ContentContext) CDATA

func (s *ContentContext) CDATA(i int) antlr.TerminalNode

func (*ContentContext) COMMENT

func (s *ContentContext) COMMENT(i int) antlr.TerminalNode

func (*ContentContext) Chardata

func (s *ContentContext) Chardata(i int) IChardataContext

func (*ContentContext) Element

func (s *ContentContext) Element(i int) IElementContext

func (*ContentContext) EnterRule

func (s *ContentContext) EnterRule(listener antlr.ParseTreeListener)

func (*ContentContext) ExitRule

func (s *ContentContext) ExitRule(listener antlr.ParseTreeListener)

func (*ContentContext) GetParser

func (s *ContentContext) GetParser() antlr.Parser

func (*ContentContext) GetRuleContext

func (s *ContentContext) GetRuleContext() antlr.RuleContext

func (*ContentContext) IsContentContext

func (*ContentContext) IsContentContext()

func (*ContentContext) PI

func (*ContentContext) Reference

func (s *ContentContext) Reference(i int) IReferenceContext

func (*ContentContext) ToStringTree

func (s *ContentContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string

type DocumentContext

type DocumentContext struct {
	*antlr.BaseParserRuleContext
	// contains filtered or unexported fields
}

func NewDocumentContext

func NewDocumentContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *DocumentContext

func NewEmptyDocumentContext

func NewEmptyDocumentContext() *DocumentContext

func (*DocumentContext) AllMisc

func (s *DocumentContext) AllMisc() []IMiscContext

func (*DocumentContext) Element

func (s *DocumentContext) Element() IElementContext

func (*DocumentContext) EnterRule

func (s *DocumentContext) EnterRule(listener antlr.ParseTreeListener)

func (*DocumentContext) ExitRule

func (s *DocumentContext) ExitRule(listener antlr.ParseTreeListener)

func (*DocumentContext) GetParser

func (s *DocumentContext) GetParser() antlr.Parser

func (*DocumentContext) GetRuleContext

func (s *DocumentContext) GetRuleContext() antlr.RuleContext

func (*DocumentContext) IsDocumentContext

func (*DocumentContext) IsDocumentContext()

func (*DocumentContext) Misc

func (s *DocumentContext) Misc(i int) IMiscContext

func (*DocumentContext) Prolog

func (s *DocumentContext) Prolog() IPrologContext

func (*DocumentContext) ToStringTree

func (s *DocumentContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string

type ElementContext

type ElementContext struct {
	*antlr.BaseParserRuleContext
	// contains filtered or unexported fields
}

func NewElementContext

func NewElementContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ElementContext

func NewEmptyElementContext

func NewEmptyElementContext() *ElementContext

func (*ElementContext) AllAttribute

func (s *ElementContext) AllAttribute() []IAttributeContext

func (*ElementContext) AllCLOSE

func (s *ElementContext) AllCLOSE() []antlr.TerminalNode

func (*ElementContext) AllName

func (s *ElementContext) AllName() []antlr.TerminalNode

func (*ElementContext) AllOPEN

func (s *ElementContext) AllOPEN() []antlr.TerminalNode

func (*ElementContext) Attribute

func (s *ElementContext) Attribute(i int) IAttributeContext

func (*ElementContext) CLOSE

func (s *ElementContext) CLOSE(i int) antlr.TerminalNode

func (*ElementContext) Content

func (s *ElementContext) Content() IContentContext

func (*ElementContext) EnterRule

func (s *ElementContext) EnterRule(listener antlr.ParseTreeListener)

func (*ElementContext) ExitRule

func (s *ElementContext) ExitRule(listener antlr.ParseTreeListener)

func (*ElementContext) GetParser

func (s *ElementContext) GetParser() antlr.Parser

func (*ElementContext) GetRuleContext

func (s *ElementContext) GetRuleContext() antlr.RuleContext

func (*ElementContext) IsElementContext

func (*ElementContext) IsElementContext()

func (*ElementContext) Name

func (s *ElementContext) Name(i int) antlr.TerminalNode

func (*ElementContext) OPEN

func (s *ElementContext) OPEN(i int) antlr.TerminalNode

func (*ElementContext) SLASH

func (s *ElementContext) SLASH() antlr.TerminalNode

func (*ElementContext) SLASH_CLOSE

func (s *ElementContext) SLASH_CLOSE() antlr.TerminalNode

func (*ElementContext) ToStringTree

func (s *ElementContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string

type IAttributeContext

type IAttributeContext interface {
	antlr.ParserRuleContext

	// GetParser returns the parser.
	GetParser() antlr.Parser

	// IsAttributeContext differentiates from other interfaces.
	IsAttributeContext()
}

IAttributeContext is an interface to support dynamic dispatch.

type IChardataContext

type IChardataContext interface {
	antlr.ParserRuleContext

	// GetParser returns the parser.
	GetParser() antlr.Parser

	// IsChardataContext differentiates from other interfaces.
	IsChardataContext()
}

IChardataContext is an interface to support dynamic dispatch.

type IContentContext

type IContentContext interface {
	antlr.ParserRuleContext

	// GetParser returns the parser.
	GetParser() antlr.Parser

	// IsContentContext differentiates from other interfaces.
	IsContentContext()
}

IContentContext is an interface to support dynamic dispatch.

type IDocumentContext

type IDocumentContext interface {
	antlr.ParserRuleContext

	// GetParser returns the parser.
	GetParser() antlr.Parser

	// IsDocumentContext differentiates from other interfaces.
	IsDocumentContext()
}

IDocumentContext is an interface to support dynamic dispatch.

type IElementContext

type IElementContext interface {
	antlr.ParserRuleContext

	// GetParser returns the parser.
	GetParser() antlr.Parser

	// IsElementContext differentiates from other interfaces.
	IsElementContext()
}

IElementContext is an interface to support dynamic dispatch.

type IMiscContext

type IMiscContext interface {
	antlr.ParserRuleContext

	// GetParser returns the parser.
	GetParser() antlr.Parser

	// IsMiscContext differentiates from other interfaces.
	IsMiscContext()
}

IMiscContext is an interface to support dynamic dispatch.

type IPrologContext

type IPrologContext interface {
	antlr.ParserRuleContext

	// GetParser returns the parser.
	GetParser() antlr.Parser

	// IsPrologContext differentiates from other interfaces.
	IsPrologContext()
}

IPrologContext is an interface to support dynamic dispatch.

type IReferenceContext

type IReferenceContext interface {
	antlr.ParserRuleContext

	// GetParser returns the parser.
	GetParser() antlr.Parser

	// IsReferenceContext differentiates from other interfaces.
	IsReferenceContext()
}

IReferenceContext is an interface to support dynamic dispatch.

type MiscContext

type MiscContext struct {
	*antlr.BaseParserRuleContext
	// contains filtered or unexported fields
}

func NewEmptyMiscContext

func NewEmptyMiscContext() *MiscContext

func NewMiscContext

func NewMiscContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *MiscContext

func (*MiscContext) COMMENT

func (s *MiscContext) COMMENT() antlr.TerminalNode

func (*MiscContext) EnterRule

func (s *MiscContext) EnterRule(listener antlr.ParseTreeListener)

func (*MiscContext) ExitRule

func (s *MiscContext) ExitRule(listener antlr.ParseTreeListener)

func (*MiscContext) GetParser

func (s *MiscContext) GetParser() antlr.Parser

func (*MiscContext) GetRuleContext

func (s *MiscContext) GetRuleContext() antlr.RuleContext

func (*MiscContext) IsMiscContext

func (*MiscContext) IsMiscContext()

func (*MiscContext) PI

func (s *MiscContext) PI() antlr.TerminalNode

func (*MiscContext) SEA_WS

func (s *MiscContext) SEA_WS() antlr.TerminalNode

func (*MiscContext) ToStringTree

func (s *MiscContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string

type PrologContext

type PrologContext struct {
	*antlr.BaseParserRuleContext
	// contains filtered or unexported fields
}

func NewEmptyPrologContext

func NewEmptyPrologContext() *PrologContext

func NewPrologContext

func NewPrologContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *PrologContext

func (*PrologContext) AllAttribute

func (s *PrologContext) AllAttribute() []IAttributeContext

func (*PrologContext) Attribute

func (s *PrologContext) Attribute(i int) IAttributeContext

func (*PrologContext) EnterRule

func (s *PrologContext) EnterRule(listener antlr.ParseTreeListener)

func (*PrologContext) ExitRule

func (s *PrologContext) ExitRule(listener antlr.ParseTreeListener)

func (*PrologContext) GetParser

func (s *PrologContext) GetParser() antlr.Parser

func (*PrologContext) GetRuleContext

func (s *PrologContext) GetRuleContext() antlr.RuleContext

func (*PrologContext) IsPrologContext

func (*PrologContext) IsPrologContext()

func (*PrologContext) SPECIAL_CLOSE

func (s *PrologContext) SPECIAL_CLOSE() antlr.TerminalNode

func (*PrologContext) ToStringTree

func (s *PrologContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string

func (*PrologContext) XMLDeclOpen

func (s *PrologContext) XMLDeclOpen() antlr.TerminalNode

type ReferenceContext

type ReferenceContext struct {
	*antlr.BaseParserRuleContext
	// contains filtered or unexported fields
}

func NewEmptyReferenceContext

func NewEmptyReferenceContext() *ReferenceContext

func NewReferenceContext

func NewReferenceContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ReferenceContext

func (*ReferenceContext) CharRef

func (s *ReferenceContext) CharRef() antlr.TerminalNode

func (*ReferenceContext) EnterRule

func (s *ReferenceContext) EnterRule(listener antlr.ParseTreeListener)

func (*ReferenceContext) EntityRef

func (s *ReferenceContext) EntityRef() antlr.TerminalNode

func (*ReferenceContext) ExitRule

func (s *ReferenceContext) ExitRule(listener antlr.ParseTreeListener)

func (*ReferenceContext) GetParser

func (s *ReferenceContext) GetParser() antlr.Parser

func (*ReferenceContext) GetRuleContext

func (s *ReferenceContext) GetRuleContext() antlr.RuleContext

func (*ReferenceContext) IsReferenceContext

func (*ReferenceContext) IsReferenceContext()

func (*ReferenceContext) ToStringTree

func (s *ReferenceContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string

type XMLLexer

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

func NewXMLLexer

func NewXMLLexer(input antlr.CharStream) *XMLLexer

type XMLParser

type XMLParser struct {
	*antlr.BaseParser
}

func NewXMLParser

func NewXMLParser(input antlr.TokenStream) *XMLParser

func (*XMLParser) Attribute

func (p *XMLParser) Attribute() (localctx IAttributeContext)

func (*XMLParser) Chardata

func (p *XMLParser) Chardata() (localctx IChardataContext)

func (*XMLParser) Content

func (p *XMLParser) Content() (localctx IContentContext)

func (*XMLParser) Document

func (p *XMLParser) Document() (localctx IDocumentContext)

func (*XMLParser) Element

func (p *XMLParser) Element() (localctx IElementContext)

func (*XMLParser) Misc

func (p *XMLParser) Misc() (localctx IMiscContext)

func (*XMLParser) Prolog

func (p *XMLParser) Prolog() (localctx IPrologContext)

func (*XMLParser) Reference

func (p *XMLParser) Reference() (localctx IReferenceContext)

type XMLParserListener

type XMLParserListener interface {
	antlr.ParseTreeListener

	// EnterDocument is called when entering the document production.
	EnterDocument(c *DocumentContext)

	// EnterProlog is called when entering the prolog production.
	EnterProlog(c *PrologContext)

	// EnterContent is called when entering the content production.
	EnterContent(c *ContentContext)

	// EnterElement is called when entering the element production.
	EnterElement(c *ElementContext)

	// EnterReference is called when entering the reference production.
	EnterReference(c *ReferenceContext)

	// EnterAttribute is called when entering the attribute production.
	EnterAttribute(c *AttributeContext)

	// EnterChardata is called when entering the chardata production.
	EnterChardata(c *ChardataContext)

	// EnterMisc is called when entering the misc production.
	EnterMisc(c *MiscContext)

	// ExitDocument is called when exiting the document production.
	ExitDocument(c *DocumentContext)

	// ExitProlog is called when exiting the prolog production.
	ExitProlog(c *PrologContext)

	// ExitContent is called when exiting the content production.
	ExitContent(c *ContentContext)

	// ExitElement is called when exiting the element production.
	ExitElement(c *ElementContext)

	// ExitReference is called when exiting the reference production.
	ExitReference(c *ReferenceContext)

	// ExitAttribute is called when exiting the attribute production.
	ExitAttribute(c *AttributeContext)

	// ExitChardata is called when exiting the chardata production.
	ExitChardata(c *ChardataContext)

	// ExitMisc is called when exiting the misc production.
	ExitMisc(c *MiscContext)
}

XMLParserListener is a complete listener for a parse tree produced by XMLParser.

Jump to

Keyboard shortcuts

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