mirror of
https://gitee.com/wa-lang/wa.git
synced 2025-12-06 09:18:53 +08:00
fmt 支持 global 关键字
This commit is contained in:
@@ -2143,7 +2143,7 @@ func output() {
|
||||
if !lflag {
|
||||
fmt.Fprintf(ftable, "\n//line yacctab:1")
|
||||
}
|
||||
fmt.Fprintf(ftable, "\nvar %sExca = [...]int{\n", prefix)
|
||||
fmt.Fprintf(ftable, "\nglobal %sExca = [...]int{\n", prefix)
|
||||
|
||||
if len(errors) > 0 {
|
||||
stateTable = make([]Row, nstate)
|
||||
|
||||
@@ -868,7 +868,7 @@ type (
|
||||
GenDecl struct {
|
||||
Doc *CommentGroup // associated documentation; or nil
|
||||
TokPos token.Pos // position of Tok
|
||||
Tok token.Token // IMPORT, CONST, TYPE, VAR
|
||||
Tok token.Token // IMPORT, CONST, TYPE, VAR, GLOBAL
|
||||
Lparen token.Pos // position of '(', if any
|
||||
Specs []Spec
|
||||
Rparen token.Pos // position of ')', if any
|
||||
|
||||
@@ -536,7 +536,7 @@ func NodeDescription(n ast.Node) string {
|
||||
return "constant declaration"
|
||||
case token.TYPE:
|
||||
return "type declaration"
|
||||
case token.VAR:
|
||||
case token.VAR, token.GLOBAL:
|
||||
return "variable declaration"
|
||||
}
|
||||
case *ast.Ident:
|
||||
|
||||
@@ -2394,7 +2394,7 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, keyword token.Token, iota
|
||||
p.expectSemi() // call before accessing p.linecomment
|
||||
|
||||
switch keyword {
|
||||
case token.VAR:
|
||||
case token.VAR, token.GLOBAL:
|
||||
if typ == nil && values == nil {
|
||||
p.error(pos, "missing variable type or initialization")
|
||||
}
|
||||
@@ -2417,7 +2417,7 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, keyword token.Token, iota
|
||||
Comment: p.lineComment,
|
||||
}
|
||||
kind := ast.Con
|
||||
if keyword == token.VAR {
|
||||
if keyword == token.VAR || keyword == token.GLOBAL {
|
||||
kind = ast.Var
|
||||
}
|
||||
p.declare(spec, iota, p.topScope, kind, idents...)
|
||||
@@ -2460,10 +2460,6 @@ func (p *parser) parseGenDecl(keyword token.Token, f parseSpecFunction) *ast.Gen
|
||||
doc := p.leadComment
|
||||
pos := p.expect(keyword)
|
||||
|
||||
if keyword == token.GLOBAL {
|
||||
keyword = token.VAR // TODO(chai2010): AST 支持 global
|
||||
}
|
||||
|
||||
var lparen, rparen token.Pos
|
||||
var list []ast.Spec
|
||||
if p.tok == token.LPAREN {
|
||||
|
||||
@@ -1523,7 +1523,7 @@ func (p *printer) genDecl(d *ast.GenDecl) {
|
||||
p.print(d.Lparen, token.LPAREN)
|
||||
if n := len(d.Specs); n > 0 {
|
||||
p.print(indent, formfeed)
|
||||
if n > 1 && (d.Tok == token.CONST || d.Tok == token.VAR) {
|
||||
if n > 1 && (d.Tok == token.CONST || d.Tok == token.VAR || d.Tok == token.GLOBAL) {
|
||||
// two or more grouped const/var declarations:
|
||||
// determine if the type column must be kept
|
||||
keepType := keepTypeColumn(d.Specs)
|
||||
|
||||
@@ -164,6 +164,7 @@ var tokens = [...]elt{
|
||||
{token.FOR, "for", keyword},
|
||||
|
||||
{token.FUNC, "func", keyword},
|
||||
{token.GLOBAL, "global", keyword},
|
||||
{token.IF, "if", keyword},
|
||||
{token.IMPORT, "import", keyword},
|
||||
|
||||
|
||||
@@ -1722,7 +1722,7 @@ start:
|
||||
|
||||
case *ast.DeclStmt: // Con, Var or Typ
|
||||
d := s.Decl.(*ast.GenDecl)
|
||||
if d.Tok == token.VAR {
|
||||
if d.Tok == token.VAR || d.Tok == token.GLOBAL {
|
||||
for _, spec := range d.Specs {
|
||||
if vs, ok := spec.(*ast.ValueSpec); ok {
|
||||
b.localValueSpec(fn, vs)
|
||||
|
||||
@@ -126,7 +126,7 @@ func membersFromDecl(pkg *Package, decl ast.Decl) {
|
||||
}
|
||||
}
|
||||
|
||||
case token.VAR:
|
||||
case token.VAR, token.GLOBAL:
|
||||
for _, spec := range decl.Specs {
|
||||
for _, id := range spec.(*ast.ValueSpec).Names {
|
||||
if !isBlankIdent(id) {
|
||||
|
||||
@@ -77,7 +77,7 @@ func findEnclosingPackageLevelFunction(pkg *Package, path []ast.Node) *Function
|
||||
if n := len(path); n >= 2 { // [... {Gen,Func}Decl File]
|
||||
switch decl := path[n-2].(type) {
|
||||
case *ast.GenDecl:
|
||||
if decl.Tok == token.VAR && n >= 3 {
|
||||
if (decl.Tok == token.VAR || decl.Tok == token.GLOBAL) && n >= 3 {
|
||||
// Package-level 'var' initializer.
|
||||
return pkg.init
|
||||
}
|
||||
|
||||
@@ -615,7 +615,7 @@ func (check *Checker) declStmt(decl ast.Decl) {
|
||||
check.declare(check.scope, name, lhs[i], scopePos)
|
||||
}
|
||||
|
||||
case token.VAR:
|
||||
case token.VAR, token.GLOBAL:
|
||||
top := len(check.delayed)
|
||||
|
||||
lhs0 := make([]*Var, len(s.Names))
|
||||
|
||||
@@ -124,7 +124,7 @@ func (check *Checker) blockBranches(all *Scope, parent *block, lstmt *ast.Labele
|
||||
stmtBranches = func(s ast.Stmt) {
|
||||
switch s := s.(type) {
|
||||
case *ast.DeclStmt:
|
||||
if d, _ := s.Decl.(*ast.GenDecl); d != nil && d.Tok == token.VAR {
|
||||
if d, _ := s.Decl.(*ast.GenDecl); d != nil && (d.Tok == token.VAR || d.Tok == token.GLOBAL) {
|
||||
recordVarDecl(d.Pos())
|
||||
}
|
||||
|
||||
|
||||
@@ -356,7 +356,7 @@ func (check *Checker) collectObjects() {
|
||||
|
||||
check.arityMatch(s, last)
|
||||
|
||||
case token.VAR:
|
||||
case token.VAR, token.GLOBAL:
|
||||
lhs := make([]*Var, len(s.Names))
|
||||
// If there's exactly one rhs initializer, use
|
||||
// the same declInfo d1 for all lhs variables
|
||||
|
||||
@@ -13,7 +13,7 @@ type exprSymType struct {
|
||||
|
||||
const NUM = 57346
|
||||
|
||||
var exprToknames = [...]string{
|
||||
global exprToknames = [...]string{
|
||||
"$end",
|
||||
"error",
|
||||
"$unk",
|
||||
@@ -26,7 +26,7 @@ var exprToknames = [...]string{
|
||||
"NUM",
|
||||
}
|
||||
|
||||
var exprStatenames = [...]string{}
|
||||
global exprStatenames = [...]string{}
|
||||
|
||||
const exprEofCode = 1
|
||||
const exprErrCode = 2
|
||||
@@ -79,7 +79,7 @@ func main {
|
||||
})
|
||||
}
|
||||
|
||||
var exprExca = [...]int{
|
||||
global exprExca = [...]int{
|
||||
-1, 1,
|
||||
1, -1,
|
||||
-2, 0,
|
||||
@@ -89,45 +89,45 @@ const exprPrivate = 57344
|
||||
|
||||
const exprLast = 23
|
||||
|
||||
var exprAct = [...]int{
|
||||
global exprAct = [...]int{
|
||||
7, 4, 5, 2, 21, 9, 6, 8, 12, 13,
|
||||
9, 1, 8, 16, 3, 19, 20, 17, 18, 14,
|
||||
15, 10, 11,
|
||||
}
|
||||
|
||||
var exprPact = [...]int{
|
||||
global exprPact = [...]int{
|
||||
-3, -1000, -1000, 17, -3, -3, 13, -1000, -1000, -3,
|
||||
2, 2, -1000, -1000, 2, 2, -5, 13, 13, -1000,
|
||||
-1000, -1000,
|
||||
}
|
||||
|
||||
var exprPgo = [...]int{
|
||||
global exprPgo = [...]int{
|
||||
0, 3, 14, 6, 0, 11,
|
||||
}
|
||||
|
||||
var exprR1 = [...]int{
|
||||
global exprR1 = [...]int{
|
||||
0, 5, 1, 1, 1, 2, 2, 2, 3, 3,
|
||||
3, 4, 4,
|
||||
}
|
||||
|
||||
var exprR2 = [...]int{
|
||||
global exprR2 = [...]int{
|
||||
0, 1, 1, 2, 2, 1, 3, 3, 1, 3,
|
||||
3, 1, 3,
|
||||
}
|
||||
|
||||
var exprChk = [...]int{
|
||||
global exprChk = [...]int{
|
||||
-1000, -5, -1, -2, 4, 5, -3, -4, 10, 8,
|
||||
4, 5, -1, -1, 6, 7, -1, -3, -3, -4,
|
||||
-4, 9,
|
||||
}
|
||||
|
||||
var exprDef = [...]int{
|
||||
global exprDef = [...]int{
|
||||
0, -2, 1, 2, 0, 0, 5, 8, 11, 0,
|
||||
0, 0, 3, 4, 0, 0, 0, 6, 7, 9,
|
||||
10, 12,
|
||||
}
|
||||
|
||||
var exprTok1 = [...]int{
|
||||
global exprTok1 = [...]int{
|
||||
1, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
||||
@@ -135,11 +135,11 @@ var exprTok1 = [...]int{
|
||||
8, 9, 6, 4, 3, 5, 3, 7,
|
||||
}
|
||||
|
||||
var exprTok2 = [...]int{
|
||||
global exprTok2 = [...]int{
|
||||
2, 3, 10,
|
||||
}
|
||||
|
||||
var exprTok3 = [...]int{
|
||||
global exprTok3 = [...]int{
|
||||
0,
|
||||
}
|
||||
|
||||
@@ -149,11 +149,11 @@ type exprErrorMessageInfo struct {
|
||||
msg :string
|
||||
}
|
||||
|
||||
var exprErrorMessages = [...]exprErrorMessageInfo{}
|
||||
global exprErrorMessages = [...]exprErrorMessageInfo{}
|
||||
|
||||
/* parser for yacc output */
|
||||
|
||||
var (
|
||||
global (
|
||||
exprDebug = 0
|
||||
exprErrorVerbose = false
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user