2012-10-09 54 views
3

我試圖用下面的EBNF傳遞nuke腳本(foundry .nk文件),但我似乎在我的'內容'文字中捕捉得太多。另外,我很確定我在格式化過程中發生了一些主要的noob錯誤。任何人都可以幫我一把嗎?用簡單的解析EBNF解析nuke腳本

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]* 

Nukescript:

#! /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扼流圈上的 '視圖' knobvalue。通過從節點中刪除它,我的代碼按預期工作。我完整的代碼是在這裏:http://pastebin.com/z01RWpqW

感謝

+0

遞歸定義,如'knobvalue'也可以是'節點'可能會在這裏幫助,例如,參見[json grammar](http://tools.ietf.org/html/rfc4627)。將相關代碼添加到問題中,所使用的符號不是標準的EBNF。 – jfs

回答

3

這是固定聲明:

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]* 
""" 
  1. 節點可以結束與\ n所以這就是爲什麼你需要追加「\ n '*到節點定義
  2. multiknobgroup definition is not allowed以\ n結尾\ n通過節點內容定義(鍵值\ n)附加,並導致多重旋轉組不能與節點內容匹配