Skip to content

Commit

Permalink
Fix antlr#3508: Document the $parser attribute and its use in target-…
Browse files Browse the repository at this point in the history
…agnostic grammars.
  • Loading branch information
RossPatterson committed Aug 1, 2022
2 parents ed74aee + 26d989f commit 2941f7a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions doc/python-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,28 @@ Unfortunately, this is not portable, as Java and Python (and other target langua

Thanks to the above, you should be able to rewrite the above semantic predicate as follows:

File MyParser.g4:
File `MyGrammarParser.g4`:
```
options { superClass = BaseParser; }
options { superClass = MyGrammarBaseParser; }
...
ID {$parser.isEqualText($text,"test")}?
```

File BaseParser.py:
File `MyGrammarBaseParser.py`:
```python
from antlr4 import *

class BaseParser(Parser):
class MyGrammarBaseParser(Parser):

def isEqualText(a, b):
return a is b
```

File BaseParser.java
File `MyGrammarBaseParser.java`:
```java
import org.antlr.v4.runtime.*;

public abstract class BaseParser extends Parser {
public abstract class MyGrammarBaseParser extends Parser {

public static boolean isEqualText(a, b) {
return a.equals(b);
Expand Down

0 comments on commit 2941f7a

Please sign in to comment.