14. Step 1
3 year computer science
degree
Saturday, 23 February 13
15. Lexing/Tokenising
if x > 100 then return “big” else return “small”
if x > 100 then return “big” else return “small”
Saturday, 23 February 13
16. Tree Building
if x > 100 then return “big” else return a + b
if
> then else
x 100 return return
“big” +
a b
Saturday, 23 February 13
17. Parsing Expression
Grammars
Like regular expressions, but can handle
recursion, e.g. HTML
Not actually that much harder to use
Saturday, 23 February 13
26. How
Build a parse tree of the Ruby source
Walk the tree and spit out a <span>
element for each bit of text
Oh yes, make sure each line goes in <div>
and <pre> tags
Wrap it in <html>
And for bonus points, do some fancy
method highlighting
Saturday, 23 February 13
28. Switch to
Sublime Text again, idiot
Code is now available:
https://github.com/patchspace/parsing_for_fun_and_profit/
Saturday, 23 February 13
29. We’re doing this the
hard way
Ruby’s grammar is too complex and
undefined to easily implement as a PEG
Tools for parsing Ruby already exist
Saturday, 23 February 13
31. Learn
more!
Skip theoretical physics,
start by playing with Lego
Saturday, 23 February 13
32. Do more
Ideas you might like to try:
CSV parser
JSON parser (return arrays & hashes)
XML parser
JSON highlighter
A simple JavaScript minifier (just kill
whitespace)
Saturday, 23 February 13
33. Thank you
Ash Moran
ash.moran@patchspace.co.uk
PatchSpace Ltd
Saturday, 23 February 13