It seems that the function definition cannot be recognized when parsing PHP. #4729
-
My code: import com.bonbonwork.code.core.antlr.PhpLexer
import com.bonbonwork.code.core.antlr.PhpParser
import com.bonbonwork.code.core.antlr.PhpParserBaseListener
import org.antlr.v4.runtime.CharStreams
import org.antlr.v4.runtime.CommonTokenStream
fun main() {
val lexer = PhpLexer(CharStreams.fromString("""
<?php
echo "hello world";
class A {
public function _invoke() {
}
}
""".trimIndent()))
val tokens = CommonTokenStream(lexer)
val parser = PhpParser(tokens)
parser.addParseListener(TestVisitor())
println(parser.phpBlock().toStringTree(parser))
}
class TestVisitor : PhpParserBaseListener() {
override fun enterFunctionDeclaration(ctx: PhpParser.FunctionDeclarationContext) {
println('a')
}
} After executing the code, The final output of the code is:
My g4 is: https://github.com/antlr/grammars-v4/tree/master/php |
Beta Was this translation helpful? Give feedback.
Answered by
kaby76
Nov 17, 2024
Replies: 1 comment 1 reply
-
The input to the parser defines a class with a method, not a function. Try:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
EmptyDreams
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The input to the parser defines a class with a method, not a function. Try: