我应该如何为这个简单的玩具语言创建Vim语法?

我应该如何为这个简单的玩具语言创建Vim语法?,vim,syntax-highlighting,Vim,Syntax Highlighting,我有一个非常简单的玩具语言,我想为它创建一个Vim语法 // A non-functional sample: // "resolve" is the keyword here, though that's not a fixed part of the // syntax. $hostsys : resolve "host" "system" // Since there's only one token to the right of the = here, it's an alias /

我有一个非常简单的玩具语言,我想为它创建一个Vim语法

// A non-functional sample:

// "resolve" is the keyword here, though that's not a fixed part of the
// syntax.
$hostsys : resolve "host" "system"
// Since there's only one token to the right of the = here, it's an alias
// and not an operation.
$zero = 0
// An operation is analogous to a method call in a typical OO language.
// "toString" would be the keyword or method name here
$str = toString $someObject
// It's possible for there to be more or fewer than one lvalue on a
// directive or operation.
// 2 return values
$xp $yp = rotate $util $x $y 90
// No return values
= println $out $str
我似乎遇到的主要问题是,这种语言没有固定的关键字集,而是每行某个位置的标记被视为关键字。我不确定在哪里可以找到这样的例子

下面是语法的完整概述:

program : line*

line : <start of line> WS* command? comment? <end of line>

command : operation | alias | directive

// Always at least one operand after operator
operation : (Register WS+)* '=' WS+ operator (WS+ operand)+ WS*

// No operator and only one "operand"
alias : Register WS+ '=' WS+ operand <not followed by WS+ operand> WS*

directive : (Register WS+)* ':' WS+ operator (WS+ operand)* WS*

operator : QuotedString | Register | bareword

operand : value

WS : /\s/

QuotedString : /"[^"]*"/

Register : /\$\S+/

BooleanLiteral : /true|false/

NoneLiteral : /none/

NumericLiteral : /-?\d+(\.\d+)?/

nonBarewordValue :
    QuotedString | Register | BooleanLiteral | NoneLiteral | NumericLiteral

Comment : "//" <any non-newline character>*

bareword : /\S+/ except {Comment, nonBarewordValue}

value : bareword | nonBarewordValue
程序:行*
行:WS*命令?议论
命令:操作|别名|指令
//运算符后始终至少有一个操作数
操作:(寄存器WS+*'='WS+运算符(WS+操作数)+WS*
//没有运算符,只有一个“操作数”
别名:寄存器WS+'='WS+操作数WS*
指令:(寄存器WS+*):'WS+运算符(WS+操作数)*WS*
运算符:QuotedString“寄存器”空字
操作数:值
WS://\s/
QuotedString:/“[^”]*”/
寄存器:/\$\S+/
BooleanLiteral:/true | false/
非文字:/none/
数值文字:/-?\d+(\。\d+)/
非BareWordValue:
QuotedString |寄存器|布尔文字|非文字|数字文字
评论:“/”*
bareword://\S+/除了{Comment,nonBarewordValue}
值:bareword | nonBarewordValue
特别是,出现在
指令
操作
中的
操作员
规则应突出显示为关键字,而不是其正常角色。此外,可以突出显示
别名
中的
=
,与
操作
中的
=/code>不同


我在这件事上一直在兜圈子,决定是时候问问更熟悉黑魔法的人了。提前谢谢。

只是想告诉你如何区分那些操作/别名关键字:

syn match alias /=\s*\w\+/ contains=alEqual
syn match operation /=\s*\w\+\ze\s\+\S\+/ contains=opEqual

syn match alEqual /=/ contained
syn match opEqual /=/ contained