add documentation on scanner and parser.
This commit is contained in:
parent
75e9e171f8
commit
264f15fd00
2 changed files with 24 additions and 6 deletions
|
@ -1,3 +1,13 @@
|
||||||
|
/*
|
||||||
|
Parser parses the Tengo source files.
|
||||||
|
|
||||||
|
Parser is a modified version of Go's parser implementation.
|
||||||
|
|
||||||
|
Copyright 2009 The Go Authors. All rights reserved.
|
||||||
|
Use of this source code is governed by a BSD-style
|
||||||
|
license that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
package parser
|
package parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -135,7 +145,7 @@ L:
|
||||||
x = p.parseSelector(x)
|
x = p.parseSelector(x)
|
||||||
default:
|
default:
|
||||||
pos := p.pos
|
pos := p.pos
|
||||||
p.errorExpected(pos, "selector string")
|
p.errorExpected(pos, "selector")
|
||||||
p.advance(stmtStart)
|
p.advance(stmtStart)
|
||||||
return &ast.BadExpr{From: pos, To: p.pos}
|
return &ast.BadExpr{From: pos, To: p.pos}
|
||||||
}
|
}
|
||||||
|
@ -647,7 +657,7 @@ func (p *Parser) parseIfStmt() ast.Stmt {
|
||||||
elseStmt = p.parseBlockStmt()
|
elseStmt = p.parseBlockStmt()
|
||||||
p.expectSemi()
|
p.expectSemi()
|
||||||
default:
|
default:
|
||||||
p.errorExpected(p.pos, "if statement or block")
|
p.errorExpected(p.pos, "if or {")
|
||||||
elseStmt = &ast.BadStmt{From: p.pos, To: p.pos}
|
elseStmt = &ast.BadStmt{From: p.pos, To: p.pos}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,3 +1,13 @@
|
||||||
|
/*
|
||||||
|
Scanner reads the Tengo source text and tokenize them.
|
||||||
|
|
||||||
|
Scanner is a modified version of Go's scanner implementation.
|
||||||
|
|
||||||
|
Copyright 2009 The Go Authors. All rights reserved.
|
||||||
|
Use of this source code is governed by a BSD-style
|
||||||
|
license that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
package scanner
|
package scanner
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -295,10 +305,8 @@ exit:
|
||||||
lit := s.src[offs:s.offset]
|
lit := s.src[offs:s.offset]
|
||||||
|
|
||||||
// On Windows, a (//-comment) line may end in "\r\n".
|
// On Windows, a (//-comment) line may end in "\r\n".
|
||||||
// Remove the final '\r' before analyzing the text for
|
// Remove the final '\r' before analyzing the text for line directives (matching the compiler).
|
||||||
// line directives (matching the compiler). Remove any
|
// Remove any other '\r' afterwards (matching the pre-existing behavior of the scanner).
|
||||||
// other '\r' afterwards (matching the pre-existing be-
|
|
||||||
// havior of the scanner).
|
|
||||||
if numCR > 0 && len(lit) >= 2 && lit[1] == '/' && lit[len(lit)-1] == '\r' {
|
if numCR > 0 && len(lit) >= 2 && lit[1] == '/' && lit[len(lit)-1] == '\r' {
|
||||||
lit = lit[:len(lit)-1]
|
lit = lit[:len(lit)-1]
|
||||||
numCR--
|
numCR--
|
||||||
|
|
Loading…
Reference in a new issue