Created
June 9, 2017 13:04
-
-
Save bioduds/f4acfdc1294684243976a4205c7413b5 to your computer and use it in GitHub Desktop.
How to get the array?
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
#### SO, I have this grammar | |
unit package EC::Grammars:auth<github:bioduds>; | |
grammar ADDR { | |
rule TOP { <IDENTIFIER> <TIMESTAMP> <LINKER> <ADDRESS>+ } | |
token IDENTIFIER { 'Right now, ' } | |
rule TIMESTAMP { <WEEK-DAY> <MONTH> <DAY> <TIME> <PLACE> <YEAR> } | |
token WEEK-DAY { \S+ } | |
token MONTH { \S+ } | |
token DAY { \d+ } | |
token TIME { \d+ \: \d+ \: \d+ } | |
token PLACE { \S+ } | |
token YEAR { \d+ } | |
token LINKER { 'I have' } | |
token ADDRESS { \d+ \. \d+ \. \d+ \. \d+ } | |
} | |
class ADDR::Actions { | |
method TOP ($/) { say "ADDR went through!" } | |
method IDENTIFIER ($/) { say "Got IDENTIFIER " ~ $/; } | |
method TIMESTAMP ($/) { say "Got TIMESTAMP " ~ $/; } | |
method LINKER ($/) { say "Got LINKER" ~ $/; } | |
method ADDRESS ($/) { | |
say "Got ADDRESSES " ~ $/; | |
for $/ -> $addr { | |
say $addr; | |
} | |
} | |
} | |
#### being called from | |
use v6; | |
use lib 'lib/grammars'; | |
use message; | |
say "Running Test..."; | |
my $addr = EC::Grammars::ADDR.new.parse( | |
'Right now, Sex Jun 9 09:23:35 BRT 2017 I have 154.54.78.96 56.21.147.10', | |
:actions( EC::Grammars::ADDR::Actions.new ) | |
); | |
#### BUT I'M ONLY GETTING THE FIRST IP ADDRESS, HOW CAN I GET ALL THE LIST? THANKS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to allow for whitespace between the addresses so you must specify the first rule differently;
Also by checking the returned Match object in
$addr
you will see that Any is returned and this means that the parse failed somewhere. In this case before the second address because you saw the first one.Success
Marcel