grammar Latex
rule document
(paragraph)* {
def content
[:document, elements.map { |e| e.content }]
end
}
end
rule paragraph
( tag / text )* eop {
def content
[:paragraph, elements.map { |e| e.content } ]
end
}
end
rule text
( !( tag_start / eop) . )* {
def content
[:text, text_value ]
end
}
end
# Example: \tag{inner_text}
rule tag
tag_start tag_type "{" inner_text "}" {
def content
[tag_type, inner_text.content]
end
}
end
# Example: \emph{inner_text}
rule inner_text
( !'}' . )* {
def content
[:inner_text, text_value]
end
}
end
rule eop
newline 2.. {
def content
[:newline, text_value]
end
}
end
rule tag_type
"emph" / "texttt"
end
rule newline
"\n"
end
rule tag_start
"\\"
end
end