Skip to content

Commit a509fc0

Browse files
authored
[golang] Partial fix of #4449: removing ambiguity in conversion vs function calls. (#4458)
* Remove one ambiguity in golang grammar. This code removes an ambiguity between conversion and function calls. We don't have a symbol table, so we assume that if we have "ID(...)" we will assume a function call, otherwise it's a conversion. The change improves the performance by more than double for restorer.go (see #4449). In addition, there are numerous problems in the refactoring of the grammar from the official spec for golang. I'm changing it back to reflect what is actually in the spec, but will employ correct refactoring techniques in the future. The use of EOF on the RHS of a lexer rule is way, way incorrect!! The use of EOF in eos is also way, way incorrect. * Fix CSharp port. * Fix rest of the current ports. * Fix Java port, add Antlr4ng and Dart ports for golang. * More fixes to ports. * More fixes to ports. * Fix Cpp port. * Add JavaScript port. * Update GoParserBase.js
1 parent acc240d commit a509fc0

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

golang/JavaScript/GoParserBase.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Parser, Token } from 'antlr4';
2+
import GoLexer from './GoLexer.js';
3+
4+
export default class GoParserBase extends Parser {
5+
constructor(input) {
6+
super(input);
7+
}
8+
9+
closingBracket() {
10+
const stream = this._input;
11+
const la = stream.LA(1);
12+
return la === GoLexer.R_CURLY || la === GoLexer.R_PAREN || la === Token.EOF;
13+
}
14+
15+
isType() {
16+
const stream = this._input;
17+
const la = stream.LA(1);
18+
return la !== GoLexer.IDENTIFIER;
19+
}
20+
21+
isNotReceive() {
22+
const stream = this._input;
23+
const la = stream.LA(2);
24+
return la !== GoLexer.RECEIVE;
25+
}
26+
}
27+

golang/desc.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<desc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../_scripts/desc.xsd">
33
<antlr-version>^4.13.0</antlr-version>
4-
<targets>Antlr4ng;Cpp;CSharp;Dart;Go;Java;Python3;TypeScript</targets>
4+
<targets>Antlr4ng;Cpp;CSharp;Dart;Go;Java;JavaScript;Python3;TypeScript</targets>
55
</desc>

0 commit comments

Comments
 (0)