Added support for dashes in identities

This commit is contained in:
Leon Mika 2024-04-16 05:39:03 +00:00
parent a65e6b2627
commit acdd8b3f72
2 changed files with 6 additions and 3 deletions

View File

@ -1,9 +1,10 @@
package cmdlang package cmdlang
import ( import (
"io"
"github.com/alecthomas/participle/v2" "github.com/alecthomas/participle/v2"
"github.com/alecthomas/participle/v2/lexer" "github.com/alecthomas/participle/v2/lexer"
"io"
) )
type astLiteral struct { type astLiteral struct {
@ -52,7 +53,7 @@ var scanner = lexer.MustStateful(lexer.Rules{
{"RC", `\}`, nil}, {"RC", `\}`, nil},
{"NL", `[;\n][; \n\t]*`, nil}, {"NL", `[;\n][; \n\t]*`, nil},
{"PIPE", `\|`, nil}, {"PIPE", `\|`, nil},
{"Ident", `\w+`, nil}, {"Ident", `[\w-]+`, nil},
}, },
}) })
var parser = participle.MustBuild[astScript](participle.Lexer(scanner), var parser = participle.MustBuild[astScript](participle.Lexer(scanner),

View File

@ -3,9 +3,10 @@ package cmdlang_test
import ( import (
"bytes" "bytes"
"context" "context"
"testing"
"github.com/lmika/cmdlang-proto/cmdlang" "github.com/lmika/cmdlang-proto/cmdlang"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing"
) )
func TestInst_Eval(t *testing.T) { func TestInst_Eval(t *testing.T) {
@ -15,6 +16,7 @@ func TestInst_Eval(t *testing.T) {
want string want string
}{ }{
{desc: "simple string", expr: `firstarg "hello"`, want: "hello"}, {desc: "simple string", expr: `firstarg "hello"`, want: "hello"},
{desc: "simple ident", expr: `firstarg a-test`, want: "a-test"},
// Sub-expressions // Sub-expressions
{desc: "sub expression 1", expr: `firstarg (sjoin "hello")`, want: "hello"}, {desc: "sub expression 1", expr: `firstarg (sjoin "hello")`, want: "hello"},