Commit a0c709be authored by Robert Griesemer's avatar Robert Griesemer

- use new letter definition for pretty

- fixed a bug with error column reporting in the presence of utf-8 chars
- fixed an assertion failure

R=r
OCL=22762
CL=22762
parent 5ea8ac78
...@@ -4,13 +4,16 @@ ...@@ -4,13 +4,16 @@
package Compilation package Compilation
import "array" import (
import OS "os" "array";
import Platform "platform" "utf8";
import Scanner "scanner" OS "os";
import Parser "parser" Platform "platform";
import AST "ast" Scanner "scanner";
import TypeChecker "typechecker" Parser "parser";
AST "ast";
TypeChecker "typechecker";
)
func assert(b bool) { func assert(b bool) {
...@@ -67,7 +70,7 @@ func (h *ErrorHandler) LineCol(pos int) (line, col int) { ...@@ -67,7 +70,7 @@ func (h *ErrorHandler) LineCol(pos int) (line, col int) {
} }
} }
return line, pos - lpos; return line, utf8.RuneCountInString(src, lpos, pos - lpos);
} }
......
...@@ -167,15 +167,17 @@ func (P *Parser) DeclareInScope(scope *AST.Scope, x *AST.Expr, kind int) { ...@@ -167,15 +167,17 @@ func (P *Parser) DeclareInScope(scope *AST.Scope, x *AST.Expr, kind int) {
if P.scope_lev < 0 { if P.scope_lev < 0 {
panic("cannot declare objects in other packages"); panic("cannot declare objects in other packages");
} }
obj := x.obj; if x.tok != Scanner.ILLEGAL { // ignore bad exprs
assert(x.tok == Scanner.IDENT && obj.kind == AST.NONE); obj := x.obj;
obj.kind = kind; assert(x.tok == Scanner.IDENT && obj.kind == AST.NONE);
obj.pnolev = P.scope_lev; obj.kind = kind;
if scope.LookupLocal(obj.ident) != nil { obj.pnolev = P.scope_lev;
P.Error(obj.pos, `"` + obj.ident + `" is declared already`); if scope.LookupLocal(obj.ident) != nil {
return; // don't insert it into the scope P.Error(obj.pos, `"` + obj.ident + `" is declared already`);
} return; // don't insert it into the scope
scope.Insert(obj); }
scope.Insert(obj);
}
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package Scanner package Scanner
import "utf8" import "utf8"
import "unicode"
import Utils "utils" import Utils "utils"
...@@ -254,7 +255,9 @@ func init() { ...@@ -254,7 +255,9 @@ func init() {
func is_letter(ch int) bool { func is_letter(ch int) bool {
return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch >= 128 ; return
'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || // common case
ch == '_' || unicode.IsLetter(ch);
} }
......
...@@ -52,6 +52,12 @@ var ( ...@@ -52,6 +52,12 @@ var (
) )
var (
// Unicode identifiers
ä, ö, ü, Á, Ø, Å, ƒ, ß int;
)
func d0() { func d0() {
var ( var (
a string; a string;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment