我复制了关于SMIE的GNU手册中的代码。 begin
和end
的缩进效果很好。
(defvar sample-smie-grammar
(smie-prec2->grammar
(smie-bnf->prec2
'((id)
(inst ("begin" insts "end")
("if" exp "then" inst "else" inst)
(id ":=" exp)
(exp))
(insts (insts ";" insts) (inst))
(exp (exp "+" exp)
(exp "*" exp)
("(" exps ")"))
(exps (exps "," exps) (exp)))
'((assoc ";"))
'((assoc ","))
'((assoc "+") (assoc "*")))))
但是当我尝试添加class
/ endclass
,module
/ endmodule
时,新添加的对根本不会缩进。当我启用show-paren-mode
时。它们不会突出显示为begin
和end
。
(defvar sample-smie-grammar
(smie-prec2->grammar
(smie-bnf->prec2
'((id)
(inst ("begin" insts "end")
("module" insts "endmodule")
("class" insts "endclass")
("if" exp "then" inst "else" inst)
(id ":=" exp)
(exp))
(insts (insts ";" insts) (inst))
(exp (exp "+" exp)
(exp "*" exp)
("(" exps ")"))
(exps (exps "," exps) (exp)))
'((assoc ";"))
'((assoc ","))
'((assoc "+") (assoc "*")))))