# OMeta OMeta is language agnostic parser and compiler. [Alex Warth's Ph.D Thesis: OMeta: an extended PEG.](http://www.vpri.org/pdf/tr2008003_experimenting.pdf) is fairly easy to read, even for those unfamiliar with parsing. OMeta unifies typically separate parsing steps into a single one: It can be thought of as an extension of regular expressions (regex) matching, though it's better to think of regex as a weird special case of OMeta. The parsing problem can be thought of as transforming text into (abstract syntax) tree (AST) according to some grammar. The compilation problem can be though of as transforming text into ASTs and then back to text. As with other parsing expression grammars (PEGs), OMeta uses the ordered choice operator `/` rather than the usual `|`. This makes the parser behave more like an imperative program. Ordered choice means `(aa / a) a` will _not_ match `aa` because once the first alternative (between `aa` and `a`) is matched, the second one isn't tried, even though the full expression doesn't match as a result. OMeta can use memoization for optimization (and I think doesn't need anything else!). ## Tips Because OMeta's circularity (it generate its own code in the host language), it may be difficult to implement an intial new version of OMeta. My two easiest options (IMO) are: 1. Find an existing implementation of OMeta and change the production rules to generate code in your host (rather than its current host) language. 2. Do production (`->`) the "old fashioned" way rather than the OMeta way by writing a bunch of if statements (or visitor pattern, recursive descent, patttern matching, depending on the host language and your prefered style). 3. Try to get from text to AST first rather than all the way from text -> AST -> text. Have some way to check that the AST looks right. 4. Given 3, don't try to implement all OMeta syntax/semantic at first. I suggest starting with ordered choice and concatenation. And then add more as you see your program running and producing the right output. ## OMeta implementations See [the Wikipedia section](https://en.wikipedia.org/wiki/OMeta#Versions) See also [pymetaterp](https://github.com/asrp/pymetaterp) which has a shorter [parser interpreter version in 103 lines of Python](https://github.com/asrp/pymetaterp/blob/master/pymetaterp/boot.py).