dockerscript: patch text/scanner to use a shell-like syntax instead of the default go-like syntax

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
Upstream-commit: fd890136a9fc5770b0e2acf5fbb966bbb377a1f3
Component: engine
This commit is contained in:
Solomon Hykes
2014-04-22 15:50:15 -07:00
parent 27b0b6b2ee
commit d22e5562e8
2 changed files with 24 additions and 3 deletions
@@ -0,0 +1,22 @@
package scanner
import (
"unicode"
"strings"
)
// extra functions used to hijack the upstream text/scanner
func detectIdent(ch rune) bool {
if unicode.IsLetter(ch) {
return true
}
if unicode.IsDigit(ch) {
return true
}
if strings.ContainsRune("_:/+-@%^", ch) {
return true
}
return false
}
@@ -30,7 +30,6 @@ import (
"fmt"
"io"
"os"
"unicode"
"unicode/utf8"
)
@@ -336,7 +335,7 @@ func (s *Scanner) error(msg string) {
func (s *Scanner) scanIdentifier() rune {
ch := s.next() // read character after first '_' or letter
for ch == '_' || unicode.IsLetter(ch) || unicode.IsDigit(ch) {
for detectIdent(ch) {
ch = s.next()
}
return ch
@@ -563,7 +562,7 @@ redo:
// determine token value
tok := ch
switch {
case unicode.IsLetter(ch) || ch == '_':
case detectIdent(ch):
if s.Mode&ScanIdents != 0 {
tok = Ident
ch = s.scanIdentifier()