ericprud / shexc-mode-for-emacs

MIT License
2 stars 2 forks source link

highlight PrefixedName or IRIREF at BOL as "function" #2

Open VladimirAlexiev opened 5 years ago

VladimirAlexiev commented 5 years ago

I think that a value list like

fhirvs:conditional-read-status ["not-supported" "modified-since" "not-match" "full-support"]

should use font-lock-function-name-face on the PrefixedName, just like a bigger shape definition does, eg

<Account> CLOSED {
    a [fhir:Account];
    ...

Both of them are shapes, no matter if they are small or large. (In emacs culture a "function" is any block of code that has its own identity). Barring full shex parsing in emacs (there is the "semantic bovinator" that can do that), we can recognize them by virtue of being at beginning of line.

The current definition:

         ;; (foo:)bar
         (list (format "\\(%s\\)%s" PNAME_NS PN_LOCAL) 1 font-lock-type-face t)
         ;; foo:(bar)
         (list (format "%s\\(%s\\)" PNAME_NS PN_LOCAL) 1 font-lock-constant-face t)
         ;; <foo>
         (list (format "\\(%s\\)" IRIREF) 1 font-lock-function-name-face t)
         ;; _:foo
         (list (format "\\(%s\\)" BlankNode) 1 font-lock-function-name-face t)
  1. if I change the IRIREF <Account> to PrefixedName myshapes:Account, it won't be recognized as a "function"
  2. Why do you use font-lock-type-face for the prefix but font-lock-constant-face for the local name?
  3. I'm not familiar with using blank nodes in shex, why the last pattern is font-lock-function-name-face?

To sum up: font-lock-function-name-face should be used on any PrefixedName or IRIREF at the beginning of a line without intervening SP.

I've made a corresponding fix to imenu support:

  (setq shex-imenu-generic-expression
        (list (list nil (format "^\\(%s\\|%s\\)" IRIREF PrefixedName) 1)))
ericprud commented 5 years ago

Wow, Semantic Bovinator seems really cool!(short howto) I just wrote a ShExC mode for highlight.js where I provided context-sensitivity (e.g. the shape expression content model allows shapeDecl, shapeRef, ...) but I couldn't find any way to say that the PREFIX keyword is followed by a namespace prefix and an IRI in that order. That said, I'm pretty much in an LSE mode right now so I'd be glad to pair with you on this. I was also about to start on an Ace module; maybe I can slow this whole process down by trying to dream up some meta-meta-language to help us create these meta-languages. Hmm, maybe it's called "BNF".

VladimirAlexiev commented 5 years ago

semantic can provision a bunch of related functionalities which otherwise use different mechanisms (font-lock regexps, imenu regexp, beginning-of-defun definitions, etc). https://www.gnu.org/software/emacs/manual/html_node/emacs/Semantic.html: "Most of the language-aware features in Emacs, such as Font Lock mode (see Font Lock), rely on rules of thumb (regexps and syntax tables) that usually give good results but are never completely exact".

Homepage: http://cedet.sourceforge.net/semantic.shtml. I think the up to date doc is at https://www.gnu.org/software/emacs/manual/html_mono/semantic.html. It mentions it can be used for the following functionalities, and I've added a comment

I'm sure you'll get a kick of converting the g4 grammar to bovinator or wisent, and probably you can do it very quickly. I myself don't have time to grok this. But if you redo shexc-mode to use semantic, I'll figure out how to redo the imenu support to use that. This would be the high-road way, and in principle the better way.

The low-road way would be to just fix the font-lock regexps.

wrote a ShExC mode for highlight.js

Great! Earlier I wrote highlight.js modules for Turtle and SPARQL. It wasn't properly merged, but now cygri and w3c (respec) want to use it, so I'll make an effort to do it. But they tell me the new organization is to have a repo per language, so I expect you'll also have to turn your PR into a separate repo: see https://github.com/highlightjs/highlight.js/pull/1553