Go 2026-02
2026-06 2026-02
Grammar changes
Tokens
Source: golang/GoParser.g4 @ ed5e15c348d6125840384bc271bd76c437c556a4 (ed5e15c) / antlr4 antlr4-parser-v1 / 2026-02-08
These diagrams describe a parser grammar, rather than the complete language specification. Lexer state and semantic checks may impose additional restrictions.
This is an upstream ANTLR grammar snapshot. Its date identifies the grammar revision, rather than a language release.
BSD-3-Clause
BNF sourceFile ::= packageClause eos sourceFile__1 sourceFile__2 EOF
Used by (0)
References (4)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
package IDENTIFIER EOF
sourceFile › packageClause
BNF packageClause ::= PACKAGE packageName
Used by (1)
References (1)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
package IDENTIFIER
sourceFile › packageClause › packageName
BNF packageName ::= identifier
Used by (2)
References (1)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
IDENTIFIER
sourceFile › packageClause › packageName › identifier
BNF identifier ::= IDENTIFIER
Used by (1)
References (0)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
IDENTIFIER
sourceFile › sourceFile__1 › importDecl
BNF importDecl ::= IMPORT importDecl__1
Used by (1)
References (1)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
import RAW_STRING_LIT
sourceFile › sourceFile__1 › importDecl › importDecl__1 › importSpec
BNF importSpec ::= importSpec__1 importPath
Used by (2)
References (2)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
RAW_STRING_LIT
sourceFile › sourceFile__2 › sourceFile__3 › declaration
BNF declaration ::= constDecl
| typeDecl
| varDecl
Used by (2)
References (3)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
const IDENTIFIER
sourceFile › sourceFile__2 › sourceFile__3 › declaration › constDecl
BNF constDecl ::= CONST constDecl__1
Used by (1)
References (1)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
const IDENTIFIER
sourceFile › sourceFile__2 › sourceFile__3 › functionDecl
BNF functionDecl ::= FUNC IDENTIFIER functionDecl__1 signature functionDecl__2
Used by (1)
References (3)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
func IDENTIFIER ( )
Code example package main
func main() {
println("hello")
}
sourceFile › sourceFile__2 › sourceFile__3 › methodDecl
BNF methodDecl ::= FUNC receiver IDENTIFIER signature methodDecl__1
Used by (1)
References (3)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
func ( ) IDENTIFIER ( )
sourceFile › eos
BNF eos ::= SEMI
| EOS
| ε
Used by (13)
References (0)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
ε
Inline rule
sourceFile › sourceFile__1
BNF sourceFile__1 ::= ε
| importDecl eos sourceFile__1
Used by (2)
References (3)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
ε
Inline rule
sourceFile › sourceFile__2
BNF sourceFile__2 ::= ε
| sourceFile__3 eos sourceFile__2
Used by (2)
References (3)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
ε
Inline rule
sourceFile › sourceFile__2 › sourceFile__3
BNF sourceFile__3 ::= functionDecl
| methodDecl
| declaration
Used by (1)
References (3)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
const IDENTIFIER
Inline rule
sourceFile › sourceFile__1 › importDecl › importDecl__1
BNF importDecl__1 ::= importSpec
| L_PAREN importDecl__2 R_PAREN
Used by (1)
References (2)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
RAW_STRING_LIT
Inline rule
sourceFile › sourceFile__1 › importDecl › importDecl__1 › importDecl__2
BNF importDecl__2 ::= ε
| importSpec eos importDecl__2
Used by (2)
References (3)
Shortest derivation This is a token sequence derived from the grammar. It may require lexer context or semantic checks to be valid code.
ε