diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-12-09 02:38:12 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-12-10 01:50:32 +0900 |
commit | d595194791483a71c5afaff2aa3f4b575a9d22b7 (patch) | |
tree | 65477d9fab1db2b9ded5eeda8a14ce0b235718b5 /cmd | |
parent | Add a new DFA compiler that generates DFA from a set of CPTree (diff) | |
download | tre-d595194791483a71c5afaff2aa3f4b575a9d22b7.tar.gz tre-d595194791483a71c5afaff2aa3f4b575a9d22b7.tar.xz |
Use new parser and DFA compiler
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/maleeni/compile.go | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/cmd/maleeni/compile.go b/cmd/maleeni/compile.go index c7a8b59..21e5058 100644 --- a/cmd/maleeni/compile.go +++ b/cmd/maleeni/compile.go @@ -3,8 +3,10 @@ package main import ( "encoding/json" "fmt" + "io" "io/ioutil" "os" + "strings" "github.com/nihei9/maleeni/compiler" "github.com/nihei9/maleeni/spec" @@ -38,8 +40,17 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) { return fmt.Errorf("Cannot read a lexical specification: %w", err) } - clspec, err := compiler.Compile(lspec, compiler.CompressionLevel(*compileFlags.compLv)) + clspec, err, cerrs := compiler.Compile(lspec, compiler.CompressionLevel(*compileFlags.compLv)) 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 fmt.Errorf(b.String()) + } return err } err = writeCompiledLexSpec(clspec, *compileFlags.output) @@ -50,6 +61,16 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) { return nil } +func writeCompileError(w io.Writer, cerr *compiler.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) + } +} + func readLexSpec(path string) (*spec.LexSpec, error) { r := os.Stdin if path != "" { |