aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/ucdgen/main.go2
-rw-r--r--cmd/vartan-go/generate.go14
-rw-r--r--cmd/vartan/compile.go13
-rw-r--r--cmd/vartan/parse.go11
-rw-r--r--cmd/vartan/root.go21
-rw-r--r--cmd/vartan/show.go9
-rw-r--r--cmd/vartan/test.go7
7 files changed, 50 insertions, 27 deletions
diff --git a/cmd/ucdgen/main.go b/cmd/ucdgen/main.go
index 6d7d33e..aeb88e2 100644
--- a/cmd/ucdgen/main.go
+++ b/cmd/ucdgen/main.go
@@ -7,7 +7,7 @@ import (
"strings"
"text/template"
- "github.com/nihei9/vartan/ucd"
+ "ucd"
)
func main() {
diff --git a/cmd/vartan-go/generate.go b/cmd/vartan-go/generate.go
index 7d95ed7..7d84da9 100644
--- a/cmd/vartan-go/generate.go
+++ b/cmd/vartan-go/generate.go
@@ -2,24 +2,25 @@ package main
import (
"encoding/json"
- "fmt"
+ // "fmt"
"io"
"os"
- "github.com/nihei9/vartan/driver/lexer"
- "github.com/nihei9/vartan/driver/parser"
- spec "github.com/nihei9/vartan/spec/grammar"
- "github.com/spf13/cobra"
+ // "driver/lexer"
+ // "driver/parser"
+ spec "spec/grammar"
)
func Execute() error {
- return generateCmd.Execute()
+ // return generateCmd.Execute()
+ return nil
}
var generateFlags = struct {
pkgName *string
}{}
+/*
var generateCmd = &cobra.Command{
Use: "vartan-go",
Short: "Generate a parser for Go",
@@ -103,6 +104,7 @@ func runGenerate(cmd *cobra.Command, args []string) error {
return nil
}
+*/
func readCompiledGrammar(path string) (*spec.CompiledGrammar, error) {
f, err := os.Open(path)
diff --git a/cmd/vartan/compile.go b/cmd/vartan/compile.go
index e645366..0755456 100644
--- a/cmd/vartan/compile.go
+++ b/cmd/vartan/compile.go
@@ -7,17 +7,17 @@ import (
"os"
"path/filepath"
- verr "github.com/nihei9/vartan/error"
- "github.com/nihei9/vartan/grammar"
- spec "github.com/nihei9/vartan/spec/grammar"
- "github.com/nihei9/vartan/spec/grammar/parser"
- "github.com/spf13/cobra"
+ verr "error"
+ "grammar"
+ spec "spec/grammar"
+ "spec/grammar/parser"
)
var compileFlags = struct {
output *string
}{}
+/*
func init() {
cmd := &cobra.Command{
Use: "compile",
@@ -29,8 +29,9 @@ func init() {
compileFlags.output = cmd.Flags().StringP("output", "o", "", "output file path (default stdout)")
rootCmd.AddCommand(cmd)
}
+*/
-func runCompile(cmd *cobra.Command, args []string) (retErr error) {
+func runCompile(args []string) (retErr error) {
var tmpDirPath string
defer func() {
if tmpDirPath == "" {
diff --git a/cmd/vartan/parse.go b/cmd/vartan/parse.go
index 8b3e34e..50d867e 100644
--- a/cmd/vartan/parse.go
+++ b/cmd/vartan/parse.go
@@ -7,10 +7,9 @@ import (
"os"
"strings"
- driver "github.com/nihei9/vartan/driver/parser"
- spec "github.com/nihei9/vartan/spec/grammar"
- "github.com/nihei9/vartan/tester"
- "github.com/spf13/cobra"
+ driver "driver/parser"
+ spec "spec/grammar"
+ "tester"
)
var parseFlags = struct {
@@ -27,6 +26,7 @@ const (
outputFormatJSON = "json"
)
+/*
func init() {
cmd := &cobra.Command{
Use: "parse <grammar file path>",
@@ -42,8 +42,9 @@ func init() {
parseFlags.format = cmd.Flags().StringP("format", "f", "text", "output format: one of text|tree|json")
rootCmd.AddCommand(cmd)
}
+*/
-func runParse(cmd *cobra.Command, args []string) error {
+func runParse(args []string) error {
if *parseFlags.onlyParse && *parseFlags.cst {
return fmt.Errorf("You cannot enable --only-parse and --cst at the same time")
}
diff --git a/cmd/vartan/root.go b/cmd/vartan/root.go
index 8d2219d..32eb3c3 100644
--- a/cmd/vartan/root.go
+++ b/cmd/vartan/root.go
@@ -1,9 +1,10 @@
package main
import (
- "github.com/spf13/cobra"
+ "os"
)
+/*
var rootCmd = &cobra.Command{
Use: "vartan",
Short: "Generate a portable LALR(1) parsing table from grammar you defined",
@@ -13,7 +14,23 @@ var rootCmd = &cobra.Command{
SilenceErrors: true,
SilenceUsage: true,
}
+*/
func Execute() error {
- return rootCmd.Execute()
+ // return rootCmd.Execute()
+
+ cmd := os.Args[1]
+ args := os.Args[2:]
+
+ if cmd == "compile" {
+ return runCompile(args)
+ } else if cmd == "parse" {
+ return runParse(args)
+ } else if cmd == "show" {
+ return runShow(args)
+ } else if cmd == "test" {
+ return runTest(args)
+ }
+
+ return nil // FIXME
}
diff --git a/cmd/vartan/show.go b/cmd/vartan/show.go
index c142623..c56be1f 100644
--- a/cmd/vartan/show.go
+++ b/cmd/vartan/show.go
@@ -8,11 +8,11 @@ import (
"strings"
"text/template"
- "github.com/nihei9/vartan/grammar"
- spec "github.com/nihei9/vartan/spec/grammar"
- "github.com/spf13/cobra"
+ "grammar"
+ spec "spec/grammar"
)
+/*
func init() {
cmd := &cobra.Command{
Use: "show",
@@ -23,8 +23,9 @@ func init() {
}
rootCmd.AddCommand(cmd)
}
+*/
-func runShow(cmd *cobra.Command, args []string) error {
+func runShow(args []string) error {
report, err := readReport(args[0])
if err != nil {
return err
diff --git a/cmd/vartan/test.go b/cmd/vartan/test.go
index 9bd88ff..73949e0 100644
--- a/cmd/vartan/test.go
+++ b/cmd/vartan/test.go
@@ -5,10 +5,10 @@ import (
"fmt"
"os"
- "github.com/nihei9/vartan/tester"
- "github.com/spf13/cobra"
+ "tester"
)
+/*
func init() {
cmd := &cobra.Command{
Use: "test <grammar file path> <test file path>|<test directory path>",
@@ -19,8 +19,9 @@ func init() {
}
rootCmd.AddCommand(cmd)
}
+*/
-func runTest(cmd *cobra.Command, args []string) error {
+func runTest(args []string) error {
gram, _, err := readGrammar(args[0])
if err != nil {
return fmt.Errorf("Cannot read a grammar: %w", err)