rename parse command to show
This commit is contained in:
parent
d6dde78f74
commit
444c559510
@ -8,8 +8,8 @@ import (
|
|||||||
const summary = `treerack - parser generator - https://github.com/aryszka/treerack`
|
const summary = `treerack - parser generator - https://github.com/aryszka/treerack`
|
||||||
|
|
||||||
const commandsHelp = `Available commands:
|
const commandsHelp = `Available commands:
|
||||||
check validates arbitrary input against a syntax definition
|
check validates an arbitrary input against a syntax definition
|
||||||
parse parses arbitrary input with a syntax definition into an abstract syntax tree
|
show parses an arbitrary input with a syntax definition and prints the abstract syntax tree
|
||||||
check-syntax validates a syntax definition
|
check-syntax validates a syntax definition
|
||||||
generate generates a parser from a syntax definition
|
generate generates a parser from a syntax definition
|
||||||
help prints the current help
|
help prints the current help
|
||||||
@ -49,12 +49,12 @@ parsed with it.`
|
|||||||
const checkExample = `Example:
|
const checkExample = `Example:
|
||||||
treerack check -syntax example.treerack foo.example`
|
treerack check -syntax example.treerack foo.example`
|
||||||
|
|
||||||
const parseUsage = `'treerack parse' takes a syntax description from a file or inline string, an arbitrary piece
|
const showUsage = `'treerack show' takes a syntax description from a file or inline string, an arbitrary piece
|
||||||
of text from the standard input, or a file, or inline string, and parses the input text with the defined syntax.
|
of text from the standard input, or a file, or inline string, and parses the input text with the defined syntax.
|
||||||
If it was successfully parsed, it prints the resulting abstract syntax tree (AST) in JSON format.`
|
If it was successfully parsed, it prints the resulting abstract syntax tree (AST) in JSON format.`
|
||||||
|
|
||||||
const parseExample = `Example:
|
const showExample = `Example:
|
||||||
treerack parse -syntax example.treerack foo.example`
|
treerack show -syntax example.treerack foo.example`
|
||||||
|
|
||||||
const checkSyntaxUsage = `'treerack check-syntax' takes a syntax description from the standard input, or a file,
|
const checkSyntaxUsage = `'treerack check-syntax' takes a syntax description from the standard input, or a file,
|
||||||
or inline string, and validates it to check whether it represents a valid syntax. It returns with non-zero exit
|
or inline string, and validates it to check whether it represents a valid syntax. It returns with non-zero exit
|
||||||
|
@ -30,8 +30,8 @@ func main() {
|
|||||||
cmd = generate
|
cmd = generate
|
||||||
case "check":
|
case "check":
|
||||||
cmd = check
|
cmd = check
|
||||||
case "parse":
|
case "show":
|
||||||
cmd = parse
|
cmd = show
|
||||||
case "help", "-help":
|
case "help", "-help":
|
||||||
mainHelp()
|
mainHelp()
|
||||||
return
|
return
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/aryszka/treerack"
|
"github.com/aryszka/treerack"
|
||||||
)
|
)
|
||||||
|
|
||||||
type parseOptions struct {
|
type showOptions struct {
|
||||||
command *commandOptions
|
command *commandOptions
|
||||||
syntax *fileOptions
|
syntax *fileOptions
|
||||||
input *fileOptions
|
input *fileOptions
|
||||||
@ -40,9 +40,9 @@ func mapNode(n *treerack.Node) *node {
|
|||||||
return &nn
|
return &nn
|
||||||
}
|
}
|
||||||
|
|
||||||
func parse(args []string) int {
|
func show(args []string) int {
|
||||||
var o parseOptions
|
var o showOptions
|
||||||
o.command = initOptions(parseUsage, parseExample, positionalInputUsage, args)
|
o.command = initOptions(showUsage, showExample, positionalInputUsage, args)
|
||||||
o.syntax = &fileOptions{typ: "syntax", flagSet: o.command.flagSet, positionalDoc: positionalInputUsage}
|
o.syntax = &fileOptions{typ: "syntax", flagSet: o.command.flagSet, positionalDoc: positionalInputUsage}
|
||||||
o.input = &fileOptions{typ: "input", flagSet: o.command.flagSet, positionalDoc: positionalInputUsage}
|
o.input = &fileOptions{typ: "input", flagSet: o.command.flagSet, positionalDoc: positionalInputUsage}
|
||||||
|
|
@ -2,13 +2,13 @@ package main
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
var parseFailureTests = convertTests("parse", checkFailureTests)
|
var showFailureTests = convertTests("show", checkFailureTests)
|
||||||
|
|
||||||
var parseTests = []mainTest{
|
var showTests = []mainTest{
|
||||||
{
|
{
|
||||||
title: "syntax as file",
|
title: "syntax as file",
|
||||||
args: []string{
|
args: []string{
|
||||||
"treerack", "parse", "-syntax", "foo_test.treerack", "-input-string", "bar",
|
"treerack", "show", "-syntax", "foo_test.treerack", "-input-string", "bar",
|
||||||
},
|
},
|
||||||
stdout: []string{
|
stdout: []string{
|
||||||
`"name":"foo"`,
|
`"name":"foo"`,
|
||||||
@ -18,7 +18,7 @@ var parseTests = []mainTest{
|
|||||||
{
|
{
|
||||||
title: "syntax as string",
|
title: "syntax as string",
|
||||||
args: []string{
|
args: []string{
|
||||||
"treerack", "parse", "-syntax-string", `foo = "bar"`, "-input-string", "bar",
|
"treerack", "show", "-syntax-string", `foo = "bar"`, "-input-string", "bar",
|
||||||
},
|
},
|
||||||
stdout: []string{
|
stdout: []string{
|
||||||
`"name":"foo"`,
|
`"name":"foo"`,
|
||||||
@ -28,7 +28,7 @@ var parseTests = []mainTest{
|
|||||||
{
|
{
|
||||||
title: "input as stdin",
|
title: "input as stdin",
|
||||||
args: []string{
|
args: []string{
|
||||||
"treerack", "parse", "-syntax-string", `foo = "bar"`,
|
"treerack", "show", "-syntax-string", `foo = "bar"`,
|
||||||
},
|
},
|
||||||
stdin: "bar",
|
stdin: "bar",
|
||||||
stdout: []string{
|
stdout: []string{
|
||||||
@ -39,7 +39,7 @@ var parseTests = []mainTest{
|
|||||||
{
|
{
|
||||||
title: "input as file",
|
title: "input as file",
|
||||||
args: []string{
|
args: []string{
|
||||||
"treerack", "parse", "-syntax-string", `foo = "bar"`, "-input", "bar_test.txt",
|
"treerack", "show", "-syntax-string", `foo = "bar"`, "-input", "bar_test.txt",
|
||||||
},
|
},
|
||||||
stdout: []string{
|
stdout: []string{
|
||||||
`"name":"foo"`,
|
`"name":"foo"`,
|
||||||
@ -49,7 +49,7 @@ var parseTests = []mainTest{
|
|||||||
{
|
{
|
||||||
title: "input as positional",
|
title: "input as positional",
|
||||||
args: []string{
|
args: []string{
|
||||||
"treerack", "parse", "-syntax-string", `foo = "bar"`, "bar_test.txt",
|
"treerack", "show", "-syntax-string", `foo = "bar"`, "bar_test.txt",
|
||||||
},
|
},
|
||||||
stdout: []string{
|
stdout: []string{
|
||||||
`"name":"foo"`,
|
`"name":"foo"`,
|
||||||
@ -59,7 +59,7 @@ var parseTests = []mainTest{
|
|||||||
{
|
{
|
||||||
title: "input as string",
|
title: "input as string",
|
||||||
args: []string{
|
args: []string{
|
||||||
"treerack", "parse", "-syntax-string", `foo = "bar"`, "-input-string", "bar",
|
"treerack", "show", "-syntax-string", `foo = "bar"`, "-input-string", "bar",
|
||||||
},
|
},
|
||||||
stdout: []string{
|
stdout: []string{
|
||||||
`"name":"foo"`,
|
`"name":"foo"`,
|
||||||
@ -69,7 +69,7 @@ var parseTests = []mainTest{
|
|||||||
{
|
{
|
||||||
title: "explicit over stdin",
|
title: "explicit over stdin",
|
||||||
args: []string{
|
args: []string{
|
||||||
"treerack", "parse", "-syntax", "foo_test.treerack", "-input-string", "bar",
|
"treerack", "show", "-syntax", "foo_test.treerack", "-input-string", "bar",
|
||||||
},
|
},
|
||||||
stdin: "invalid",
|
stdin: "invalid",
|
||||||
stdout: []string{
|
stdout: []string{
|
||||||
@ -80,7 +80,7 @@ var parseTests = []mainTest{
|
|||||||
{
|
{
|
||||||
title: "pretty",
|
title: "pretty",
|
||||||
args: []string{
|
args: []string{
|
||||||
"treerack", "parse", "-syntax-string", `foo = "bar"`, "-input-string", "bar", "-pretty",
|
"treerack", "show", "-syntax-string", `foo = "bar"`, "-input-string", "bar", "-pretty",
|
||||||
},
|
},
|
||||||
stdout: []string{
|
stdout: []string{
|
||||||
` "name": "foo"`,
|
` "name": "foo"`,
|
||||||
@ -90,7 +90,7 @@ var parseTests = []mainTest{
|
|||||||
{
|
{
|
||||||
title: "pretty and indent",
|
title: "pretty and indent",
|
||||||
args: []string{
|
args: []string{
|
||||||
"treerack", "parse", "-syntax-string", `foo = "bar"`, "-input-string", "bar", "-pretty", "-indent", "xx",
|
"treerack", "show", "-syntax-string", `foo = "bar"`, "-input-string", "bar", "-pretty", "-indent", "xx",
|
||||||
},
|
},
|
||||||
stdout: []string{
|
stdout: []string{
|
||||||
`xx"name": "foo"`,
|
`xx"name": "foo"`,
|
||||||
@ -100,7 +100,7 @@ var parseTests = []mainTest{
|
|||||||
{
|
{
|
||||||
title: "indent without pretty",
|
title: "indent without pretty",
|
||||||
args: []string{
|
args: []string{
|
||||||
"treerack", "parse", "-syntax-string", `foo = "bar"`, "-input-string", "bar", "-pretty", "-indent", "xx",
|
"treerack", "show", "-syntax-string", `foo = "bar"`, "-input-string", "bar", "-pretty", "-indent", "xx",
|
||||||
},
|
},
|
||||||
stdout: []string{
|
stdout: []string{
|
||||||
`xx"name": "foo"`,
|
`xx"name": "foo"`,
|
||||||
@ -110,7 +110,7 @@ var parseTests = []mainTest{
|
|||||||
{
|
{
|
||||||
title: "with child nodes",
|
title: "with child nodes",
|
||||||
args: []string{
|
args: []string{
|
||||||
"treerack", "parse", "-syntax-string", `foo = "bar"; doc = foo`, "-input-string", "bar",
|
"treerack", "show", "-syntax-string", `foo = "bar"; doc = foo`, "-input-string", "bar",
|
||||||
},
|
},
|
||||||
stdout: []string{
|
stdout: []string{
|
||||||
`"nodes":[`,
|
`"nodes":[`,
|
||||||
@ -119,14 +119,14 @@ var parseTests = []mainTest{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParse(t *testing.T) {
|
func TestShow(t *testing.T) {
|
||||||
runMainTest(t, mainTest{
|
runMainTest(t, mainTest{
|
||||||
title: "help",
|
title: "help",
|
||||||
args: []string{
|
args: []string{
|
||||||
"treerack", "parse", "-help",
|
"treerack", "show", "-help",
|
||||||
},
|
},
|
||||||
stdout: []string{
|
stdout: []string{
|
||||||
wrapLines(parseUsage),
|
wrapLines(showUsage),
|
||||||
"-syntax",
|
"-syntax",
|
||||||
"-syntax-string",
|
"-syntax-string",
|
||||||
"-input",
|
"-input",
|
||||||
@ -134,11 +134,11 @@ func TestParse(t *testing.T) {
|
|||||||
"-pretty",
|
"-pretty",
|
||||||
"-indent",
|
"-indent",
|
||||||
wrapLines(positionalInputUsage),
|
wrapLines(positionalInputUsage),
|
||||||
wrapLines(parseExample),
|
wrapLines(showExample),
|
||||||
wrapLines(docRef),
|
wrapLines(docRef),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
runMainTest(t, parseFailureTests...)
|
runMainTest(t, showFailureTests...)
|
||||||
runMainTest(t, parseTests...)
|
runMainTest(t, showTests...)
|
||||||
}
|
}
|
@ -20,6 +20,7 @@ input name needed in command to differentiate between syntax and input in check
|
|||||||
allchars: can have char sequence
|
allchars: can have char sequence
|
||||||
make generator output non-random (track parsers in a list in definition order)
|
make generator output non-random (track parsers in a list in definition order)
|
||||||
fix the license in the output
|
fix the license in the output
|
||||||
|
play with the int sizes
|
||||||
|
|
||||||
[releasing]
|
[releasing]
|
||||||
spellcheck
|
spellcheck
|
||||||
|
Loading…
Reference in New Issue
Block a user