Rename second parser attempt

This commit is contained in:
Dan Buch 2022-05-29 19:16:13 -04:00
parent 1452d544bb
commit 622d47071a
Signed by: meatballhat
GPG Key ID: A12F782281063434
4 changed files with 22 additions and 11 deletions

View File

@ -7,20 +7,31 @@ import (
"os"
"git.meatballhat.com/x/box-o-sand/argh"
"github.com/davecgh/go-spew/spew"
)
func main() {
asJSON := os.Getenv("ARGH_OUTPUT_JSON") == "enabled"
log.SetFlags(0)
ast, err := argh.ParseArgs2(os.Args, nil)
pt, err := argh.ParseArgs(os.Args, nil)
if err != nil {
log.Fatal(err)
}
b, err := json.MarshalIndent(ast, "", " ")
if err != nil {
log.Fatal(err)
ast := argh.NewQuerier(pt.Nodes).AST()
if asJSON {
b, err := json.MarshalIndent(ast, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(b))
return
}
fmt.Println(string(b))
spew.Dump(ast)
}

View File

@ -24,14 +24,14 @@ type ParseTree struct {
Nodes []Node `json:"nodes"`
}
func ParseArgs2(args []string, pCfg *ParserConfig) (*ParseTree, error) {
func ParseArgs(args []string, pCfg *ParserConfig) (*ParseTree, error) {
p := &parser{}
p.init(
strings.NewReader(strings.Join(args, string(nul))),
pCfg,
)
tracef("ParseArgs2(...) parser=%+#v", p)
tracef("ParseArgs(...) parser=%+#v", p)
return p.parseArgs()
}

View File

@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
)
func TestParser2(t *testing.T) {
func TestParser(t *testing.T) {
for _, tc := range []struct {
name string
args []string
@ -766,7 +766,7 @@ func TestParser2(t *testing.T) {
return
}
pt, err := argh.ParseArgs2(tc.args, tc.cfg)
pt, err := argh.ParseArgs(tc.args, tc.cfg)
if err != nil || tc.expErr != nil {
if !assert.ErrorIs(ct, err, tc.expErr) {
spew.Dump(err, tc.expErr)
@ -788,7 +788,7 @@ func TestParser2(t *testing.T) {
return
}
pt, err := argh.ParseArgs2(tc.args, tc.cfg)
pt, err := argh.ParseArgs(tc.args, tc.cfg)
if err != nil || tc.expErr != nil {
if !assert.ErrorIs(ct, err, tc.expErr) {
spew.Dump(pt)

View File

@ -34,7 +34,7 @@ func TestQuerier_Program(t *testing.T) {
},
} {
t.Run(tc.name, func(ct *testing.T) {
pt, err := argh.ParseArgs2(tc.args, tc.cfg)
pt, err := argh.ParseArgs(tc.args, tc.cfg)
require.Nil(ct, err)
prog, ok := argh.NewQuerier(pt.Nodes).Program()