Your SlideShare is downloading. ×
Parsing for Fun and Profit
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Parsing for Fun and Profit

2,040
views

Published on

Slides from my talk Parsing for Fun and Profit, code is available here: https://github.com/patchspace/parsing_for_fun_and_profit

Slides from my talk Parsing for Fun and Profit, code is available here: https://github.com/patchspace/parsing_for_fun_and_profit

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,040
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Parsing for Fun and Profit (but mainly fun) Ash Moran ash.moran@patchspace.co.uk PatchSpace LtdSaturday, 23 February 13
  • 2. What?Saturday, 23 February 13
  • 3. Parsing Adding structure and meaning to textSaturday, 23 February 13
  • 4. Parsing Human Languages Jake stretched his legs “Jake”, “stretched”, “his”, “legs” “Jake”<noun>, “stretched”<verb, past>, “his”<possessive pronoun>, “legs”<noun> “Jake” <noun, subject>, “stretched”, (“his”, “legs”)<noun phrase, object>Saturday, 23 February 13
  • 5. Parsing Computer Languages “foo = bar + 123” “foo”, “=”, “bar”, “+”, “123” “foo”<var>, “=”<assignment_op>, “bar”<var>, “+”<op_plus>, “123”<int_literal>Saturday, 23 February 13
  • 6. Why?Saturday, 23 February 13
  • 7. Not just compiling! Compilers breathe fire.Saturday, 23 February 13
  • 8. Pretty PrintingSaturday, 23 February 13
  • 9. Pretty Printing gofmt http://gofmt.com/Saturday, 23 February 13
  • 10. Code Smell Detectors https://rubygems.org/gems/reekSaturday, 23 February 13
  • 11. Code Smell DetectorsSaturday, 23 February 13
  • 12. Other ideas Code metrics Bug detectors Domain-specific languages Language translators (e.g. Ruby -> PHP) Code obfuscators Alternative syntaxes (e.g. CoffeeScript) Refactoring toolsSaturday, 23 February 13
  • 13. How?Saturday, 23 February 13
  • 14. Step 1 3 year computer science degreeSaturday, 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 bSaturday, 23 February 13
  • 17. Parsing Expression Grammars Like regular expressions, but can handle recursion, e.g. HTML Not actually that much harder to useSaturday, 23 February 13
  • 18. Regexes and HTMLSaturday, 23 February 13
  • 19. Treetop PEG grammarSaturday, 23 February 13
  • 20. Doing SumsSaturday, 23 February 13
  • 21. Switch to Sublime Text, idiot Code is now available: https://github.com/patchspace/parsing_for_fun_and_profit/Saturday, 23 February 13
  • 22. A Ruby Syntax HighlighterSaturday, 23 February 13
  • 23. What A tool to read in simple Ruby source and output syntax highlighted HTMLSaturday, 23 February 13
  • 24. Why Because I thought it would be fun It was Because I thought it would be easy …Saturday, 23 February 13
  • 25. WhySaturday, 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 highlightingSaturday, 23 February 13
  • 27. Switch to Chrome, idiotSaturday, 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 existSaturday, 23 February 13
  • 30. Ripper (Ruby 1.9.3)Saturday, 23 February 13
  • 31. Learn more! Skip theoretical physics, start by playing with LegoSaturday, 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 LtdSaturday, 23 February 13