Skip to content

Instantly share code, notes, and snippets.

@sogaiu
Last active May 6, 2021 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sogaiu/842c75e5a89d6ad5992a4bec154f246c to your computer and use it in GitHub Desktop.
Save sogaiu/842c75e5a89d6ad5992a4bec154f246c to your computer and use it in GitHub Desktop.
leverage spork/regex to help transition to using pegs
(import spork/regex)
(comment
(regex/source "a")
# => "a"
(regex/source `\s`)
# => '(set "\n\t\r\v\f ")
(regex/source `\d`)
# => '(range "09")
(regex/source "a+")
# => '(some "a")
(regex/source "a*")
# => '(any "a")
(regex/source "a?")
# => '(? "a")
(regex/source "a.")
# => '(* "a" 1)
(regex/source "x{3}")
# => '(repeat 3 "x")
(regex/source "x{2,8}")
# => '(between 2 8 "x")
(regex/source "[0-9]")
# => '(range "09")
(regex/source "[0-9a-z]")
# => '(range "09" "az")
(regex/source "[elphant]")
# => '(range "ee" "ll" "pp" "hh" "aa" "nn" "tt")
(regex/source "[^fox]")
# => '(if-not (range "ff" "oo" "xx") 1)
(regex/source "cat|dog|penguin")
# => '(choice "cat" "dog" "penguin")
(regex/source "(cat)")
# => '(capture "cat")
(regex/source "(?:cat)")
# => "cat"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment