From c757cfdcb1ff5c1e22854b0e477853f73ecffc1a 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) --- dockerscript/extra.go | 22 ++++++++++++++++++++++ dockerscript/scanner.go | 5 ++--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 dockerscript/extra.go diff --git a/dockerscript/extra.go b/dockerscript/extra.go new file mode 100644 index 0000000..72291c8 --- /dev/null +++ b/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/dockerscript/scanner.go b/dockerscript/scanner.go index e0d86e3..b208fc7 100644 --- a/dockerscript/scanner.go +++ b/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()