Skip to content

Commit 3ef5065

Browse files
committedMar 28, 2017
[bugfix] Digits were not being handled.
1 parent 6ccd9f2 commit 3ef5065

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed
 

‎doc.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
22
Package kvalscanner implements a basic lexical scanner for KVAL (Key Value
3-
Access Language). The language has been created for more fluid access to
4-
Key-Value-like databases such as the popular BoltDb.
3+
Access Language). The language has been created for more fluid access to
4+
Key-Value-like databases such as the popular BoltDb.
55
66
Parsers can access a new Scanner() to check that a user provided string is
7-
valid according to the language's specification. For Golang, however, this
7+
valid according to the language's specification. For Golang, however, this
88
work is already done for you at http://github.com/kval-access-language/kval-parse
99
1010
The most up-to-date specification for KVAL can be found here:

‎kval-scanner.go

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ func (s *Scanner) Scan() (tok Token, lit string) {
5555
} else if isLetter(ch) {
5656
s.unread()
5757
return s.scanLiteral()
58+
} else if isDigit(ch) {
59+
s.unread()
60+
return s.scanLiteral()
5861
}
5962

6063
// Otherwise read the individual character.

‎kval-scanner_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestScan(t *testing.T) {
3838

3939
// Test a range of literals that should be allowed by the library
4040
func TestValidLiterals(t *testing.T) {
41-
var lits = []string{"āēīōūĀĒĪŌŪ", ">>>", "/)(*&^%$#@!>:!@#", "abc123", "子:?"}
41+
var lits = []string{"āēīōūĀĒĪŌŪ", ">>>", "/)(*&^%$#@!>:!@#", "abc123", "子:?", "200"}
4242
for _, s := range lits {
4343
s := NewScanner(strings.NewReader(s))
4444
var tok Token

‎kval-token.go

+25
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,31 @@ const (
2929
REGEX // Regular expression, REGEX: {PATT} ANy regex pattern inside OPATT and CPATT
3030
)
3131

32+
var ErrorLookup = map[Token]string{
33+
ILLEGAL: "ILLEGAL",
34+
EOF: "EOF", // Spacial token, EOF: Token signals the end of input
35+
WS: "WHITESPACE", // Spacial token, WS: Token signals whitespace has been found
36+
37+
LITERAL: "LITERAL", // LITERAL: String literal discovered
38+
39+
BUCKEY: "BUCKET >>>> KEY", // Other operator, BUCKKEY: >>>> Bucket to Key syntax for KVAL
40+
BUCBUC: "BUCKET >> BUCKET", // Other operator, BUCBUC: >> Bucket to Bucket syntax for KVAL
41+
KEYVAL: "KEY :: VALUE", // Other operator, KEYVALL :: Key to Value syntax for KVAL
42+
ASSIGN: "ASSIGNMENT", // Other operator, ASSIGN: => Assignment operator for KVAL renames
43+
44+
USCORE: "UNDERSCORE", // Single character operator, USCORE: _ Return unknown Key or Value
45+
OPATT: "OPEN REGEX PATTERN", // Single character operator, OPATT: { Open a regular expression pattern
46+
CPATT: "CLOSE REGEX PATTERN", // Single character operator, COATT: } Close a regular expression pattern
47+
48+
INS: "INSERT KEYWORD", // Keyword, INS: Insert capability of KVAL
49+
GET: "GET KEYWORD", // Keyword, GET: Get capability of KVAL
50+
LIS: "LIS KEYWORD", // Keyword, LIS: LIS capability of KVAL
51+
DEL: "DEL KEYWORD", // Keyword, DEL: Delete capability of KVAL
52+
REN: "REN KEYWORD", // Keyword, REN: Rename capability of KVAL
53+
54+
REGEX: "REGEX PATTERN", // Regular expression, REGEX: {PATT} ANy regex pattern inside OPATT and CPATT
55+
}
56+
3257
// Mapped values exported for KVAL Parser to verify keywords
3358
// Lookup 'LIT' value in KeyWordMap and if found we have a KVAL key word,
3459
// e.g. INS, GET, LIS, REN, DEL. If used correctly this map will help a parser

0 commit comments

Comments
 (0)
Please sign in to comment.