From 21fa2d131086372063262a47f0e29f78263c8199 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Fri, 20 May 2016 18:08:47 -0700 Subject: [PATCH] Format --- runtime/Go/antlr/atn_config.go | 12 ++++++------ runtime/Go/antlr/dfa.go | 4 ++-- runtime/Go/antlr/error_listener.go | 4 ++-- runtime/Go/antlr/error_strategy.go | 2 +- runtime/Go/antlr/errors.go | 2 -- runtime/Go/antlr/input_stream.go | 6 +++--- runtime/Go/antlr/interval_set.go | 2 +- runtime/Go/antlr/lexer.go | 9 ++++----- runtime/Go/antlr/lexer_atn_simulator.go | 8 ++++---- runtime/Go/antlr/parser.go | 6 +++--- runtime/Go/antlr/parser_atn_simulator.go | 2 +- runtime/Go/antlr/parser_rule_context.go | 20 +++++++++----------- runtime/Go/antlr/recognizer.go | 2 +- runtime/Go/antlr/rule_context.go | 2 -- runtime/Go/antlr/tree.go | 19 ++++++++++--------- runtime/Go/antlr/utils.go | 5 ++--- 16 files changed, 49 insertions(+), 56 deletions(-) diff --git a/runtime/Go/antlr/atn_config.go b/runtime/Go/antlr/atn_config.go index dceab1323..181a000fe 100644 --- a/runtime/Go/antlr/atn_config.go +++ b/runtime/Go/antlr/atn_config.go @@ -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 { diff --git a/runtime/Go/antlr/dfa.go b/runtime/Go/antlr/dfa.go index 54ec6ec73..70351fafb 100644 --- a/runtime/Go/antlr/dfa.go +++ b/runtime/Go/antlr/dfa.go @@ -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 diff --git a/runtime/Go/antlr/error_listener.go b/runtime/Go/antlr/error_listener.go index 12b1683e2..bd46d2e28 100644 --- a/runtime/Go/antlr/error_listener.go +++ b/runtime/Go/antlr/error_listener.go @@ -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() // // 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 { diff --git a/runtime/Go/antlr/error_strategy.go b/runtime/Go/antlr/error_strategy.go index df29be317..ace01ba34 100644 --- a/runtime/Go/antlr/error_strategy.go +++ b/runtime/Go/antlr/error_strategy.go @@ -543,7 +543,7 @@ func (this *DefaultErrorStrategy) getMissingSymbol(recognizer Parser) Token { tokenText = "" } else { ln := recognizer.GetLiteralNames() - if expectedTokenType > 0 && expectedTokenType < len(ln) { + if expectedTokenType > 0 && expectedTokenType < len(ln) { tokenText = "" } else { tokenText = "" // TODO matches the JS impl diff --git a/runtime/Go/antlr/errors.go b/runtime/Go/antlr/errors.go index 4eceb9727..a17aebb79 100644 --- a/runtime/Go/antlr/errors.go +++ b/runtime/Go/antlr/errors.go @@ -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 diff --git a/runtime/Go/antlr/input_stream.go b/runtime/Go/antlr/input_stream.go index e27c50f54..1fc6afce9 100644 --- a/runtime/Go/antlr/input_stream.go +++ b/runtime/Go/antlr/input_stream.go @@ -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 { diff --git a/runtime/Go/antlr/interval_set.go b/runtime/Go/antlr/interval_set.go index eb8b0fe1a..e916175e9 100644 --- a/runtime/Go/antlr/interval_set.go +++ b/runtime/Go/antlr/interval_set.go @@ -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)) } diff --git a/runtime/Go/antlr/lexer.go b/runtime/Go/antlr/lexer.go index d5687dce3..d6bca7ed7 100644 --- a/runtime/Go/antlr/lexer.go +++ b/runtime/Go/antlr/lexer.go @@ -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 { diff --git a/runtime/Go/antlr/lexer_atn_simulator.go b/runtime/Go/antlr/lexer_atn_simulator.go index 22abddaa9..639bd5ab2 100644 --- a/runtime/Go/antlr/lexer_atn_simulator.go +++ b/runtime/Go/antlr/lexer_atn_simulator.go @@ -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)) diff --git a/runtime/Go/antlr/parser.go b/runtime/Go/antlr/parser.go index 2ab3916aa..ce994b044 100644 --- a/runtime/Go/antlr/parser.go +++ b/runtime/Go/antlr/parser.go @@ -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) + ":") diff --git a/runtime/Go/antlr/parser_atn_simulator.go b/runtime/Go/antlr/parser_atn_simulator.go index 52211ab15..fd0a53e2a 100644 --- a/runtime/Go/antlr/parser_atn_simulator.go +++ b/runtime/Go/antlr/parser_atn_simulator.go @@ -14,7 +14,7 @@ type ParserATNSimulator struct { _input TokenStream _startIndex int _dfa *DFA - DecisionToDFA []*DFA + DecisionToDFA []*DFA mergeCache *DoubleDict _outerContext ParserRuleContext } diff --git a/runtime/Go/antlr/parser_rule_context.go b/runtime/Go/antlr/parser_rule_context.go index 78f00d3ac..28e9f4605 100644 --- a/runtime/Go/antlr/parser_rule_context.go +++ b/runtime/Go/antlr/parser_rule_context.go @@ -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 } diff --git a/runtime/Go/antlr/recognizer.go b/runtime/Go/antlr/recognizer.go index 6ada5affb..93061473f 100644 --- a/runtime/Go/antlr/recognizer.go +++ b/runtime/Go/antlr/recognizer.go @@ -110,7 +110,7 @@ func (this *BaseRecognizer) SetState(v int) { //

Used for XPath and tree pattern compilation.

// func (this *BaseRecognizer) GetRuleIndexMap() map[string]int { - + panic("Method not defined!") // var ruleNames = this.GetRuleNames() // if (ruleNames==nil) { diff --git a/runtime/Go/antlr/rule_context.go b/runtime/Go/antlr/rule_context.go index 87f5a4d1e..5c770fd9d 100644 --- a/runtime/Go/antlr/rule_context.go +++ b/runtime/Go/antlr/rule_context.go @@ -34,11 +34,9 @@ type RuleContext interface { } type BaseRuleContext struct { - parentCtx RuleContext invokingState int RuleIndex int - } func NewBaseRuleContext(parent RuleContext, invokingState int) *BaseRuleContext { diff --git a/runtime/Go/antlr/tree.go b/runtime/Go/antlr/tree.go index 222848b1c..9af09a96a 100644 --- a/runtime/Go/antlr/tree.go +++ b/runtime/Go/antlr/tree.go @@ -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 diff --git a/runtime/Go/antlr/utils.go b/runtime/Go/antlr/utils.go index 74441952e..004686f8f 100644 --- a/runtime/Go/antlr/utils.go +++ b/runtime/Go/antlr/utils.go @@ -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 {