Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Highlight keywords with dashes
Highlight keywords with dashes [message #1841931] Thu, 03 June 2021 14:42 Go to next message
Eclipse UserFriend
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 15:21 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Highlight keywords with dashes [message #1841937 is a reply to message #1841934] Thu, 03 June 2021 16:00 Go to previous messageGo to next message
Eclipse UserFriend
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 02:57 Go to previous messageGo to next message
Eclipse UserFriend
no i dont see any. i also wonder if this is a general problem/bug that is worth fixing
Re: Highlight keywords with dashes [message #1841983 is a reply to message #1841952] Sat, 05 June 2021 16:22 Go to previous messageGo to next message
Eclipse UserFriend
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 01:34 Go to previous messageGo to next message
Eclipse UserFriend
I don't understand why subclassing the fragment should not work
Re: Highlight keywords with dashes [message #1842658 is a reply to message #1841931] Sun, 27 June 2021 12:19 Go to previous messageGo to next message
Eclipse UserFriend
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 12:23 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Highlight keywords with dashes [message #1842662 is a reply to message #1842659] Sun, 27 June 2021 17:08 Go to previous messageGo to next message
Eclipse UserFriend
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 18:05 Go to previous message
Eclipse UserFriend
It worked, thank you very much for your help.
Previous Topic:Cannot find compatible feature name
Next Topic:Customizing XtextAnnotation
Goto Forum:
  


Current Time: Fri Apr 18 13:30:59 EDT 2025

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

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

Back to the top