diff --git a/lexer.go b/lexer.go index d94cca6..f300959 100644 --- a/lexer.go +++ b/lexer.go @@ -288,6 +288,8 @@ func lexStartExpansion(l *lexer) stateFn { return lexBracketName case isAlpha(c): return lexSimpleName + case isNum(c): + return lexNumberName } return nil // FIXME } @@ -310,6 +312,18 @@ func lexSimpleName(l *lexer) stateFn { } } +func lexNumberName(l *lexer) stateFn { + for { + if !isNum(l.next()) { + l.backup() + name := l.token() + l.emit(itemReadParam(name)) + l.ignore() + return lexText + } + } +} + func lexBracketName(l *lexer) stateFn { if l.next() == '#' { l.ignore() diff --git a/posix_test.go b/posix_test.go index e99e994..eb774a7 100644 --- a/posix_test.go +++ b/posix_test.go @@ -36,11 +36,13 @@ var paramtests = []struct { {"${null}", "", ""}, {"${unset}", "", ""}, {"${1}X${2}", "oneXtwo", ""}, + {"${11}X${22}", "elevenXtwenty-two", ""}, // Names, no brackets {"$set", "yes", ""}, {"$set$set2", "yesyes-two", ""}, - // {"$1X$2", "oneXtwo", ""}, // TODO(#3) parse numeric simple names + {"$1X$2", "oneXtwo", ""}, + {"$11X$22", "elevenXtwenty-two", ""}, // Default {"${set:-word}", "yes", ""}, @@ -154,6 +156,8 @@ func TestExpand_simple(t *testing.T) { "null": "", "1": "one", "2": "two", + "11": "eleven", + "22": "twenty-two", } for _, tt := range paramtests { @@ -171,7 +175,7 @@ func TestExpand_simple(t *testing.T) { } } -func TestExand_assignReadOnlyFunc(t *testing.T) { +func TestExpand_assignReadOnlyFunc(t *testing.T) { _, err := Expand("${unset:=word}", Func(func(s string) string { return "" })) @@ -180,7 +184,7 @@ func TestExand_assignReadOnlyFunc(t *testing.T) { } } -func TestExand_assignReadOnlyMap(t *testing.T) { +func TestExpand_assignReadOnlyMap(t *testing.T) { _, err := Expand("${unset:=word}", Map(nil)) if err == nil { t.Fatal("assignment on read-only map should return an error")