// current token, valid after calling next()
line, col uint
tok token
- lit string // valid if tok is _Name or _Literal
+ lit string // valid if tok is _Name, _Literal, or _Semi ("semicolon", "newline", or "EOF")
kind LitKind // valid if tok is _Literal
op Operator // valid if tok is _Operator, _AssignOp, or _IncOp
prec int // valid if tok is _Operator, _AssignOp, or _IncOp
switch c {
case -1:
if nlsemi {
+ s.lit = "EOF"
s.tok = _Semi
break
}
s.tok = _EOF
case '\n':
+ s.lit = "newline"
s.tok = _Semi
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
s.tok = _Comma
case ';':
+ s.lit = "semicolon"
s.tok = _Semi
case ')':
if s.source.line > s.line && nlsemi {
// A multi-line comment acts like a newline;
// it translates to a ';' if nlsemi is set.
+ s.lit = "newline"
s.tok = _Semi
break
}
}
switch want.tok {
+ case _Semi:
+ if got.lit != "semicolon" {
+ t.Errorf("got %s; want semicolon", got.lit)
+ }
+
case _Name, _Literal:
if got.lit != want.src {
t.Errorf("got lit = %q; want %q", got.lit, want.src)
t.Errorf("got tok = %s; want ;", got.tok)
continue
}
+ if got.lit != "newline" {
+ t.Errorf("got %s; want newline", got.lit)
+ }
}
got.next()
package main
-type T // ERROR "unexpected semicolon or newline in type declaration"
-// line below uncommented to avoid follow-up error
-// {
\ No newline at end of file
+type T1 // ERROR "unexpected newline in type declaration"
+
+type T2 /* // ERROR "unexpected EOF in type declaration" */
\ No newline at end of file