csv

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/csv"

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

type exampleListener struct {
	*csv.BaseCSVListener
}

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

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

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

Index

Examples

Constants

View Source
const (
	CSVLexerT__0   = 1
	CSVLexerT__1   = 2
	CSVLexerT__2   = 3
	CSVLexerTEXT   = 4
	CSVLexerSTRING = 5
)

CSVLexer tokens.

View Source
const (
	CSVParserEOF    = antlr.TokenEOF
	CSVParserT__0   = 1
	CSVParserT__1   = 2
	CSVParserT__2   = 3
	CSVParserTEXT   = 4
	CSVParserSTRING = 5
)

CSVParser tokens.

View Source
const (
	CSVParserRULE_csvFile = 0
	CSVParserRULE_hdr     = 1
	CSVParserRULE_row     = 2
	CSVParserRULE_field   = 3
)

CSVParser rules.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseCSVListener

type BaseCSVListener struct{}

BaseCSVListener is a complete listener for a parse tree produced by CSVParser.

func (*BaseCSVListener) EnterCsvFile

func (s *BaseCSVListener) EnterCsvFile(ctx *CsvFileContext)

EnterCsvFile is called when production csvFile is entered.

func (*BaseCSVListener) EnterEveryRule

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

EnterEveryRule is called when any rule is entered.

func (*BaseCSVListener) EnterField

func (s *BaseCSVListener) EnterField(ctx *FieldContext)

EnterField is called when production field is entered.

func (*BaseCSVListener) EnterHdr

func (s *BaseCSVListener) EnterHdr(ctx *HdrContext)

EnterHdr is called when production hdr is entered.

func (*BaseCSVListener) EnterRow

func (s *BaseCSVListener) EnterRow(ctx *RowContext)

EnterRow is called when production row is entered.

func (*BaseCSVListener) ExitCsvFile

func (s *BaseCSVListener) ExitCsvFile(ctx *CsvFileContext)

ExitCsvFile is called when production csvFile is exited.

func (*BaseCSVListener) ExitEveryRule

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

ExitEveryRule is called when any rule is exited.

func (*BaseCSVListener) ExitField

func (s *BaseCSVListener) ExitField(ctx *FieldContext)

ExitField is called when production field is exited.

func (*BaseCSVListener) ExitHdr

func (s *BaseCSVListener) ExitHdr(ctx *HdrContext)

ExitHdr is called when production hdr is exited.

func (*BaseCSVListener) ExitRow

func (s *BaseCSVListener) ExitRow(ctx *RowContext)

ExitRow is called when production row is exited.

func (*BaseCSVListener) VisitErrorNode

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

VisitErrorNode is called when an error node is visited.

func (*BaseCSVListener) VisitTerminal

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

VisitTerminal is called when a terminal node is visited.

type CSVLexer

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

func NewCSVLexer

func NewCSVLexer(input antlr.CharStream) *CSVLexer

type CSVListener

type CSVListener interface {
	antlr.ParseTreeListener

	// EnterCsvFile is called when entering the csvFile production.
	EnterCsvFile(c *CsvFileContext)

	// EnterHdr is called when entering the hdr production.
	EnterHdr(c *HdrContext)

	// EnterRow is called when entering the row production.
	EnterRow(c *RowContext)

	// EnterField is called when entering the field production.
	EnterField(c *FieldContext)

	// ExitCsvFile is called when exiting the csvFile production.
	ExitCsvFile(c *CsvFileContext)

	// ExitHdr is called when exiting the hdr production.
	ExitHdr(c *HdrContext)

	// ExitRow is called when exiting the row production.
	ExitRow(c *RowContext)

	// ExitField is called when exiting the field production.
	ExitField(c *FieldContext)
}

CSVListener is a complete listener for a parse tree produced by CSVParser.

type CSVParser

type CSVParser struct {
	*antlr.BaseParser
}

func NewCSVParser

func NewCSVParser(input antlr.TokenStream) *CSVParser

func (*CSVParser) CsvFile

func (p *CSVParser) CsvFile() (localctx ICsvFileContext)

func (*CSVParser) Field

func (p *CSVParser) Field() (localctx IFieldContext)

func (*CSVParser) Hdr

func (p *CSVParser) Hdr() (localctx IHdrContext)

func (*CSVParser) Row

func (p *CSVParser) Row() (localctx IRowContext)

type CsvFileContext

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

func NewCsvFileContext

func NewCsvFileContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *CsvFileContext

func NewEmptyCsvFileContext

func NewEmptyCsvFileContext() *CsvFileContext

func (*CsvFileContext) AllRow

func (s *CsvFileContext) AllRow() []IRowContext

func (*CsvFileContext) EnterRule

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

func (*CsvFileContext) ExitRule

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

func (*CsvFileContext) GetParser

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

func (*CsvFileContext) GetRuleContext

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

func (*CsvFileContext) Hdr

func (s *CsvFileContext) Hdr() IHdrContext

func (*CsvFileContext) IsCsvFileContext

func (*CsvFileContext) IsCsvFileContext()

func (*CsvFileContext) Row

func (s *CsvFileContext) Row(i int) IRowContext

func (*CsvFileContext) ToStringTree

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

type FieldContext

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

func NewEmptyFieldContext

func NewEmptyFieldContext() *FieldContext

func NewFieldContext

func NewFieldContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *FieldContext

func (*FieldContext) EnterRule

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

func (*FieldContext) ExitRule

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

func (*FieldContext) GetParser

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

func (*FieldContext) GetRuleContext

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

func (*FieldContext) IsFieldContext

func (*FieldContext) IsFieldContext()

func (*FieldContext) STRING

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

func (*FieldContext) TEXT

func (s *FieldContext) TEXT() antlr.TerminalNode

func (*FieldContext) ToStringTree

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

type HdrContext

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

func NewEmptyHdrContext

func NewEmptyHdrContext() *HdrContext

func NewHdrContext

func NewHdrContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *HdrContext

func (*HdrContext) EnterRule

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

func (*HdrContext) ExitRule

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

func (*HdrContext) GetParser

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

func (*HdrContext) GetRuleContext

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

func (*HdrContext) IsHdrContext

func (*HdrContext) IsHdrContext()

func (*HdrContext) Row

func (s *HdrContext) Row() IRowContext

func (*HdrContext) ToStringTree

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

type ICsvFileContext

type ICsvFileContext interface {
	antlr.ParserRuleContext

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

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

ICsvFileContext is an interface to support dynamic dispatch.

type IFieldContext

type IFieldContext interface {
	antlr.ParserRuleContext

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

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

IFieldContext is an interface to support dynamic dispatch.

type IHdrContext

type IHdrContext interface {
	antlr.ParserRuleContext

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

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

IHdrContext is an interface to support dynamic dispatch.

type IRowContext

type IRowContext interface {
	antlr.ParserRuleContext

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

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

IRowContext is an interface to support dynamic dispatch.

type RowContext

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

func NewEmptyRowContext

func NewEmptyRowContext() *RowContext

func NewRowContext

func NewRowContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *RowContext

func (*RowContext) AllField

func (s *RowContext) AllField() []IFieldContext

func (*RowContext) EnterRule

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

func (*RowContext) ExitRule

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

func (*RowContext) Field

func (s *RowContext) Field(i int) IFieldContext

func (*RowContext) GetParser

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

func (*RowContext) GetRuleContext

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

func (*RowContext) IsRowContext

func (*RowContext) IsRowContext()

func (*RowContext) ToStringTree

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

Jump to

Keyboard shortcuts

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