题
目前我正在试图编写一个树梢语法分析简单的游戏形式的文件,并将其主要工作为止。然而,有几个问题上来了。
- 我不确定如何以实际访问的结构树梢产生的后一分析。
- 是否有更好的办法来处理拍摄的所有人物,比我的字符的规则吗?
有一个情况下评论说我不能写是正确的。
C[player1[4k\]:嗨player2[3k\]:嗨!]
我不能理解如何处理嵌套结构中的C[]节点与[]'s内。
以下是我的当前进展情况。
itunes-语法。树梢
grammar SgfGrammar
rule node
'(' chunk* ')' {
def value
text_value
end
}
end
rule chunk
';' property_set* {
def value
text_value
end
}
end
rule property_set
property ('[' property_data ']')* / property '[' property_data ']' {
def value
text_value
end
}
end
rule property_data
chars '[' (!'\]' . )* '\]' chars / chars / empty {
def value
text_value
end
}
end
rule property
[A-Z]+ / [A-Z] {
def value
text_value
end
}
end
rule chars
[a-zA-Z0-9_/\-:;|'"\\<>(){}!@#$%^&\*\+\-,\.\?!= \r\n\t]*
end
rule empty
''
end
end
和我的测试情况,目前不包括的C[]节点与上述提到的嵌套架的问题:
例。rb
require 'rubygems'
require 'treetop'
require 'sgf-grammar'
parser = SgfGrammarParser.new
parser.parse("(;GM[1]FF[4]CA[UTF-8]AP[CGoban:3]ST[2]
RU[Japanese]SZ[19]KM[0.50]TM[1800]OT[5x30 byo-yomi]
PW[stoic]PB[bojo]WR[3k]BR[4k]DT[2008-11-30]RE[B+2.50])")
解决方案
- 该结构还是回到你作为一个树SyntaxNodes(如果结果是"无",检查分析程序。failure_reason).你可以走这棵树或(和建议)可以增加它与职能做你想要什么就叫你的主要功能上的根源。
如果你的意思是"你怎么访问的部件从一个节点内功能?"有几种方法。你可以在他们的元件[x]符号或通过的规则:
rule url_prefix
protocol "://" host_name {
def example
assert element[0] == protocol
assert element[2] == host_name
unless protocol.text_value == "http"
print "#{protocol.text_value} not supported"
end
end
}
你也可以他们的名字就像这样:
rule phone_number
"(" area_code:( digit digit digit ) ")" ...
然后提到他们的名字。
你的字符的规则看起来不错如果你只想到匹配的那些字。如果你想要比赛 任何 你可能只是用一个点(.) 像在一个普通的表达。
我不熟悉的语言你是在试图分析,但是该规则是寻找可以是这样的:
rule comment "C" balanced_square_bracket_string end rule balanced_square_bracket_string "[" ( [^\[\]] / balanced_square_bracket_string )* "]" end
中间部分第二匹配规则任何东西,不是一个平支架或一套串与balanced_square括号内。
P.S.有一个相当积极 谷歌群, 与档案和搜索。
不隶属于 StackOverflow