summaryrefslogtreecommitdiff
path: root/lang
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2026-01-07 12:09:20 +0100
committerMarc Vertes <mvertes@free.fr>2026-01-07 12:09:20 +0100
commitca80eeaa812b49afea75d3084d0c62770e4a8d18 (patch)
tree4670f02b9cb187485d229197d3c74c5cc46e9cfd /lang
parent5ad2f3a0af1204bfe364ec165ecbd742c5ac1872 (diff)
fix: set 'HasInit' token property in language definition
Diffstat (limited to 'lang')
-rw-r--r--lang/golang/go.go10
-rw-r--r--lang/spec.go16
2 files changed, 9 insertions, 17 deletions
diff --git a/lang/golang/go.go b/lang/golang/go.go
index 603b256..2085c3b 100644
--- a/lang/golang/go.go
+++ b/lang/golang/go.go
@@ -141,25 +141,25 @@ var GoSpec = &lang.Spec{
lang.Colon: {Precedence: 7},
lang.Inc: {SkipSemi: true},
lang.Dec: {SkipSemi: true},
- lang.Case: {SkipSemi: true},
+ lang.Case: {SkipSemi: true, HasInit: true},
lang.Chan: {SkipSemi: true},
lang.Const: {SkipSemi: true},
lang.Default: {SkipSemi: true},
lang.Defer: {SkipSemi: true},
lang.Else: {SkipSemi: true},
- lang.For: {SkipSemi: true},
+ lang.For: {SkipSemi: true, HasInit: true},
lang.Func: {SkipSemi: true},
lang.Go: {SkipSemi: true},
lang.Goto: {SkipSemi: true},
- lang.If: {SkipSemi: true},
+ lang.If: {SkipSemi: true, HasInit: true},
lang.Import: {SkipSemi: true},
lang.Interface: {SkipSemi: true},
lang.Map: {SkipSemi: true},
lang.Package: {SkipSemi: true},
lang.Range: {SkipSemi: true},
- lang.Select: {SkipSemi: true},
+ lang.Select: {SkipSemi: true, HasInit: true},
lang.Struct: {SkipSemi: true},
- lang.Switch: {SkipSemi: true},
+ lang.Switch: {SkipSemi: true, HasInit: true},
lang.Type: {SkipSemi: true},
lang.Var: {SkipSemi: true},
lang.MaxTok: {}, // To ensure that all Tokens have a TokenProp.
diff --git a/lang/spec.go b/lang/spec.go
index 37017e7..b8539e3 100644
--- a/lang/spec.go
+++ b/lang/spec.go
@@ -35,9 +35,10 @@ const (
// TokenProp represent token properties for parsing.
type TokenProp struct {
Token
- SkipSemi bool // automatic semicolon insertion after newline
- Precedence int // operator precedence
- Associativity
+ SkipSemi bool // automatic semicolon insertion after newline
+ Precedence int // operator precedence
+ Associativity //
+ HasInit bool // true if may have an init clause
}
// Spec represents the language specification for scanning.
@@ -52,12 +53,3 @@ type Spec struct {
NumUnder bool // true if a number can contain _ character
// TokenProps map[string]TokenProp // token properties
}
-
-// HasInit stores if a statement may contain a simple init statement.
-var HasInit = map[Token]bool{
- Case: true,
- For: true,
- If: true,
- Select: true,
- Switch: true,
-}