Triply-Dev / YASGUI.YASQE-deprecated

Deprecated, see https://github.com/TriplyDB/Yasgui for the Yasgui monorepo
MIT License
73 stars 36 forks source link

different codemirror class for plain prefixes? #67

Closed alanruttenberg closed 9 years ago

alanruttenberg commented 9 years ago

In tokenizer.js push the PNAME_NS higher, but change regex to not allow characters after color. Allows for this styling:

sample

index 85e236d..b240cd1 100644
--- a/lib/grammar/tokenizer.js
+++ b/lib/grammar/tokenizer.js
@@ -143,9 +143,15 @@ CodeMirror.defineMode("sparql11", function(config, parserConfig) {
            regex:new RegExp("^"+COMMENT),
            style:"comment" },

-       { name: "IRI_REF",
+                { name: "PNAME_NS",
+                  regex:new RegExp("^"+PNAME_NS+"[^A-Za-z]"),
+             style:"qualifier" },
+
+           { name: "IRI_REF",
            regex:new RegExp("^"+IRI_REF),
-           style:"variable-3" },
+         style:"variable-3" },
+
+       

        { name: "VAR1",
            regex:new RegExp("^"+VAR1),
@@ -221,9 +227,6 @@ CodeMirror.defineMode("sparql11", function(config, parserConfig) {
            regex:new RegExp("^"+PNAME_LN),
            style:"string-2" },

-       { name: "PNAME_NS",
-           regex:new RegExp("^"+PNAME_NS),
-           style:"string-2" },

        { name: "BLANK_NODE_LABEL",
            regex:new RegExp("^"+BLANK_NODE_LABEL),
LaurensRietveld commented 9 years ago

I see the use, but would like to avoid changing the tokenizer for this as I'd like to deviate as little as possible from the regex and grammar definition of the official standards

alanruttenberg commented 9 years ago

I understand the rationale. Any suggestion for doing something that keeps the tokenizer intact but lets the cm class differ?

LaurensRietveld commented 9 years ago

You could try the following


    var checkPlainPrefixes = function(yasqe) {
        $(yasqe.getWrapperElement()).find('.cm-string-2').each(function(i, el){
            if (val.charAt(val.length-1) == ":") {
                $(el).addClass("plainPrefix");
            } else {
                $(el).removeClass("plainPrefix");
            }
        })
    }
    checkPlainPrefixes(yasqe);//run for first time
    yasqe.on('change', checkPlainPrefixes);

Then you could use a css rule such as .cm-string-2.plainPrefix {color:black}

The downside of this approach: extra work for every time the cursor changes. Nothing drastic, but still yet another thing to do each time a cursor changes

ps. if jquery is not loaded on your page, you could use the one in the YASQE namespace instead. (i.e. $ -> YASQE.$)