summaryrefslogtreecommitdiff
path: root/lang/spec.go
diff options
context:
space:
mode:
authorMarc Vertes <mvertes@free.fr>2025-12-19 18:00:34 +0100
committerMarc Vertes <mvertes@free.fr>2025-12-19 18:00:34 +0100
commit3cf8207c708f23d1bd8400de5483b6b8eadb01ca (patch)
tree7b10d04e1075490272e99c3e9bac6118406bc4ab /lang/spec.go
parentf07fc0178831432b68f1b9bd6c96b257aa2e9abe (diff)
fix lang: attribute properties to tokens, not strings
Diffstat (limited to 'lang/spec.go')
-rw-r--r--lang/spec.go28
1 files changed, 21 insertions, 7 deletions
diff --git a/lang/spec.go b/lang/spec.go
index b1b2580..37017e7 100644
--- a/lang/spec.go
+++ b/lang/spec.go
@@ -21,22 +21,36 @@ const (
// ASCIILen is the length of the ASCII characters set.
const ASCIILen = 1 << 7 // 128
+// Associativity represent the associativity rule of an operator.
+type Associativity int
+
+// Associativity kinds for operators.
+const (
+ Aboth Associativity = iota // both left and right associative
+ Aleft // left associative only
+ Aright // right associative only
+ Anon // non associative
+)
+
// TokenProp represent token properties for parsing.
type TokenProp struct {
Token
SkipSemi bool // automatic semicolon insertion after newline
Precedence int // operator precedence
+ Associativity
}
// Spec represents the language specification for scanning.
type Spec struct {
- CharProp [ASCIILen]uint // special Character properties
- End map[string]string // end delimiters, indexed by start
- BlockProp map[string]uint // block properties
- TokenProps map[string]TokenProp // token properties
- DotNum bool // true if a number can start with '.'
- IdentASCII bool // true if an identifier can be in ASCII only
- NumUnder bool // true if a number can contain _ character
+ CharProp [ASCIILen]uint // special Character properties
+ End map[string]string // end delimiters, indexed by start
+ BlockProp map[string]uint // block properties
+ Tokens map[string]Token // token per string
+ TokenProps []TokenProp // token properties, indexed by token
+ DotNum bool // true if a number can start with '.'
+ IdentASCII bool // true if an identifier can be in ASCII only
+ 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.