Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Highlight keywords with dashes
Highlight keywords with dashes [message #1841931] Thu, 03 June 2021 18:42 Go to next message
Nico-Pascal Huch is currently offline Nico-Pascal HuchFriend
Messages: 6
Registered: June 2021
Junior Member
Hello,

I'm currently trying to get some keywords highlighted in a CodeMirror text editor in my language via the mode.js file and I noticed it doesn't unclude my keywords if they contain a dash. For example "foobar" is included in the keyword variable of my mode.js file, as well as "foo_bar", but "foo-bar" is not. How can I make it work that these are included in the file when building my project?

Re: Highlight keywords with dashes [message #1841934 is a reply to message #1841931] Thu, 03 June 2021 19:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Guess you need to customize this one in your workflow
https://github.com/eclipse/xtext-core/blob/master/org.eclipse.xtext.xtext.generator/src/org/eclipse/xtext/xtext/generator/web/WebIntegrationFragment.xtend


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Highlight keywords with dashes [message #1841937 is a reply to message #1841934] Thu, 03 June 2021 20:00 Go to previous messageGo to next message
Nico-Pascal Huch is currently offline Nico-Pascal HuchFriend
Messages: 6
Registered: June 2021
Junior Member
Thank you. That helped including the keywords in my mode.js file by setting the keywordsFilter to "[a-zA-Z0-9_-]+".

Now it's just a problem that order inside the regex of the mode.js files needs to be reversed. As it currently orders them ascending "foobar|foobar-baz" it means that the foobar part gets highlighted but the baz part is not.
I suppose this means I have to override the generateJsHighlighting method in the WebIntegrationFragment class? Or is there an easier way?

Re: Highlight keywords with dashes [message #1841952 is a reply to message #1841937] Fri, 04 June 2021 06:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
no i dont see any. i also wonder if this is a general problem/bug that is worth fixing

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Highlight keywords with dashes [message #1841983 is a reply to message #1841952] Sat, 05 June 2021 20:22 Go to previous messageGo to next message
Nico-Pascal Huch is currently offline Nico-Pascal HuchFriend
Messages: 6
Registered: June 2021
Junior Member
It seems like an edgecase, but one that could be easily fixed. As of now it's not possible to generate a mode.js file for the CodeMirror editor that highlights all keywords correctly when theres the same keyword without the dash already.

foobar
foobar-baz

baz is not highlighted, presumingly as the regex already finished on finding "foobar", so a reverse ordering would help in my opinion.

Also, as of now the list of keywords is applied as it is, even though the dash would need to be escaped if my understanding of regex is correct?
It generated a second regex for the dash alone but even here the dash would need to be escaped I think, and I'm not quite sure I understand what the second regex is doing, but it doesn't help with the highlighting.

var keywords = "foobar|foobar-baz";
var extraKeywords = "-";
{token: "keyword", regex: "\\b(?:" + keywords + ")\\b"},
{token: "keyword", regex: "(?:^|\\s)(?:" + extraKeywords + ")(?=[\\s.:;,!?+\\-*/&|<>()[\\]{}]|$)"}


As of now I see no other way but to edit the file by hand so it will work. Is there anyone I can contact so this might get looked at?
Re: Highlight keywords with dashes [message #1841987 is a reply to message #1841983] Sun, 06 June 2021 05:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
I don't understand why subclassing the fragment should not work

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Highlight keywords with dashes [message #1842658 is a reply to message #1841931] Sun, 27 June 2021 16:19 Go to previous messageGo to next message
Nico-Pascal Huch is currently offline Nico-Pascal HuchFriend
Messages: 6
Registered: June 2021
Junior Member
Hello again, thanks for your help so far. Currently I am trying to subclassing the WebIntegrationFragment-class. I created a new class called "CustomWebIntegrationFragment" and tried to add it to my mwe2-Configuration file by adding the import and classname to the file:

webSupport = CustomWebIntegrationFragment {
	[...]
	codeMirrorVersion = "5.52.2"
	framework = "CodeMirror"
	generateJsHighlighting = true
	keywordsFilter = "[a-zA-Z0-9_-]+"
}


The class currently contains no logic as I wanted to test if it builds first:
import org.eclipse.xtext.xtext.generator.web.WebIntegrationFragment

class CustomWebIntegrationFragment extends WebIntegrationFragment {
	
}


But when I try to built the language I also get an error that he cannot find my subclassed WebIntegrationFragment .

[ERROR] [XtextLinkingDiagnostic: null:76 Couldn't resolve reference to JvmType 'CustomWebIntegrationFragment'., XtextLinkingDiagnostic: null:77 Couldn't resolve reference to JvmIdentifiableElement 'generateHtmlExample'., XtextLinkingDiagnostic: null:78 Couldn't resolve reference to JvmIdentifiableElement 'codeMirrorVersion'., XtextLinkingDiagnostic: null:79 Couldn't resolve reference to JvmIdentifiableElement 'requireJsVersion'., XtextLinkingDiagnostic: null:80 Couldn't resolve reference to JvmIdentifiableElement 'requireJsTextVersion'., XtextLinkingDiagnostic: null:81 Couldn't resolve reference to JvmIdentifiableElement 'jQueryVersion'., XtextLinkingDiagnostic: null:82 Couldn't resolve reference to JvmIdentifiableElement 'framework'., XtextLinkingDiagnostic: null:83 Couldn't resolve reference to JvmIdentifiableElement 'generateJettyLauncher'., XtextLinkingDiagnostic: null:84 Couldn't resolve reference to JvmIdentifiableElement 'generateJsHighlighting'., XtextLinkingDiagnostic: null:85 Couldn't resolve reference to JvmIdentifiableElement 'generateServlet'., XtextLinkingDiagnostic: null:86 Couldn't resolve reference to JvmIdentifiableElement 'generateWebXml'., XtextLinkingDiagnostic: null:87 Couldn't resolve reference to JvmIdentifiableElement 'highlightingModuleName'., XtextLinkingDiagnostic: null:88 Couldn't resolve reference to JvmIdentifiableElement 'keywordsFilter'., XtextLinkingDiagnostic: null:90 Couldn't resolve reference to JvmIdentifiableElement 'suppressPattern'., XtextLinkingDiagnostic: null:91 Couldn't resolve reference to JvmIdentifiableElement 'suppressPattern'., XtextLinkingDiagnostic: null:92 Couldn't resolve reference to JvmIdentifiableElement 'suppressPattern'., XtextLinkingDiagnostic: null:93 Couldn't resolve reference to JvmIdentifiableElement 'suppressPattern'., XtextLinkingDiagnostic: null:94 Couldn't resolve reference to JvmIdentifiableElement 'suppressPattern'., XtextLinkingDiagnostic: null:95 Couldn't resolve reference to JvmIdentifiableElement 'suppressPattern'.]
java.lang.IllegalStateException: [XtextLinkingDiagnostic: null:76 Couldn't resolve reference to JvmType 'CustomWebIntegrationFragment'., XtextLinkingDiagnostic: null:77 Couldn't resolve reference to JvmIdentifiableElement 'generateHtmlExample'., XtextLinkingDiagnostic: null:78 Couldn't resolve reference to JvmIdentifiableElement 'codeMirrorVersion'., XtextLinkingDiagnostic: null:79 Couldn't resolve reference to JvmIdentifiableElement 'requireJsVersion'., XtextLinkingDiagnostic: null:80 Couldn't resolve reference to JvmIdentifiableElement 'requireJsTextVersion'., XtextLinkingDiagnostic: null:81 Couldn't resolve reference to JvmIdentifiableElement 'jQueryVersion'., XtextLinkingDiagnostic: null:82 Couldn't resolve reference to JvmIdentifiableElement 'framework'., XtextLinkingDiagnostic: null:83 Couldn't resolve reference to JvmIdentifiableElement 'generateJettyLauncher'., XtextLinkingDiagnostic: null:84 Couldn't resolve reference to JvmIdentifiableElement 'generateJsHighlighting'., XtextLinkingDiagnostic: null:85 Couldn't resolve reference to JvmIdentifiableElement 'generateServlet'., XtextLinkingDiagnostic: null:86 Couldn't resolve reference to JvmIdentifiableElement 'generateWebXml'., XtextLinkingDiagnostic: null:87 Couldn't resolve reference to JvmIdentifiableElement 'highlightingModuleName'., XtextLinkingDiagnostic: null:88 Couldn't resolve reference to JvmIdentifiableElement 'keywordsFilter'., XtextLinkingDiagnostic: null:90 Couldn't resolve reference to JvmIdentifiableElement 'suppressPattern'., XtextLinkingDiagnostic: null:91 Couldn't resolve reference to JvmIdentifiableElement 'suppressPattern'., XtextLinkingDiagnostic: null:92 Couldn't resolve reference to JvmIdentifiableElement 'suppressPattern'., XtextLinkingDiagnostic: null:93 Couldn't resolve reference to JvmIdentifiableElement 'suppressPattern'., XtextLinkingDiagnostic: null:94 Couldn't resolve reference to JvmIdentifiableElement 'suppressPattern'., XtextLinkingDiagnostic: null:95 Couldn't resolve reference to JvmIdentifiableElement 'suppressPattern'.]
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:89)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:63)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:53)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:79)
        at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:37)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:254)
        at java.base/java.lang.Thread.run(Thread.java:834)


First I thought it's a problem because my CustomWebIntegrationFragment is in separate Webproject that gets built after the language, but also moving the class to the actual language project didn't help. Eclipse shows no error in the mwe2 file but does so when I remove the import which makes me think that the mwe2 file should be correct.

Am I missing something?
Re: Highlight keywords with dashes [message #1842659 is a reply to message #1842658] Sun, 27 June 2021 16:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
if you do this with maven you (of course) have to move the fragment class to a own module.
the generation in the mydsl module happens before any compilation


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Highlight keywords with dashes [message #1842662 is a reply to message #1842659] Sun, 27 June 2021 21:08 Go to previous messageGo to next message
Nico-Pascal Huch is currently offline Nico-Pascal HuchFriend
Messages: 6
Registered: June 2021
Junior Member
That makes sense. Thanks. I will look into that.
Re: Highlight keywords with dashes [message #1842961 is a reply to message #1842662] Wed, 07 July 2021 22:05 Go to previous message
Nico-Pascal Huch is currently offline Nico-Pascal HuchFriend
Messages: 6
Registered: June 2021
Junior Member
It worked, thank you very much for your help.
Previous Topic:Cannot find compatible feature name
Next Topic:Customizing XtextAnnotation
Goto Forum:
  


Current Time: Wed Apr 24 19:56:03 GMT 2024

Powered by FUDForum. Page generated in 0.03396 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top