Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Antlr4 import grammar from path

Tags:

antlr

antlr4

Simple questions which I so far think the answer is no:

Is it possible to import grammars from a child directory? e.g.:

grammar literals;

import myFolder/IntegerLiterals;

with the following structure:

/ 
 literals.g4
 myFolder/
    IntegerLiterals.g4
like image 549
Diolor Avatar asked Oct 27 '25 16:10

Diolor


1 Answers

I had the same problem and found this site but got no solution. After some more googling I found a solution for this problem:

Actually there is now a way how to import grammars from other directories:

Use the -lib option when running antlr to define where your gramars are that you want to import. Here is the docu for the options: https://github.com/antlr/antlr4/blob/master/doc/tool-options.md

So you write your grammar:

grammar literals;
import IntegerLiterals;

Then you run in command line:

antlr4 -lib C:/.../myFolder literals.g4
like image 158
Sabed Avatar answered Oct 29 '25 18:10

Sabed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!