提交 3d73f080 编写于 作者: chai2010's avatar chai2010

const 和 var 支持冒号分隔符

上级 d7286819
......@@ -18,8 +18,8 @@ import (
heart()
}
fn sum(n int) => int {
var v int
fn sum(n: int) => int {
var v: int
for i := 1; i <= n; i++ {
v += i
}
......
......@@ -2,10 +2,9 @@
fn main() {
println("凹凹,吃了吗")
println(answer())
println(add(40, 2))
}
fn answer() => (x:int) {
x = 40 + 2
return
fn add(a:i32, b:i32) => i32 {
return a + b
}
......@@ -2244,6 +2244,11 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, keyword token.Token, iota
pos := p.pos
idents := p.parseIdentList()
var colonPos token.Pos
if p.tok == token.COLON {
colonPos = p.pos
p.next()
}
typ := p.tryType()
var values []ast.Expr
// always permit optional initialization for more tolerant parsing
......@@ -2269,11 +2274,12 @@ func (p *parser) parseValueSpec(doc *ast.CommentGroup, keyword token.Token, iota
// the end of the innermost containing block.
// (Global identifiers are resolved in a separate phase after parsing.)
spec := &ast.ValueSpec{
Doc: doc,
Names: idents,
Type: typ,
Values: values,
Comment: p.lineComment,
Doc: doc,
Names: idents,
ColonPos: colonPos,
Type: typ,
Values: values,
Comment: p.lineComment,
}
kind := ast.Con
if keyword == token.VAR {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册