The compiler can be broken down into 3 separate stages:
The opal lexer is implemented in pure ruby using
StringScanner class from the opal stdlib. The source code is scanned
and tokens are then provided to the parser. This process simply converts
the ruby code given as a string, into a list of tokens representing the
parts of the ruby code.
The opal parser is implemented using a standard
bison like syntax, but relies on
racc, a ruby implementation of yacc/bison
which is again available in the standard library. The parser takes these tokens
generated by the lexer and builds a syntax tree representing the ruby code.
This syntax tree is represented by sexps. As
ruby is such a complex and dynamic language, there is a lot of interaction
between the parser and the lexer, namely through a preserved