Created
January 6, 2010 01:25
-
-
Save bryan-ash/269918 to your computer and use it in GitHub Desktop.
Treetop grammar to find array of C enum elements
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 Spike | |
rule typedef | |
'typedef enum { ' typedef_items ' }' | |
{ | |
def items | |
typedef_items.items | |
end | |
} | |
end | |
rule typedef_items | |
first_item:item other:(',' s item)* | |
{ | |
def items | |
[first_item.name] + other_item_names | |
end | |
def other_item_names | |
other.elements.map do |comma_and_item| | |
comma_and_item.item.name | |
end | |
end | |
} | |
end | |
rule item | |
[\w]+ | |
{ | |
def name | |
text_value | |
end | |
} | |
end | |
rule s # Optional space | |
S? | |
end | |
rule S # Mandatory space | |
(white / comment_to_eol / comment_c_style)+ | |
end | |
rule white | |
[ \t\n\r]+ | |
end | |
rule comment_to_eol | |
'//' (!"\n" .)+ | |
end | |
rule comment_c_style | |
'/*' (!'*/' . )* '*/' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment