antlr / antlr/jetbrains-plugin-sample

Adding new custom keywords leads to errors

Open
#15 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
120
Forks
35
PR merge metrics
No merged PRs in 30d

Description

Hello,

Today I have been trying to use this plugin to create a new language for a JetBrains product.
I however can't extend the plugin with new keywords.

I keep getting errors such as:

![image](https://user-images.githubusercontent.com/2529002/147963003-7657d740-4159-4a74-afb9-9df47e61dd20.png)
![image](https://user-images.githubusercontent.com/2529002/147963304-f9dcba92-553d-4f8c-9d32-737861fa1ee5.png)

While the ANTLR preview works just fine:
![image](https://user-images.githubusercontent.com/2529002/147963329-35f7b3cf-8216-4eba-b992-d05e2124de24.png)

I have tried to add a block keywords (e.g. 'class') that works very similar to a func definition:

```g4
script
: vardef* define_class* function* statement* EOF
;

define_class
: 'class' ID block
;

// ...

CLASS : 'class' ;
```

---

And I have tried to copy the `print()` definition to `log()`, which also leads to errors in the IDE (but not in the preview):

![image](https://user-images.githubusercontent.com/2529002/147963747-91635c6d-217c-47d0-8e5e-2e733ee85ae2.png)
![image](https://user-images.githubusercontent.com/2529002/147963730-c7f5274f-27ba-4ec8-b390-cb9b5774fbd7.png)

```g4
| 'print' '(' expr? ')' # Print
| 'log' '(' expr? ')' # Log

// ...

PRINT : 'print' ;
LOG : 'log' ;
```

---

When replacing print with log, it does work:

![image](https://user-images.githubusercontent.com/2529002/147964012-bc45b4d2-e0ac-4722-9bba-39878c5b953d.png)

---

I have tried editing and copying Java files/classes and cases/rules to match my new keywords, but this did not help at all.
What am I missing/supposed to be doing in order to create new keywords?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the errors in the JetBrains IDE with the shown grammar changes and compare them with the working ANTLR preview. Then inspect the Java files/classes and cases/rules involved in the sample plugin; the issue is done when distinct keywords such as class and log work in the IDE without errors, as they do in the preview.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.