我必须编辑很多.bnf格式的语法文件。在Emacs中有这样的模式吗?
我看过CEDET的语义包,它似乎曾经有一个bnf模式,但现在不再有了。这段代码是可以googlable的,但是semantic-bnf-mode似乎并不存在:
(autoload 'semantic-bnf-mode "semantic-bnf" "Mode for Bovine Normal Form." t)
(add-to-list 'auto-mode-alist '("\\.bnf$" . semantic-bnf-mode))发布于 2009-11-26 22:39:26
谢谢唐。我稍微改进了一下代码,这是一个新版本。
(define-generic-mode 'bnf-mode
() ;; comment char: inapplicable because # must be at start of line
nil ;; keywords
'(
("^#.*" . 'font-lock-comment-face) ;; comments at start of line
("^<.*?>" . 'font-lock-function-name-face) ;; LHS nonterminals
("<.*?>" . 'font-lock-builtin-face) ;; other nonterminals
("::=" . 'font-lock-const-face) ;; "goes-to" symbol
("\|" . 'font-lock-warning-face) ;; "OR" symbol
("\{:\\|:\}" . 'font-lock-keyword-face) ;; special pybnf delimiters
)
'("\\.bnf\\'" "\\.pybnf\\'") ;; filename suffixes
nil ;; extra function hooks
"Major mode for BNF highlighting.")发布于 2009-11-26 06:26:46
语义bnf模式用于它自己的内部解析器格式。最初的“bnf”名字是一个双关语,最终让人们感到困惑。
现有的语义模式如wisent-语法模式和bovine语法模式都是针对CEDET使用的语法,原始的BNF -模式是相似的,并不能代表真正的BNF风格的语法。
您可能对ebnf2ps更感兴趣,它将ebnf语法(yacc等)转换为语法图表,尽管我自己还没有用过它。
发布于 2009-11-26 08:59:49
为了更具可读性和可读性,jmmcd用以下内容回答了自己的问题。您可以在emacs Help > elisp > 23.2.6 Generic Modes中找到更多。
“我把它放到我的.emacs里,它似乎起作用了。”
(define-generic-mode 'bnf-mode
'("#")
nil
'(("^<.*?>" . 'font-lock-variable-name-face)
("<.*?>" . 'font-lock-keyword-face)
("::=" . 'font-lock-warning-face)
("\|" . 'font-lock-warning-face))
'("\\.bnf\\.pybnf\\'")
nil
"Major mode for BNF highlighting.")https://stackoverflow.com/questions/1800199
复制相似问题