Residents of parse.y ‣ I'm in "Five Chariot Stars" ‣ A castle inhabited by the creator of the Ruby, Two monsters, and the Organizers of TRICK $ git shortlog -ns parse.y 1354 Nobuyoshi Nakada 362 Yukihiro "Matz" Matsumoto 252 yui-knk 174 Yusuke Endoh 75 ydah The Patch Monster The Creator of the Ruby The Parser Monster The Organizer of TRICK Me
parse.y is ‣A file that defines the rules and symbols needed to parse Ruby programs and generate abstract syntax trees (AST) ‣Before Ruby 3.2, it was compiled using the GNU Bison parser generator, and from Ruby 3.3 onward, it uses a parser generator called Lrama
Lrama has tracing $ lrama sample.y - - trace=rules Grammar rules: $accept - > program YYEOF program - > expr expr - > term '+' expr expr - > term term - > factor '*' term term - > factor factor - > number
Railroad diagram ‣ A way to represent a context-free grammar ‣ Represent a graphical alternative to BNF and other text- based grammars as metalanguages
Chevrotain ‣ Parser Building Toolkit for JavaScript ‣https://github.com/Chevrotain/chevrotain ‣ Primarily builds parsers using LL(k) grammar techniques, specifically the top-down parsing method ‣Grammars are defined directly within JavaScript or TypeScript code using a fluent API
Syntax Diagrams ‣ Visually examining grammar diagrams is often useful during development and for documentation purposes ‣Generate railroad diagrams using the railroad-diagrams library
railroad-diagrams ‣ A small JS+SVG library for drawing railroad syntax diagrams, like on JSON.org ‣This library is supported by both JS and Python modules ‣Ruby is not supported ...
Conclusion ‣ We have the power to look at context-free grammar ‣ Railroad diagrams make the structure of grammar easier to read ‣ If it doesn't exist, just create it ‣ Only on the Lrama