Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2363,10 +2363,6 @@ L:
x = p.parseSelector(p.checkExprOrType(x))
case token.LPAREN:
x = p.parseTypeAssertion(p.checkExpr(x))
case token.GOTO, token.BREAK, token.CONTINUE, token.FALLTHROUGH:
// XGo: allow goto() as a function
p.tok = token.IDENT
x = p.parseSelector(p.checkExprOrType(x))
default:
pos := p.pos
p.errorExpected(pos, "selector or type assertion", 2)
Expand Down
30 changes: 18 additions & 12 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ type Scanner struct {
rdOffset int // reading offset (position after current character)
lineOffset int // current line offset
nParen int
unitVal string
peekLit string
peekTok token.Token
insertSemi bool // insert a semicolon before next newline

// public state - ok to modify
Expand Down Expand Up @@ -511,11 +512,11 @@ func (s *Scanner) scanNumber() (token.Token, string) {
case "r":
tok = token.RAT
default:
s.unitVal = id
s.peekTok, s.peekLit = token.UNIT, id
}
}

lit := string(s.src[offs : s.offset-len(s.unitVal)])
lit := string(s.src[offs : s.offset-len(s.peekLit)])
if tok == token.INT && invalid >= 0 {
s.errorf(invalid, "invalid digit %q in %s", lit[invalid-offs], litname(prefix))
}
Expand Down Expand Up @@ -825,20 +826,21 @@ func (s *Scanner) tokSEMICOLON() token.Token {
// and thus relative to the file set.
func (s *Scanner) Scan() (pos token.Pos, tok token.Token, lit string) {
scanAgain:
insertSemi := false
if s.peekTok != 0 {
insertSemi = true
pos = s.file.Pos(s.offset - len(s.peekLit))
tok, lit = s.peekTok, s.peekLit
s.peekTok, s.peekLit = 0, ""
goto done
}

s.skipWhitespace()

// current token start
pos = s.file.Pos(s.offset)

// determine token value
insertSemi := false
if s.unitVal != "" { // number with unit
insertSemi = true
pos -= token.Pos(len(s.unitVal))
tok, lit = token.UNIT, s.unitVal
s.unitVal = ""
goto done
}
switch ch := s.ch; {
case isLetter(ch):
lit = s.scanIdentifier()
Expand Down Expand Up @@ -899,14 +901,18 @@ scanAgain:
tok = s.switch2(token.COLON, token.DEFINE)
case '.':
// fractions starting with a '.' are handled by outer switch
tok = token.PERIOD
if s.ch == '.' && s.peek() == '.' {
s.next()
s.next() // consume last '.'
if s.nParen == 0 {
insertSemi = true
}
tok = token.ELLIPSIS
} else {
tok = token.PERIOD
if ch := ('a' - 'A') | s.ch; 'a' <= ch && ch <= 'z' {
s.peekTok, s.peekLit = token.IDENT, s.scanIdentifier()
}
}
case ',':
tok = token.COMMA
Expand Down