Support User defined literals
osyo-manga opened this issue · 6 comments
Twitter でそういう話がでていたので立てておきます。
[目的]
以下のように C++11 で追加されたユーザ定義リテラルもリテラルとして一緒に
ハイライトを行いたい。
// _user_defined_literal をリテラルとしてハイライトしたい
1234_user_defined_literal
"homu"_user_defined_literalVim のシンタックスはあまり詳しくないのですが、とりあえず、既存のシンタックスの末尾に `\w*` を追加してみました。
syn match cNumber display contained "\d\+\(\w*\)\>"
syn match cNumber display contained "0x\x\+\(\w*\)\>"
syn match cOctal display contained "0\o\+\(\w*\)\>" contains=cOctalZero
syn match cFloat display contained "\d\+\.\d*\(\w*\)"
syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\w*+ end='$' contains=cSpecial,cFormat,@Spellいまは『数値+リテラル』を1つのシンタックスとして定義する事を考えています。
上記のコードを https://github.com/vim-jp/cpp-vim/blob/master/syntax/cpp.vim#L38 あたりに追加すればよさそう?
Vim のシンタックスに詳しい人誰か。
リテラルとして扱うのではなく、どうせならユーザ定義リテラルだと分かる様にしたいです。
反応遅くなってすみません.
とりあえず上ので実装して試してみました.
https://github.com/rhysd/cpp-vim/tree/user-defined-literals
@mattn
その場合,ユーザ定義リテラル用のハイライトを定義して,nextgroup を既存のリテラルのハイライトに定義するのが良いんでしょうか?
ハイライト設定はあまり書いたことが無いので,どうやるのが定石なのか分からないです…
ですです > nextgroup
うーん,現状 nextgroup で単純にやろうとすると,数値リテラルはすべて \> で終わっているので,45min をハイライトできないですね…
何か良い方法あるでしょうか?
Hi all, any plans to add literals highlight into master?
リテラルとして扱うのではなく、どうせならユーザ定義リテラルだと分かる様にしたいです。
I do not want to treat it as a literal, but I want to make sure that it is a user-defined literal.
My understanding is that to do this would require information from the source file which can only be obtained by parsing it as a compiler would do. Consider the related desire of highlighting macros: it would be necessary to detect if a sequence was found in a corresponding preprocessor directive, which involves scanning the file for those include directives.
While it is possible to solve the above example fairly easily, this quickly requires implementing more and more rules until, eventually, you must implement a C++ parser to get highlighting right in every case. And it is not possible to do this with regular expressions.
I would suggest closing this issue and researching e.g. DyeVim to see if it fits your needs, or another project found by a search query like "vim C++ semantic highlighting".
