aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2022-03-30 21:25:40 +0900
committerRyo Nihei <nihei.dev@gmail.com>2022-03-30 21:35:12 +0900
commitb565c7ddb7cbbf2ccfb8653c9a77140d83e02c55 (patch)
tree32d16c248f238407df3a063f708fbc4a5d7f811c
parentAllow an alternative to have multiple directives (diff)
downloadurubu-b565c7ddb7cbbf2ccfb8653c9a77140d83e02c55.tar.gz
urubu-b565c7ddb7cbbf2ccfb8653c9a77140d83e02c55.tar.xz
Upgrade maleeni to v0.6.0
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--grammar/grammar.go22
-rw-r--r--spec/lexer.go2
4 files changed, 25 insertions, 5 deletions
diff --git a/go.mod b/go.mod
index 0ffb9c8..874c384 100644
--- a/go.mod
+++ b/go.mod
@@ -3,6 +3,6 @@ module github.com/nihei9/vartan
go 1.16
require (
- github.com/nihei9/maleeni v0.5.1
+ github.com/nihei9/maleeni v0.6.0
github.com/spf13/cobra v1.1.3
)
diff --git a/go.sum b/go.sum
index 1552208..e9c55e2 100644
--- a/go.sum
+++ b/go.sum
@@ -118,8 +118,8 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
-github.com/nihei9/maleeni v0.5.1 h1:/w5fT7rYpiOdYZ86OCf+V0FX7mNlEwOKYoDMA2igxJU=
-github.com/nihei9/maleeni v0.5.1/go.mod h1:d5x5jHHuema6IUi+aDPczMZQ4AlNokcKbEgB5T+70dI=
+github.com/nihei9/maleeni v0.6.0 h1:lefUhn1GrC6VVntQDk+bAYZXFRHv4QDtwLKM5/0+Q5g=
+github.com/nihei9/maleeni v0.6.0/go.mod h1:d5x5jHHuema6IUi+aDPczMZQ4AlNokcKbEgB5T+70dI=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
diff --git a/grammar/grammar.go b/grammar/grammar.go
index 2cdf2b3..1a09a22 100644
--- a/grammar/grammar.go
+++ b/grammar/grammar.go
@@ -3,6 +3,7 @@ package grammar
import (
"encoding/json"
"fmt"
+ "io"
"os"
"strings"
@@ -1074,8 +1075,17 @@ func Compile(gram *Grammar, opts ...CompileOption) (*spec.CompiledGrammar, error
opt(config)
}
- lexSpec, err := mlcompiler.Compile(gram.lexSpec, mlcompiler.CompressionLevel(mlcompiler.CompressionLevelMax))
+ lexSpec, err, cErrs := mlcompiler.Compile(gram.lexSpec, mlcompiler.CompressionLevel(mlcompiler.CompressionLevelMax))
if err != nil {
+ if len(cErrs) > 0 {
+ var b strings.Builder
+ writeCompileError(&b, cErrs[0])
+ for _, cerr := range cErrs[1:] {
+ fmt.Fprintf(&b, "\n")
+ writeCompileError(&b, cerr)
+ }
+ return nil, fmt.Errorf(b.String())
+ }
return nil, err
}
@@ -1274,3 +1284,13 @@ func Compile(gram *Grammar, opts ...CompileOption) (*spec.CompiledGrammar, error
},
}, nil
}
+
+func writeCompileError(w io.Writer, cErr *mlcompiler.CompileError) {
+ if cErr.Fragment {
+ fmt.Fprintf(w, "fragment ")
+ }
+ fmt.Fprintf(w, "%v: %v", cErr.Kind, cErr.Cause)
+ if cErr.Detail != "" {
+ fmt.Fprintf(w, ": %v", cErr.Detail)
+ }
+}
diff --git a/spec/lexer.go b/spec/lexer.go
index 6e9279d..f9ad871 100644
--- a/spec/lexer.go
+++ b/spec/lexer.go
@@ -1,4 +1,4 @@
-//go:generate maleeni compile -l lexspec.json -o clexspec.json
+//go:generate maleeni compile lexspec.json -o clexspec.json
//go:generate maleeni-go clexspec.json --package spec
package spec