diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-03-30 22:09:55 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-03-30 22:09:55 +0000 |
commit | 75cd0c848ff1a57a6fa90b79eef180e7a33b0a42 (patch) | |
tree | 26322d11da7cc220190e0b8430565ea207eb3eab /libgo/go/text/template/parse/lex.go | |
parent | 5a333029b49a1435961f5e39c5c16294da81e322 (diff) | |
download | gcc-75cd0c848ff1a57a6fa90b79eef180e7a33b0a42.tar.gz |
libgo: Update to weekly.2012-03-22.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186026 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/text/template/parse/lex.go')
-rw-r--r-- | libgo/go/text/template/parse/lex.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libgo/go/text/template/parse/lex.go b/libgo/go/text/template/parse/lex.go index 54e75ee0ca2..7705c0b88ff 100644 --- a/libgo/go/text/template/parse/lex.go +++ b/libgo/go/text/template/parse/lex.go @@ -347,6 +347,9 @@ Loop: default: l.backup() word := l.input[l.start:l.pos] + if !l.atTerminator() { + return l.errorf("unexpected character %+U", r) + } switch { case key[word] > itemKeyword: l.emit(key[word]) @@ -365,6 +368,28 @@ Loop: return lexInsideAction } +// atTerminator reports whether the input is at valid termination character to +// appear after an identifier. Mostly to catch cases like "$x+2" not being +// acceptable without a space, in case we decide one day to implement +// arithmetic. +func (l *lexer) atTerminator() bool { + r := l.peek() + if isSpace(r) { + return true + } + switch r { + case eof, ',', '|', ':': + return true + } + // Does r start the delimiter? This can be ambiguous (with delim=="//", $x/2 will + // succeed but should fail) but only in extremely rare cases caused by willfully + // bad choice of delimiter. + if rd, _ := utf8.DecodeRuneInString(l.rightDelim); rd == r { + return true + } + return false +} + // lexChar scans a character constant. The initial quote is already // scanned. Syntax checking is done by the parse. func lexChar(l *lexer) stateFn { |