From a5a63f20d7a365a1003495313ff74b806bc53a96 Mon Sep 17 00:00:00 2001 From: Erik Rasmussen Date: Wed, 15 Jan 2025 16:43:44 -0600 Subject: [PATCH] Semi and pipe tokens (#6) --- token/token.go | 6 +++++- token/token_test.go | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/token/token.go b/token/token.go index 0e8d591..9fd1591 100644 --- a/token/token.go +++ b/token/token.go @@ -32,7 +32,9 @@ const ( RBRACE // } DOLLAR // $ COLON // : + SEMI // ; COMMA // , + PIPE // | NEWLINE // \n TAB // \t @@ -119,7 +121,9 @@ var tokens = [...]string{ RBRACE: "}", DOLLAR: "$", COLON: ":", + SEMI: ";", COMMA: ",", + PIPE: "|", NEWLINE: "\n", TAB: "\t", @@ -279,7 +283,7 @@ func IsIdentifier(name string) bool { return false } switch name { - case "(", ")", "{", "}", "$", ":", ",", "\n", "\t", "#": + case "(", ")", "{", "}", "$", ":", ";", ",", "\n", "\t", "|", "#": fallthrough case "=", ":=", "::=", ":::=", "?=", "!=": return false diff --git a/token/token_test.go b/token/token_test.go index 1c298ca..f4812d9 100644 --- a/token/token_test.go +++ b/token/token_test.go @@ -508,11 +508,18 @@ var _ = Describe("Token", func() { Entry(nil, "file"), Entry(nil, "value"), Entry(nil, ""), + func(keyword string) { + Expect(token.IsIdentifier(keyword)).To(BeFalse()) + }, + ) + + DescribeTable("special characters", Entry(nil, "("), Entry(nil, ")"), Entry(nil, "{"), Entry(nil, "}"), Entry(nil, ":"), + Entry(nil, ";"), Entry(nil, "$"), Entry(nil, "#"), Entry(nil, ","), @@ -524,6 +531,7 @@ var _ = Describe("Token", func() { Entry(nil, "\t"), Entry(nil, "?="), Entry(nil, "!="), + Entry(nil, "|"), func(keyword string) { Expect(token.IsIdentifier(keyword)).To(BeFalse()) },