1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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)
This commit is contained in:
Solomon Hykes 2014-03-21 17:40:11 -07:00
parent cd8ddacdc7
commit fd890136a9
2 changed files with 24 additions and 3 deletions

22
pkg/dockerscript/extra.go Normal file
View file

@ -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
}

View file

@ -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()