Comments are not available in AST
I got a test php file:
<?php
/* Foo */
// Bar
$baz = "hey";
and a small go tool to parse this:
package main
import (
"fmt"
"github.com/stephens2424/php"
"github.com/stephens2424/php/passes/printing"
"io/ioutil"
"log"
)
func main() {
content, err := ioutil.ReadFile("./test.php")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(content))
p := php.NewParser()
a, err := p.Parse("test.php", string(content))
if err != nil {
log.Fatal(err)
}
w := printing.NewWalker()
for _, node := range a.Nodes {
w.Walk(node)
}
}
The output looks like:
go run main.go
<?php
/* Foo */
// Bar
$baz = "hey";
(ast.ExpressionStmt)=
(ast.AssignmentExpression)=
(*ast.Variable)$baz
(*ast.Identifier)baz
(*ast.Literal)Literal-string: "hey"
As you see the single line + multi line comments are nor parsed in the AST. Do i something wrong or are they not reflected as node?
The comments aren't in the AST at the moment, but I have some pending work that should address this.
The changes I pushed just now make the comments available in the lexed token stream, but there's still no association with AST nodes.
Thank you. I think you mean https://github.com/stephens2424/php/commit/29a80da86744883c0d48919adbe7ca6acd1317f0 ?
Is your pending work this commit? If not it would be nice to push the branch :) Thanks for your project!
Yep, that's the one. It's really a work in progress, though, since it's pretty difficult to use in a meaningful way. I'd like to get phpdoc comments into the ast, but I'm still pondering the approach.
Thank you :)