Created
February 28, 2009 04:02
-
-
Save boj/71859 to your computer and use it in GitHub Desktop.
SgfGrammar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar SgfGrammar | |
rule node | |
'(' sp chunk* sp ')' sp { | |
def value | |
get([elements[2]]) | |
end | |
def get(e) | |
a = [] | |
if !e.nil? | |
e.each do |el| | |
if el.respond_to?(:value) | |
a << el.value | |
else | |
a += get(el.elements) if !el.nil? | |
end | |
end | |
end | |
a | |
end | |
} | |
end | |
rule chunk | |
';' sp property_set* sp { | |
def value | |
get([elements[2]]) | |
end | |
def get(e) | |
a = [] | |
if !e.nil? | |
e.each do |el| | |
if el.respond_to?(:value) | |
a << el.value | |
else | |
a += get(el.elements) if !el.nil? | |
end | |
end | |
end | |
a | |
end | |
} | |
end | |
rule property_set | |
property property_bracket* sp { | |
def value | |
{ | |
:property => elements[0].text_value, | |
:data => elements[1].text_value[1..-2] | |
} | |
end | |
} | |
end | |
rule property_bracket | |
'[' ( [^\[\]] / property_bracket )* ']' | |
end | |
rule property | |
[A-Z]+ / [A-Z] sp | |
end | |
rule sp | |
[\r\n\t ]* | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment