Paul Jolly
2014-08-26 22:06:01 UTC
Apologies if I am missing something obvious, but is there a way to
determine the token.Position of the 'else' keyword in a go/ast IfStmt?
Given the following:
package main
func main() {
if true {
} else {
}
}
The relevant part of the AST looks like this:
27 . . . . . 0: *ast.IfStmt {
28 . . . . . . If:
/tmp/67948a64-58db-625e-1cf6-ed449ec3e2cf.go:3:3
29 . . . . . . Cond: *ast.Ident {
30 . . . . . . . NamePos:
/tmp/67948a64-58db-625e-1cf6-ed449ec3e2cf.go:3:6
31 . . . . . . . Name: "true"
32 . . . . . . }
33 . . . . . . Body: *ast.BlockStmt {
34 . . . . . . . Lbrace:
/tmp/67948a64-58db-625e-1cf6-ed449ec3e2cf.go:3:11
35 . . . . . . . Rbrace:
/tmp/67948a64-58db-625e-1cf6-ed449ec3e2cf.go:4:3
36 . . . . . . }
37 . . . . . . Else: *ast.BlockStmt {
38 . . . . . . . Lbrace:
/tmp/67948a64-58db-625e-1cf6-ed449ec3e2cf.go:4:10
39 . . . . . . . Rbrace:
/tmp/67948a64-58db-625e-1cf6-ed449ec3e2cf.go:5:3
40 . . . . . . }
41 . . . . . }
Clearly the 'else' keyword is somewhere between the Rbrace of the IfStmt
Body and the Lbrace of the Else.
But is there a way to know exactly?
Thanks
determine the token.Position of the 'else' keyword in a go/ast IfStmt?
Given the following:
package main
func main() {
if true {
} else {
}
}
The relevant part of the AST looks like this:
27 . . . . . 0: *ast.IfStmt {
28 . . . . . . If:
/tmp/67948a64-58db-625e-1cf6-ed449ec3e2cf.go:3:3
29 . . . . . . Cond: *ast.Ident {
30 . . . . . . . NamePos:
/tmp/67948a64-58db-625e-1cf6-ed449ec3e2cf.go:3:6
31 . . . . . . . Name: "true"
32 . . . . . . }
33 . . . . . . Body: *ast.BlockStmt {
34 . . . . . . . Lbrace:
/tmp/67948a64-58db-625e-1cf6-ed449ec3e2cf.go:3:11
35 . . . . . . . Rbrace:
/tmp/67948a64-58db-625e-1cf6-ed449ec3e2cf.go:4:3
36 . . . . . . }
37 . . . . . . Else: *ast.BlockStmt {
38 . . . . . . . Lbrace:
/tmp/67948a64-58db-625e-1cf6-ed449ec3e2cf.go:4:10
39 . . . . . . . Rbrace:
/tmp/67948a64-58db-625e-1cf6-ed449ec3e2cf.go:5:3
40 . . . . . . }
41 . . . . . }
Clearly the 'else' keyword is somewhere between the Rbrace of the IfStmt
Body and the Lbrace of the Else.
But is there a way to know exactly?
Thanks
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.