From acdd8b3f72c56f63b099a611f148dba3838be851 Mon Sep 17 00:00:00 2001 From: Leon Mika Date: Tue, 16 Apr 2024 05:39:03 +0000 Subject: [PATCH] Added support for dashes in identities --- cmdlang/ast.go | 5 +++-- cmdlang/inst_test.go | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmdlang/ast.go b/cmdlang/ast.go index d5984aa..0a29001 100644 --- a/cmdlang/ast.go +++ b/cmdlang/ast.go @@ -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), diff --git a/cmdlang/inst_test.go b/cmdlang/inst_test.go index 2ca544a..beec7a8 100644 --- a/cmdlang/inst_test.go +++ b/cmdlang/inst_test.go @@ -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"},