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

View File

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