]> Cypherpunks repositories - gostls13.git/commitdiff
- use new letter definition for pretty
authorRobert Griesemer <gri@golang.org>
Wed, 14 Jan 2009 23:19:34 +0000 (15:19 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 14 Jan 2009 23:19:34 +0000 (15:19 -0800)
- fixed a bug with error column reporting in the presence of utf-8 chars
- fixed an assertion failure

R=r
OCL=22762
CL=22762

usr/gri/pretty/compilation.go
usr/gri/pretty/parser.go
usr/gri/pretty/scanner.go
usr/gri/pretty/selftest2.go

index 491b41c33ce33a902410710bb87739a6c5266e2f..06172dc66dd247d527dd5befcbf30eb1f3265da7 100644 (file)
@@ -4,13 +4,16 @@
 
 package Compilation
 
-import "array"
-import OS "os"
-import Platform "platform"
-import Scanner "scanner"
-import Parser "parser"
-import AST "ast"
-import TypeChecker "typechecker"
+import (
+       "array";
+       "utf8";
+       OS "os";
+       Platform "platform";
+       Scanner "scanner";
+       Parser "parser";
+       AST "ast";
+       TypeChecker "typechecker";
+)
 
 
 func assert(b bool) {
@@ -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);
 }
 
 
index eaadf105a330bf39e858a59fef2fef28bbe0806d..4ae58504c02ec63ad7c87e6bc807e4217312d91a 100644 (file)
@@ -167,15 +167,17 @@ func (P *Parser) DeclareInScope(scope *AST.Scope, x *AST.Expr, kind int) {
        if P.scope_lev < 0 {
                panic("cannot declare objects in other packages");
        }
-       obj := x.obj;
-       assert(x.tok == Scanner.IDENT && obj.kind == AST.NONE);
-       obj.kind = kind;
-       obj.pnolev = P.scope_lev;
-       if scope.LookupLocal(obj.ident) != nil {
-               P.Error(obj.pos, `"` + obj.ident + `" is declared already`);
-               return;  // don't insert it into the scope
-       }
-       scope.Insert(obj);
+       if x.tok != Scanner.ILLEGAL {  // ignore bad exprs
+               obj := x.obj;
+               assert(x.tok == Scanner.IDENT && obj.kind == AST.NONE);
+               obj.kind = kind;
+               obj.pnolev = P.scope_lev;
+               if scope.LookupLocal(obj.ident) != nil {
+                       P.Error(obj.pos, `"` + obj.ident + `" is declared already`);
+                       return;  // don't insert it into the scope
+               }
+               scope.Insert(obj);
+       }
 }
 
 
index 9b56e329b1dc1cb066fe6c77cd8c75e6869efd1b..681bbec45938cc2cf4493c75b8cb23fd433d65d2 100644 (file)
@@ -5,6 +5,7 @@
 package Scanner
 
 import "utf8"
+import "unicode"
 import Utils "utils"
 
 
@@ -254,7 +255,9 @@ func init() {
 
 
 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);
 }
 
 
index 9f488f2dbd8ccd55b9e574859c001daeb25fa63b..f41fbc74391016c318902d22200a2491abaedd0e 100644 (file)
@@ -52,6 +52,12 @@ var (
 )
 
 
+var (
+       // Unicode identifiers
+       ä, ö, ü, Á, Ø, Å, ƒ, ß int;
+)
+
+
 func d0() {
        var (
                a string;