Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created December 5, 2015 17:51
Show Gist options
  • Save zoffixznet/4cff770d3b81980c236f to your computer and use it in GitHub Desktop.
Save zoffixznet/4cff770d3b81980c236f to your computer and use it in GitHub Desktop.
use v6;
use Grammar::Tracer;
grammar IRC::Grammar:ver<1.001001> {
token TOP { [ <message> \r\n ]+ }
token message { [':' <prefix> ' '+ ]? <command> <params> }
token prefix { [<servername> | <nick>] [ '!' <user> ]? [ '@' <host> ]? }
token command { <letter>+ | <number>**3 }
token params { ' '* [ ':' <trailing> | <middle> <params> ]? }
token middle { <-[: \0\r\n]> <-[ \0\r\n]>+ }
token trailing { <-[\0\r\n]>+ }
token target { <to> [ ',' <target> ]? }
token to { <channel> | <user> '@' <servername> | <nick> | <mask> }
token channel { ['#' | '&'] <chstring> }
token servername { \S+ } # see RFC 952 [DNS:4] for allowed hostnames
token nick { <letter> [ <letter> | <number> | <special> ]+ }
token mask { <[#$]> <chstring> }
token chstring { <-[ \a\0\r\l,]> }
token user { <-[ \0\r\l]>+ }
token letter { <[a..zA..Z]> }
token number { <[0..9]> }
token special { <[-\[\]\\`^{}]> }
}
say so IRC::Grammar.parse(":ZoffixW!~ZoffixW\@unaffiliated/zoffix JOIN #perl6bot\r\n");
TOP
| message
| | prefix
| | | servername
| | | * MATCH "ZoffixW!~ZoffixW\@unaffiliated/zoffix"
| | * MATCH "ZoffixW!~ZoffixW\@unaffiliated/zoffix"
| | command
| | | letter
| | | * MATCH "J"
| | | letter
| | | * MATCH "O"
| | | letter
| | | * MATCH "I"
| | | letter
| | | * MATCH "N"
| | | letter
| | | * FAIL
| | * MATCH "JOIN"
| | params
| | | middle
| | | * MATCH "#perl6bot"
| | | params
| | | | middle
| | | | * FAIL
| | | * MATCH ""
| | * MATCH " #perl6bot"
| * MATCH ":ZoffixW!~ZoffixW\@unaffiliated/zoffix JOIN #perl6bot"
* FAIL
False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment