Skip to content

Instantly share code, notes, and snippets.

@tanraya
Created March 22, 2013 12:15
Show Gist options
  • Select an option

  • Save tanraya/5220815 to your computer and use it in GitHub Desktop.

Select an option

Save tanraya/5220815 to your computer and use it in GitHub Desktop.
grammar Interpolation
rule document
(text / variable / object / space)* {
def content
elements.map { |e| e.content }
end
}
end
######################################################################
# Main Literals
rule text
[^{:%]+ <TextLiteral>
end
rule variable
space? "%{" name "}" space? <VariableLiteral>
end
rule object
space? "%{" object_name assignment "}" space? <ObjectLiteral>
end
rule assignment
'[' attribute_name space? '=' space? attribute_value ']' <AssignmentLiteral>
end
######################################################################
# Common Literals
rule space
[\s]+
end
rule name
[A-Z:]+ {
def content
text_value
end
}
end
rule object_name
[A-Z] 1..1 [A-Za-z:]+ {
def content
text_value
end
}
end
rule attribute_name
'$' [a-z]+ {
def content
elements[1].text_value
end
}
end
rule attribute_value
[^\]]+ {
def content
text_value
end
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment