Created
June 10, 2017 14:51
-
-
Save bioduds/cff61d5071e53e3b1ada177c9c4cc107 to your computer and use it in GitHub Desktop.
reuse grammar in grammar?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## reusable grammars | |
grammar TIMESTAMP { | |
rule TOP { <WEEK-DAY> <MONTH> <DAY> <TIME> <PLACE> <PLACE> <YEAR> } | |
token WEEK-DAY { \S+ } | |
token MONTH { \S+ } | |
token DAY { \d+ } | |
token TIME { \d+ \: \d+ \: \d+ } | |
token PLACE { \S+ } | |
token YEAR { \d+ } | |
} | |
## | |
grammar VERSION { | |
rule TOP { <GREETING> <NODE> <VERSION> <TIMESTAMP> } | |
token GREETING { 'Hello,' | 'Hi,' | 'Good Morning,' } | |
token NODE { 'I am ' ( \d+ \. \d+ \. \d+ \. \d+ ) } | |
token VERSION { 'and my version is ' ( \d+ \. \d+ \. \d+ ) } | |
# TIMESTAMP HERE, HOW? | |
} | |
class VERSION::Actions { | |
has $.timestamp; | |
has $.node; | |
has $.version; | |
method TOP ($/) { | |
self!respond; | |
say "VERACK::Greetings done!"; | |
} | |
method GREETING ($/) { | |
say 'Has greeting!'; | |
my $proc = run 'date', :out, :err; | |
$!timestamp = $proc.out.slurp: :close; | |
} | |
method NODE ($/) { say 'Has NODE ' ~ $/[0]; $!node = $/[0]; } | |
method VERSION ($/) { say 'Has VERSION ' ~ $/[0]; $!version = $/[0]; } | |
method !respond { | |
say 'Responding to ' ~ $!node ~ ' with version ' ~ $!version ~ ' on ' ~ $!timestamp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment