Skip to content
This repository was archived by the owner on Oct 16, 2022. It is now read-only.
This repository was archived by the owner on Oct 16, 2022. It is now read-only.

Comments are not available in AST #19

@andygrunwald

Description

@andygrunwald

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?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions