我试图用下面的EBNF传递一个nuke脚本(foundry.nk文件),但是我似乎在“content”文本中捕获了太多内容。我也很确定我在格式上犯了一些重大的错误。有人能帮我吗?
EBNF:
file := header, content
header := shebang, version
shebang := '#!', ts, word, ('-',[a-zA-Z0-9]+)?,'\n'
version := 'version', ts, [0-9], '.', [0-9], ts, 'v', [0-9], '\n'
content := node*
node := word, ts, '{\n', nodecontent*, '}\n'
nodecontent := ts, knobname, ts, knobvalue, '\n'
knobname := word
knobvalue := word / string / multiknobgroup / knobgroup
knobgroup := '{', (word / string, ts)*, '}'
multiknobgroup := '{\n', (ts, knobgroup, '\n')*, ts, '}\n'
string := '"', word*, '"'
word := ([a-zA-Z0-9-_()/\~.<>?;:])+,ts
ts := [ \t]*
纽克脚本:
#! /opt/foundry/Nuke/6.3v7-x64/Nuke6.3 -nx
version 6.3 v7
Root {
inputs 0
name /path/to/file_name.nk
first_frame 0
last_frame 100
lock_range true
format "2048 1556 0 0 2048 1556 1 2K_Super_35(full-ap)"
proxy_type scale
proxy_format "1024 778 0 0 1024 778 1 1K_Super_35(full-ap)"
addUserKnob {20 custom l Custom}
addUserKnob {1 scene l Scene}
views {
{left ""}
{right ""}
}
}
当前的EBNF阻塞了“views”knobvalue。通过从节点中删除它,我的代码可以按预期工作。我的完整代码在这里:http://pastebin.com/z01RWpqW
谢谢
最佳答案
这是固定声明:
declaration = """
file := header, content
header := shebang, version
shebang := '#!', ts, word, ('-',[a-zA-Z0-9]+)?,'\n'
version := 'version', ts, [0-9], '.', [0-9], ts, 'v', [0-9], '\n'
content := node*
node := word, ts, '{\n', nodecontent*, ts, '}', '\n'*
nodecontent := ts, knobname, ts, knobvalue, '\n'
knobname := word
knobvalue := word / string / multiknobgroup / knobgroup
knobgroup := '{', (word / string)*, ts, '}'
multiknobgroup := '{\n', (ts, knobgroup, '\n')*, ts, '}'
string := '"', word*, '"'
word := ([a-zA-Z0-9-_()/\~.<>?;:])+,ts
ts := [ \t]*
"""
节点可能以结束,所以这就是为什么需要将'\n'*附加到节点定义
不允许multiknobgroup定义以}结尾,因为\n由nodecontent定义(键值)附加,这将导致multiknobgroup与nodecontent不匹配