antlr / antlr-php-runtime

PHP Runtime for ANTLR4
BSD 3-Clause "New" or "Revised" License
82 stars 19 forks source link

error(31): ANTLR cannot generate PHP code as of version 4.7.1 #5

Closed huanghantao closed 4 years ago

huanghantao commented 4 years ago

I have installed antlr4 according to the inside of the https://github.com/antlr/antlr4/blob/master/doc/getting-started.md document.

And my antlr version:

antlr: stable 4.7.2
ANother Tool for Language Recognition
https://www.antlr.org/
/usr/local/Cellar/antlr/4.7.2 (5 files, 2.0MB) *
  Built from source on 2020-08-26 at 12:44:21
From: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git/Formula/antlr.rb
==> Requirements
Required: java ✔
==> Analytics
install: 226 (30 days), 700 (90 days), 5,719 (365 days)
install-on-request: 216 (30 days), 671 (90 days), 5,437 (365 days)
build-error: 0 (30 days)

os: macOS 10.15.2

huanghantao commented 4 years ago

The documentation only says to install antlr-php-runtime, but it doesn't say how do we get antlr4 to use antlr-php-runtime? I don't know -Dlanguage=PHP how does it find antlr-php-runtime?

marcospassos commented 4 years ago

Hi @huanghantao!

When generating the parser/lexer, you need to specify what the target language passing -Dlanguage=PHP. The ANTLR tool will then generate the code in the target language you've specified.

To be able to parse files using your just generated parser, you will need the antlr-php-runtime. The recommended installation method is through the package manager Composer, as described in the docs. Just write a new composer file, add this library as a dependency, and you should be ready to try your new parser.