aboutsummaryrefslogtreecommitdiff
path: root/compiler/compiler.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-04-17 22:51:06 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-04-17 22:51:06 +0900
commit88f83624dc6d7c3b66a34c7c3f414719530e421f (patch)
tree31c0d8c966a4eaf98dd1670855298a8b4e0969c2 /compiler/compiler.go
parentChange the lexical specs of regexp and define concrete syntax error values (diff)
downloadtre-88f83624dc6d7c3b66a34c7c3f414719530e421f.tar.gz
tre-88f83624dc6d7c3b66a34c7c3f414719530e421f.tar.xz
Add validation of lexical specs and improve error messages
Diffstat (limited to 'compiler/compiler.go')
-rw-r--r--compiler/compiler.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/compiler.go b/compiler/compiler.go
index 02cda43..15f42f3 100644
--- a/compiler/compiler.go
+++ b/compiler/compiler.go
@@ -1,6 +1,7 @@
package compiler
import (
+ "fmt"
"io"
"strings"
@@ -26,6 +27,11 @@ type compilerConfig struct {
}
func Compile(lexspec *spec.LexSpec, opts ...compilerOption) (*spec.CompiledLexSpec, error) {
+ err := lexspec.Validate()
+ if err != nil {
+ return nil, fmt.Errorf("invalid lexical specification:\n%w", err)
+ }
+
config := &compilerConfig{
logger: log.NewNopLogger(),
}
@@ -36,10 +42,10 @@ func Compile(lexspec *spec.LexSpec, opts ...compilerOption) (*spec.CompiledLexSp
}
}
- var kinds []string
+ var kinds []spec.LexKind
var patterns map[int][]byte
{
- kinds = append(kinds, "")
+ kinds = append(kinds, spec.LexKindNil)
patterns = map[int][]byte{}
for i, e := range lexspec.Entries {
kinds = append(kinds, e.Kind)