aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-09-23 00:18:44 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-09-23 00:18:44 +0900
commit9f3a33484b61b4291bf4093dbe145fb01a452299 (patch)
treeb438c2eb781f66a4f522b00d573584907c8b92c5
parentKeep the order of AST nodes constant (diff)
downloadtre-9f3a33484b61b4291bf4093dbe145fb01a452299.tar.gz
tre-9f3a33484b61b4291bf4093dbe145fb01a452299.tar.xz
Remove --debug option from compile command
Diffstat (limited to '')
-rw-r--r--cmd/maleeni/compile.go30
-rw-r--r--compiler/compiler.go37
-rw-r--r--log/logger.go42
3 files changed, 2 insertions, 107 deletions
diff --git a/cmd/maleeni/compile.go b/cmd/maleeni/compile.go
index a460d9b..c7a8b59 100644
--- a/cmd/maleeni/compile.go
+++ b/cmd/maleeni/compile.go
@@ -5,7 +5,6 @@ import (
"fmt"
"io/ioutil"
"os"
- "time"
"github.com/nihei9/maleeni/compiler"
"github.com/nihei9/maleeni/spec"
@@ -27,7 +26,6 @@ func init() {
Example: ` cat lexspec.json | maleeni compile > clexspec.json`,
RunE: runCompile,
}
- compileFlags.debug = cmd.Flags().BoolP("debug", "d", false, "enable logging")
compileFlags.lexSpec = cmd.Flags().StringP("lex-spec", "l", "", "lexical specification file path (default stdin)")
compileFlags.compLv = cmd.Flags().Int("compression-level", compiler.CompressionLevelMax, "compression level")
compileFlags.output = cmd.Flags().StringP("output", "o", "", "output file path (default stdout)")
@@ -40,33 +38,7 @@ func runCompile(cmd *cobra.Command, args []string) (retErr error) {
return fmt.Errorf("Cannot read a lexical specification: %w", err)
}
- opts := []compiler.CompilerOption{
- compiler.CompressionLevel(*compileFlags.compLv),
- }
- if *compileFlags.debug {
- fileName := "maleeni-compile.log"
- f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
- if err != nil {
- return fmt.Errorf("Cannot open the log file %s: %w", fileName, err)
- }
- defer f.Close()
- fmt.Fprintf(f, `maleeni compile starts.
-Date time: %v
----
-`, time.Now().Format(time.RFC3339))
- defer func() {
- fmt.Fprintf(f, "---\n")
- if retErr != nil {
- fmt.Fprintf(f, "maleeni compile failed: %v\n", retErr)
- } else {
- fmt.Fprintf(f, "maleeni compile succeeded.\n")
- }
- }()
-
- opts = append(opts, compiler.EnableLogging(f))
- }
-
- clspec, err := compiler.Compile(lspec, opts...)
+ clspec, err := compiler.Compile(lspec, compiler.CompressionLevel(*compileFlags.compLv))
if err != nil {
return err
}
diff --git a/compiler/compiler.go b/compiler/compiler.go
index 3469044..439822c 100644
--- a/compiler/compiler.go
+++ b/compiler/compiler.go
@@ -2,27 +2,13 @@ package compiler
import (
"fmt"
- "io"
- "strings"
"github.com/nihei9/maleeni/compressor"
- "github.com/nihei9/maleeni/log"
"github.com/nihei9/maleeni/spec"
)
type CompilerOption func(c *compilerConfig) error
-func EnableLogging(w io.Writer) CompilerOption {
- return func(c *compilerConfig) error {
- logger, err := log.NewLogger(w)
- if err != nil {
- return err
- }
- c.logger = logger
- return nil
- }
-}
-
func CompressionLevel(lv int) CompilerOption {
return func(c *compilerConfig) error {
if lv < CompressionLevelMin || lv > CompressionLevelMax {
@@ -34,7 +20,6 @@ func CompressionLevel(lv int) CompilerOption {
}
type compilerConfig struct {
- logger log.Logger
compLv int
}
@@ -44,9 +29,7 @@ func Compile(lexspec *spec.LexSpec, opts ...CompilerOption) (*spec.CompiledLexSp
return nil, fmt.Errorf("invalid lexical specification:\n%w", err)
}
- config := &compilerConfig{
- logger: log.NewNopLogger(),
- }
+ config := &compilerConfig{}
for _, opt := range opts {
err := opt(config)
if err != nil {
@@ -61,7 +44,6 @@ func Compile(lexspec *spec.LexSpec, opts ...CompilerOption) (*spec.CompiledLexSp
}
for i, es := range modeEntries[1:] {
modeName := modeNames[i+1]
- config.logger.Log("Compile %v mode:", modeName)
modeSpec, err := compile(es, modeName2ID, fragmetns, config)
if err != nil {
return nil, fmt.Errorf("failed to compile in %v mode: %w", modeName, err)
@@ -167,11 +149,6 @@ func compile(entries []*spec.LexEntry, modeName2ID map[spec.LexModeName]spec.Lex
kindNames = append(kindNames, e.Kind)
patterns[spec.LexModeKindID(i+1)] = []byte(e.Pattern)
}
-
- config.logger.Log("Patterns:")
- for i, p := range patterns {
- config.logger.Log(" #%v %v", i, string(p))
- }
}
push := []spec.LexModeID{
@@ -217,10 +194,6 @@ func compile(entries []*spec.LexEntry, modeName2ID map[spec.LexModeName]spec.Lex
if err != nil {
return nil, err
}
-
- var b strings.Builder
- printAST(&b, root, "", "", false)
- config.logger.Log("AST:\n%v", b.String())
}
var tranTab *spec.TransitionTable
@@ -231,14 +204,6 @@ func compile(entries []*spec.LexEntry, modeName2ID map[spec.LexModeName]spec.Lex
if err != nil {
return nil, err
}
-
- config.logger.Log(`DFA:
- States: %v states (%v entries)
- Initial State ID: %v`, tranTab.RowCount, tranTab.RowCount*tranTab.ColCount, tranTab.InitialStateID)
- config.logger.Log(" Accepting States:")
- for state, symbol := range tranTab.AcceptingStates {
- config.logger.Log(" %v: %v", state, symbol)
- }
}
var err error
diff --git a/log/logger.go b/log/logger.go
deleted file mode 100644
index 770f1c1..0000000
--- a/log/logger.go
+++ /dev/null
@@ -1,42 +0,0 @@
-package log
-
-import (
- "fmt"
- "io"
-)
-
-type Logger interface {
- Log(format string, a ...interface{})
-}
-
-var (
- _ Logger = &logger{}
- _ Logger = &nopLogger{}
-)
-
-type logger struct {
- w io.Writer
-}
-
-func NewLogger(w io.Writer) (*logger, error) {
- if w == nil {
- return nil, fmt.Errorf("w is nil; NewLogger() needs a writer")
- }
- return &logger{
- w: w,
- }, nil
-}
-
-func (l *logger) Log(format string, a ...interface{}) {
- fmt.Fprintf(l.w, format+"\n", a...)
-}
-
-type nopLogger struct {
-}
-
-func NewNopLogger() *nopLogger {
- return &nopLogger{}
-}
-
-func (l *nopLogger) Log(format string, a ...interface{}) {
-}