func charString(ch int) string {
var s string;
switch ch {
+ case -1: return `EOF`;
case '\a': s = `\a`;
case '\b': s = `\b`;
case '\f': s = `\f`;
}
-func (S *Scanner) scanChar() {
+func (S *Scanner) scanChar(pos token.Position) {
// '\'' already consumed
- ch := S.ch;
- S.next();
- if ch == '\\' {
- S.scanEscape('\'');
+ n := 0;
+ for S.ch != '\'' {
+ ch := S.ch;
+ n++;
+ S.next();
+ if ch == '\n' || ch < 0 {
+ S.error(pos, "character literal not terminated");
+ n = 1;
+ break;
+ }
+ if ch == '\\' {
+ S.scanEscape('\'');
+ }
}
- S.expect('\'');
+ S.next();
+
+ if n != 1 {
+ S.error(pos, "illegal character literal");
+ }
}
switch ch {
case -1 : tok = token.EOF;
case '"' : tok = token.STRING; S.scanString(pos);
- case '\'': tok = token.CHAR; S.scanChar();
+ case '\'': tok = token.CHAR; S.scanChar(pos);
case '`' : tok = token.STRING; S.scanRawString(pos);
case ':' : tok = S.switch2(token.COLON, token.DEFINE);
case '.' :