From fd890136a9fc5770b0e2acf5fbb966bbb377a1f3 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 21 Mar 2014 17:40:11 -0700 Subject: [PATCH] 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 (github: shykes) --- pkg/dockerscript/extra.go | 22 ++++++++++++++++++++++ pkg/dockerscript/scanner.go | 5 ++--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 pkg/dockerscript/extra.go diff --git a/pkg/dockerscript/extra.go b/pkg/dockerscript/extra.go new file mode 100644 index 0000000000..72291c89d2 --- /dev/null +++ b/pkg/dockerscript/extra.go @@ -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 +} + diff --git a/pkg/dockerscript/scanner.go b/pkg/dockerscript/scanner.go index e0d86e343d..b208fc7810 100644 --- a/pkg/dockerscript/scanner.go +++ b/pkg/dockerscript/scanner.go @@ -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()