Ace editor uses mode.js to highlight keywords and worker.js to check syntax. In ACE editor, I want to validate syntax for ANTLR grammar rules(from .g4 file) for given user input and highlight them. By default ACE can validate syntax for Javascript(JSHint), JSON etc.
Similarly is it possible to do for ANTLR grammar ? And if so how to do it ?
Related
I am writing an asciidoc document and want to do syntax highlighting for "code" that is not known to the asciidoc highlighter.
For example I want to highlight the output of git status -sb
## main...origin/main
?? test.txt
For all I want I can imagine simple rules (for example regex).
Is there a simple way to extend the asciidoctor source code highlighter for custom syntax?
Vim supports spell-check only in comments section already, however, if I have a type name or something not a regular word, it will consider it as a typo. For instance, in the following example, std::endl will be highlighted as typo.
// Don't use std::endl, it will flush unnecessarily
I wish we could use `` to escape them like following.
// Don't use `std::endl`, it will flush unnecessarily
Is there any tips or solution for this besides adding everything into dictionary?
I really don't want to disable spell-check due to this, so any help is greatly appreciated.
Thank you!
You can use this syntax rule to create a new group matching a `...` block and disable spelling inside those blocks:
syntax region cCommentNoSpell start=+`+ end=+`+
\ contained containedin=cComment,cCommentL transparent
\ contains=#NoSpell
To load this for cpp and c files, add this line (by itself) to a file ~/.vim/after/syntax/c.vim, so it is loaded after the system syntax files for C++ and C. (The cpp syntax rule includes all syntax for c so you'll get it on cpp too.)
The syntax rule uses ` as both start and ending delimiter.
It uses contained and containedin to only match inside comments. The cComment rule matches traditional multi-line /* ... */ comments and cCommentL matches single-line // ... comments. (Both are defined in the syntax file for C and C++ shipped with Vim.)
The transparent attribute instructs it not to use this syntax rule as a highlighting group, so it keeps the normal highlighting for comments in the parts matched by this rule.
Finally, contains=#NoSpell is what disables spelling on the regions that match this rule. See :help spell-syntax for more details on how spelling works together with syntax highlighting.
Am a hardware engineer and I use Embedded Ruby Language to simplify writing my hardware verilog/system verilog code. In my *.sv and *.v files, i have a lot of ERB variables starting with "__" (double underscore). E.g. <% __MEM_DEPTH = 64 %>. Is there any way by which I can make vim display the words starting with the double underscore in a different color?
You can extend the built-in syntax highlighting. For example, put the following into ~/.vim/after/syntax/verilog.vim:
syntax match verilogErbVar "\<__\w\+\>"
hi link verilogErbVar Identifier
This assumes that the corresponding text fragments aren't yet matched by the original syntax (in my short test, they weren't). Else, you need to find the syntax groups that contain them and add a containedin=... to the :syntax command.
To find out which syntax group causes the highlighting. :syn list shows all active groups, but it's easier when you install the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin.
I'm writing a vim syntax script and I want to be able to make lines matching a certain pattern, say, '^>', "source" or imitate the markdown syntax highlighting.
Is there a way to do this at the syntax script level? Do I need to just copy and paste it in manually and make the proper adjustments? Does this require a modeline on the actual file?
Thanks!
Have a look at :help :syn-include. It allows you to import an existing syntax (like e.g. markdown) into a syntax cluster in your own syntax, and then you can assign syntax regions (if I understand you correctly, that would be a region starting with /^>/ and ending at the end of the line /$/) to it.
Note that success isn't guaranteed; you need some collaboration from the included syntax. (For example, if the markdown syntax anchors its patterns at ^, but now it's included behind the > prefix, it won't match any more.) In the worst case, you have to modify the included syntax or copy it completely into your own syntax.
I want to write bison syntax file for vim. I've managed to write syntax rule for definition section. Now I'm trying to compose syntax rule for bison rule. So, I have
rule : identifier ":" rightHandSidePart ( "|" rightHandSidePart )* ";"
where
rightHandSidePart : listOfIdentifiers "{" /* some C code here */ "}"
listOfIdentifiers : listOfIdentifiers identifier | /* nothing */
and identifier may be declared as [_a-zA-Z][_0-9a-zA-Z]* regular expression.
So the question is: how do I translate this grammar to vim syntax rules?
You might be able to use autohighlight to convert your grammar to vim's syntax regex.
Autohighlight generates vim and emacs syntax highlighting from a BNF grammar and a description of which terms should be highlighted which colors.