This commit is contained in:
Will Faught 2016-05-20 18:08:47 -07:00
parent baaf1fe72f
commit 21fa2d1310
16 changed files with 49 additions and 56 deletions

View File

@ -2,7 +2,7 @@ package antlr
import (
"fmt"
// "reflect"
// "reflect"
"strconv"
)
@ -162,17 +162,17 @@ func (this *BaseATNConfig) equals(o interface{}) bool {
}
var b bool
if this.context==nil {
b = other.context==nil
if this.context == nil {
b = other.context == nil
} else {
b = this.context.equals(other.context)
}
return this.state.GetStateNumber() == other.state.GetStateNumber() &&
this.alt==other.alt &&
this.alt == other.alt &&
this.semanticContext.equals(other.semanticContext) &&
this.precedenceFilterSuppressed==other.precedenceFilterSuppressed &&
b;
this.precedenceFilterSuppressed == other.precedenceFilterSuppressed &&
b
}
func (this *BaseATNConfig) shortHash() string {

View File

@ -71,9 +71,9 @@ func (this *DFA) setPrecedenceStartState(precedence int, startState *DFAState) {
// s0.edges is never nil for a precedence DFA
// s0.edges is never null for a precedence DFA
if (precedence >= len(this.s0.edges)) {
if precedence >= len(this.s0.edges) {
// enlarge the slice
this.s0.edges = append( this.s0.edges, make([]*DFAState, precedence + 1 - len(this.s0.edges))...)
this.s0.edges = append(this.s0.edges, make([]*DFAState, precedence+1-len(this.s0.edges))...)
}
this.s0.edges[precedence] = startState

View File

@ -2,8 +2,8 @@ package antlr
import (
"fmt"
"strconv"
"os"
"strconv"
)
// Provides an empty default implementation of {@link ANTLRErrorListener}. The
@ -74,7 +74,7 @@ var ConsoleErrorListenerINSTANCE = NewConsoleErrorListener()
// </pre>
//
func (this *ConsoleErrorListener) SyntaxError(recognizer Recognizer, offendingSymbol interface{}, line, column int, msg string, e RecognitionException) {
fmt.Fprintln(os.Stderr, "line " + strconv.Itoa(line) + ":" + strconv.Itoa(column) + " " + msg)
fmt.Fprintln(os.Stderr, "line "+strconv.Itoa(line)+":"+strconv.Itoa(column)+" "+msg)
}
type ProxyErrorListener struct {

View File

@ -543,7 +543,7 @@ func (this *DefaultErrorStrategy) getMissingSymbol(recognizer Parser) Token {
tokenText = "<missing EOF>"
} else {
ln := recognizer.GetLiteralNames()
if expectedTokenType > 0 && expectedTokenType < len(ln) {
if expectedTokenType > 0 && expectedTokenType < len(ln) {
tokenText = "<missing " + recognizer.GetLiteralNames()[expectedTokenType] + ">"
} else {
tokenText = "<missing undefined>" // TODO matches the JS impl

View File

@ -1,7 +1,5 @@
package antlr
import ()
// The root of the ANTLR exception hierarchy. In general, ANTLR tracks just
// 3 kinds of errors: prediction errors, failed predicate errors, and
// misMatched input errors. In each case, the parser knows where it is

View File

@ -94,11 +94,11 @@ func (is *InputStream) GetText(start int, stop int) string {
}
func (is *InputStream) GetTextFromTokens(start, stop Token) string {
if ( start!=nil && stop !=nil ) {
return is.GetTextFromInterval(NewInterval(start.GetTokenIndex(), stop.GetTokenIndex()));
if start != nil && stop != nil {
return is.GetTextFromInterval(NewInterval(start.GetTokenIndex(), stop.GetTokenIndex()))
}
return "";
return ""
}
func (is *InputStream) GetTextFromInterval(i *Interval) string {

View File

@ -282,7 +282,7 @@ func (is *IntervalSet) toIndexString() string {
func (is *IntervalSet) toTokenString(literalNames []string, symbolicNames []string) string {
var names = make([]string, 0)
for _,v := range is.intervals {
for _, v := range is.intervals {
for j := v.start; j < v.stop; j++ {
names = append(names, is.elementName(literalNames, symbolicNames, j))
}

View File

@ -25,11 +25,11 @@ type Lexer interface {
type BaseLexer struct {
*BaseRecognizer
Interpreter *LexerATNSimulator
Interpreter *LexerATNSimulator
TokenStartCharIndex int
TokenStartLine int
TokenStartColumn int
ActionType int
TokenStartLine int
TokenStartColumn int
ActionType int
_input CharStream
_factory TokenFactory
@ -41,7 +41,6 @@ type BaseLexer struct {
_modeStack IntStack
_mode int
_text string
}
func NewBaseLexer(input CharStream) *BaseLexer {

View File

@ -52,7 +52,7 @@ type LexerATNSimulator struct {
recog Lexer
predictionMode int
DecisionToDFA []*DFA
DecisionToDFA []*DFA
mergeCache DoubleDict
startIndex int
line int
@ -207,9 +207,9 @@ func (this *LexerATNSimulator) execATN(input CharStream, ds0 *DFAState) int {
// that already has lots of edges out of it. e.g., .* in comments.
// print("Target for:" + str(s) + " and:" + str(t))
var target = this.getExistingTargetState(s, t)
// if PortDebug {
// fmt.Println(target)
// }
// if PortDebug {
// fmt.Println(target)
// }
if target == nil {
target = this.computeTargetState(input, s, t)
// print("Computed:" + str(target))

View File

@ -199,7 +199,7 @@ func (p *BaseParser) GetParserRuleContext() ParserRuleContext {
return p._ctx
}
func (p *BaseParser) SetParserRuleContext(v ParserRuleContext) {
func (p *BaseParser) SetParserRuleContext(v ParserRuleContext) {
p._ctx = v
}
@ -698,8 +698,8 @@ func (p *BaseParser) GetDFAStrings() string {
func (p *BaseParser) DumpDFA() {
var seenOne = false
for _, dfa := range p.Interpreter.DecisionToDFA {
if ( len(dfa.GetStates()) > 0) {
if (seenOne) {
if len(dfa.GetStates()) > 0 {
if seenOne {
fmt.Println()
}
fmt.Println("Decision " + strconv.Itoa(dfa.decision) + ":")

View File

@ -14,7 +14,7 @@ type ParserATNSimulator struct {
_input TokenStream
_startIndex int
_dfa *DFA
DecisionToDFA []*DFA
DecisionToDFA []*DFA
mergeCache *DoubleDict
_outerContext ParserRuleContext
}

View File

@ -3,7 +3,7 @@ package antlr
import (
"reflect"
"strconv"
// "fmt"
// "fmt"
)
type ParserRuleContext interface {
@ -32,7 +32,7 @@ type BaseParserRuleContext struct {
start, stop Token
exception RecognitionException
children []Tree
children []Tree
}
func NewBaseParserRuleContext(parent ParserRuleContext, invokingStateNumber int) *BaseParserRuleContext {
@ -233,29 +233,30 @@ func (prc *BaseParserRuleContext) GetTokens(ttype int) []TerminalNode {
}
}
func (prc *BaseParserRuleContext) GetPayload() interface{}{
func (prc *BaseParserRuleContext) GetPayload() interface{} {
return prc
}
func (prc *BaseParserRuleContext) getChild(ctxType reflect.Type, i int) RuleContext {
if ( prc.children==nil || i < 0 || i >= len(prc.children) ) {
if prc.children == nil || i < 0 || i >= len(prc.children) {
return nil
}
var j int = -1 // what element have we found with ctxType?
for _,o := range prc.children {
for _, o := range prc.children {
childType := reflect.TypeOf(o)
if ( childType.Implements(ctxType) ) {
if childType.Implements(ctxType) {
j++
if ( j == i ) {
if j == i {
return o.(RuleContext)
}
}
}
return nil
}
// Go lacks generics, so it's not possible for us to return the child with the correct type, but we do
// check for convertibility
@ -270,7 +271,7 @@ func (prc *BaseParserRuleContext) GetTypedRuleContexts(ctxType reflect.Type) []R
var contexts = make([]RuleContext, 0)
for _,child := range prc.children {
for _, child := range prc.children {
childType := reflect.TypeOf(child)
if childType.ConvertibleTo(ctxType) {
@ -335,11 +336,8 @@ func (this *BaseParserRuleContext) String(ruleNames []string, stop RuleContext)
return s
}
var RuleContextEmpty = NewBaseParserRuleContext(nil, -1)
type InterpreterRuleContext interface {
ParserRuleContext
}

View File

@ -34,11 +34,9 @@ type RuleContext interface {
}
type BaseRuleContext struct {
parentCtx RuleContext
invokingState int
RuleIndex int
}
func NewBaseRuleContext(parent RuleContext, invokingState int) *BaseRuleContext {

View File

@ -54,12 +54,12 @@ type ParseTreeVisitor interface {
VisitErrorNode(node ErrorNode) interface{}
}
type BaseParseTreeVisitor struct {}
type BaseParseTreeVisitor struct{}
func (v *BaseParseTreeVisitor) Visit(tree ParseTree) interface{} { return nil }
func (v *BaseParseTreeVisitor) VisitChildren(node RuleNode) interface{} { return nil }
func (v *BaseParseTreeVisitor) Visit(tree ParseTree) interface{} { return nil }
func (v *BaseParseTreeVisitor) VisitChildren(node RuleNode) interface{} { return nil }
func (v *BaseParseTreeVisitor) VisitTerminal(node TerminalNode) interface{} { return nil }
func (v *BaseParseTreeVisitor) VisitErrorNode(node ErrorNode) interface{} { return nil }
func (v *BaseParseTreeVisitor) VisitErrorNode(node ErrorNode) interface{} { return nil }
// TODO
//func (this ParseTreeVisitor) Visit(ctx) {
@ -89,11 +89,12 @@ type ParseTreeListener interface {
ExitEveryRule(ctx ParserRuleContext)
}
type BaseParseTreeListener struct {}
func (l *BaseParseTreeListener) VisitTerminal(node TerminalNode){}
func (l *BaseParseTreeListener) VisitErrorNode(node ErrorNode){}
func (l *BaseParseTreeListener) EnterEveryRule(ctx ParserRuleContext){}
func (l *BaseParseTreeListener) ExitEveryRule(ctx ParserRuleContext){}
type BaseParseTreeListener struct{}
func (l *BaseParseTreeListener) VisitTerminal(node TerminalNode) {}
func (l *BaseParseTreeListener) VisitErrorNode(node ErrorNode) {}
func (l *BaseParseTreeListener) EnterEveryRule(ctx ParserRuleContext) {}
func (l *BaseParseTreeListener) ExitEveryRule(ctx ParserRuleContext) {}
type TerminalNodeImpl struct {
parentCtx RuleContext

View File

@ -114,7 +114,6 @@ func hashCode(s string) string {
return fmt.Sprint(h.Sum32())
}
func (this *Set) length() int {
return len(this.data)
}
@ -264,10 +263,10 @@ func (this *BitSet) String() string {
vals := this.values()
valsS := make([]string, len(vals))
for i,val := range vals {
for i, val := range vals {
valsS[i] = strconv.Itoa(val)
}
return "{" + strings.Join(valsS, ", ") + "}";
return "{" + strings.Join(valsS, ", ") + "}"
}
type AltDict struct {