Skip to content

Basic syntax coloring support for jflex grammar files#8997

Merged
matthiasblaesing merged 1 commit intoapache:masterfrom
haidubogdan:t_jflex
Nov 24, 2025
Merged

Basic syntax coloring support for jflex grammar files#8997
matthiasblaesing merged 1 commit intoapache:masterfrom
haidubogdan:t_jflex

Conversation

@haidubogdan
Copy link
Contributor

@haidubogdan haidubogdan commented Nov 9, 2025

Adding basic coloring support for jflex files using antlr grammar.
Today the lexer and parser for PHP module are implemented using jflex gramar.
I'm thinking this update can help maintain those modules, so I see it more as an internal tool
In the future this can be followed by cup syntax coloring.

image

@matthiasblaesing
Copy link
Contributor

matthiasblaesing commented Nov 13, 2025

Would you mind reiterating the colors? They differ a lot from the default NetBeans style. I think it would be good to have a look at the HTML/JS/CSS combination. For that case JS + CSS are highlighted mostly using default colors and less extreme where custom definitions are required, the embedding is highlighted using a background-color:

grafik

@haidubogdan haidubogdan force-pushed the t_jflex branch 2 times, most recently from a36cb37 to 95499ac Compare November 14, 2025 21:40
@haidubogdan
Copy link
Contributor Author

Would you mind reiterating the colors? They differ a lot from the default NetBeans style. I think it would be good to have a look at the HTML/JS/CSS combination. For that case JS + CSS are highlighted mostly using default colors and less extreme where custom definitions are required, the embedding is highlighted using a background-color:
grafik

It seems that the embedding coloring is too good for the java code.
The background color is not kept.

I've tried to use colors used in existing languages.
With the blue theme, I'm not sure if for the regex expression I should use the approach of antlr, to use string color for chars and different color for the brackets and operators ?

image image

@matthiasblaesing
Copy link
Contributor

For the background color problem please have a look here:

matthiasblaesing@6f42780

That commit transfers the idea from HTML to jflex.

@haidubogdan
Copy link
Contributor Author

For the background color problem please have a look here:

matthiasblaesing@6f42780

That commit transfers the idea from HTML to jflex.

I've also tested with Semantic Analyzer using a custom attribute set. And the highlight refresh seems more "fluent".

image

Do you think it would be enough ? : a8e7b40

@haidubogdan haidubogdan force-pushed the t_jflex branch 3 times, most recently from 2be7f6f to 23fad2e Compare November 17, 2025 06:01
@mbien
Copy link
Member

mbien commented Nov 17, 2025

is the java cluster the right place for this module? The new module would have to be hooked into CI too (main.yaml).

@haidubogdan
Copy link
Contributor Author

haidubogdan commented Nov 18, 2025

is the java cluster the right place for this module? The new module would have to be hooked into CI too (main.yaml).

I think it can be considered suitable under java, as it compiles code to java, and antlr is in the same namespace.
But if there are other suggestion, why not. Maybe contrib or ide folder ?
I'm thinking to apply the same module location for a possible cup file support.

I will include the module into main.yaml.

@matthiasblaesing
Copy link
Contributor

I've also tested with Semantic Analyzer using a custom attribute set. And the highlight refresh seems more "fluent".

Do you think it would be enough ? : a8e7b40

That is a good idea. Thank you!

@matthiasblaesing matthiasblaesing added Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) ANTLR labels Nov 20, 2025
Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sane to me in general. I left two inline nitpicks.

I would suggest to update and squash in that process.

@Chris2011
Copy link
Contributor

Chris2011 commented Nov 20, 2025

Great work, really. I would suggest to see this module in the ide cluster. Only due to java generated code doesn't mean it belongs to it. We have go, hcl, toml and yaml inside the ide cluster with language as a prefix too. I already talked to @lkishalmi and he would be also fine to more antlr to another place. It is just for a new language.

@haidubogdan
Copy link
Contributor Author

Great work, really. I would suggest to see this module in the ide cluster. Only due to java generated code doesn't mean it belongs to it. We have go, hcl, toml and yaml inside the ide cluster with language as a prefix too. I already talked to @lkishalmi and he would be also fine to more antlr to another place. It is just for a new language.

Ok, if there is this direction, I can move it into ide folder.
I also have a work in progress .env file support, so I think it can be located into ide folder too.

@haidubogdan haidubogdan force-pushed the t_jflex branch 6 times, most recently from 4e4df37 to 58d34cd Compare November 23, 2025 11:58
@haidubogdan
Copy link
Contributor Author

I need to remove the java dependency library.

Problems found with autoloads Problems found for module org.netbeans.modules.languages.jflex: [The module named org.netbeans.modules.java.lexer/1 was needed and not found.]

@matthiasblaesing
Copy link
Contributor

@Chris2011 @mbien anything more you want to request? Else I think this should go in.

@mbien mbien added this to the NB29 milestone Nov 23, 2025
Copy link
Member

@mbien mbien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no requests from my side. ide cluster sounds good to me.

Copy link
Contributor

@Chris2011 Chris2011 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left one comment, beside of this, I don't have anything left

* Added Jflex Lexer using ANTRL implementation

* Updated Fonts and Coloring configuration

* Fixed license issues

* Added module under github workflows test

* Moved module under `ide` folder

* Removed java.lexer dependency

* Update position level to 197 for jflex mime
@matthiasblaesing matthiasblaesing merged commit 8270397 into apache:master Nov 24, 2025
35 checks passed
@matthiasblaesing
Copy link
Contributor

@haidubogdan thanks for implementation. @mbien @Chris2011 thanks for review!

@lkishalmi
Copy link
Contributor

Thank you!

@haidubogdan
Copy link
Contributor Author

With pleasure, thank you also for your suggestions.
I hope I will have time to add more features to the jflex module.

@mbien
Copy link
Member

mbien commented Nov 29, 2025

@haidubogdan no hurry, but could you take a look at this ordering warning?

WARNING [org.openide.filesystems.Ordering]: Not all children in Templates/ marked with the position attribute: [Grammar], but some are: [JFX@0, JWS@0, Licenses@0, NetBeansModuleDevelopment-files@0, Privileged@0, Project@0, Recent@0, Services@0, Scripting@20, NetBeansModuleDevelopment@200, JSP_Servlet@600, JSF@700, Bean_Validation@701, OSGi@723, SpringFramework@825, J2EE@860, CDI@876, Classes@900, javafx@909, J2SEModule@999, GUIForms@1000, Beans@1052, AWTForms@1100, UnitTests@1200, SeleniumTests@1210, Html5Tests@1211, cpplite@1250, Micronaut@1280, Persistence@1300, Groovy@1350, WebServices@1500, ClientSide@1610, XML@1700, PayaraResources@1750, SunResources@1800, WebLogicResources@1850, Other@2100, Properties@2900, SaaSServices@3000]

Grammar is currently the first item on the new file dialog which is probably a bit high given that it is a less common file type.
image

Since it is about the folder, you probably will have to add it to the layer like:

<folder name="Templates">
<folder name="NetBeansModuleDevelopment">
<attr name="displayName" bundlevalue="org.netbeans.modules.apisupport.project.ui.wizard.common.Bundle#NetBeansModuleDevelopment"/>
<attr name="position" intvalue="200"/>
</folder>

(not sure if it is possible to set it via annotation)

I fixed most of those warnings recently via #8916 - the log line will now also show the positions behind the @ to make it easier to pick a value. We should keep an eye on layer positions since those are easy to forget while adding new features.

@haidubogdan
Copy link
Contributor Author

@mbien .
Yes, it should have a lower priority. I will prepare a commit at the start of the next werk.

haidubogdan added a commit to haidubogdan/netbeans that referenced this pull request Dec 2, 2025
Continuation of the jflex syntax coloring support #apache#8997 pull request

Set Grammar folder position to 1800 after XML as it has lower priority usage.
@haidubogdan haidubogdan deleted the t_jflex branch December 9, 2025 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ANTLR Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants