Skip to main content

Workshop: Perl 6 regexes and grammars

Duration
8 hours (with 3 breaks)
Audience
  • People with Perl 5 experience
  • People with Perl 6 experience
  • Developers with no Perl background
Description
This course is primarily focused on understanding Perl 6 regexes (regular expressions) and grammars. Both regexes and grammars have many in common with the Perl 5 regexes but offer much more, and often in the more elegant way. We will be creating programs to use the most of regexes and grammars, from simple text matching to a complete compiler of an artificial programming language.
Requirements
  • Understanding of regular regexes (in any language)
  • Laptop with internet
  • Latest Rakudo Perl 6 installed (optional)
Contents
  • Introduction (1 hour)
    • What are regexes?
    • Why the new name?
    • What’s new in Perl 6?
    • What are grammars?
    • Perl 6 specification as a Perl 6 grammar
    • Input in Perl 6
      • How to read from console
      • How to read from files
  • Part 1. Regexes (3 hours)
    • String matching
    • Character classes
      • Backslashed character classes
      • User-defined classes
      • Unicode properties
    • Quantifiers
      • Greediness
    • Capturing
      • Using [] and ()
      • Alternatives with || or |
      • The Match object
    • Anchors
    • Look-ahead and backwards assertions
    • Adverbs (modifiers)
  • Part 2. Grammars (4 hours)
    • What are grammars
    • Grammar is a class
      • How to create a grammar
      • How to parse text with a grammar
    • Grammar methods
      • regex
      • rule
      • token
      • Reusing methods
    • Grammar attributes
      • Keeping state
      • Avoiding global variables
    • Actions
      • The Match object in actions
      • Actions as a separate class
      • Instantiation the actions class
    • Debugging a grammar
    • Practice
      • Creating a calculator
      • Parsing numbers (and how Perl 6 does it)
      • Parsing Esperanto
      • Craft-made compiler of a simple programming language