From 264f15fd004a797e28df70def8475fddd2caa5a8 Mon Sep 17 00:00:00 2001 From: Daniel Kang Date: Mon, 14 Jan 2019 06:57:30 -0800 Subject: [PATCH] add documentation on scanner and parser. --- compiler/parser/parser.go | 14 ++++++++++++-- compiler/scanner/scanner.go | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/compiler/parser/parser.go b/compiler/parser/parser.go index 2bc77e5..528fa2a 100644 --- a/compiler/parser/parser.go +++ b/compiler/parser/parser.go @@ -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 import ( @@ -135,7 +145,7 @@ L: x = p.parseSelector(x) default: pos := p.pos - p.errorExpected(pos, "selector string") + p.errorExpected(pos, "selector") p.advance(stmtStart) return &ast.BadExpr{From: pos, To: p.pos} } @@ -647,7 +657,7 @@ func (p *Parser) parseIfStmt() ast.Stmt { elseStmt = p.parseBlockStmt() p.expectSemi() default: - p.errorExpected(p.pos, "if statement or block") + p.errorExpected(p.pos, "if or {") elseStmt = &ast.BadStmt{From: p.pos, To: p.pos} } } else { diff --git a/compiler/scanner/scanner.go b/compiler/scanner/scanner.go index 5ed9faa..b5deb5c 100644 --- a/compiler/scanner/scanner.go +++ b/compiler/scanner/scanner.go @@ -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 import ( @@ -295,10 +305,8 @@ exit: lit := s.src[offs:s.offset] // On Windows, a (//-comment) line may end in "\r\n". - // Remove the final '\r' before analyzing the text for - // line directives (matching the compiler). Remove any - // other '\r' afterwards (matching the pre-existing be- - // havior of the scanner). + // Remove the final '\r' before analyzing the text for line directives (matching the compiler). + // Remove any other '\r' afterwards (matching the pre-existing behavior of the scanner). if numCR > 0 && len(lit) >= 2 && lit[1] == '/' && lit[len(lit)-1] == '\r' { lit = lit[:len(lit)-1] numCR--