Created
October 4, 2014 06:16
-
-
Save rns/40a10da861f10d4f9912 to your computer and use it in GitHub Desktop.
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
\[ | |
'pairs', | |
[ | |
'pair', | |
[ | |
'name', | |
'Student' | |
], | |
[ | |
'value', | |
[ | |
'pairs', | |
[ | |
'pair', | |
[ | |
'name', | |
'PInfo' | |
], | |
[ | |
'value', | |
[ | |
'pairs', | |
[ | |
'pair', | |
[ | |
'name', | |
'ID' | |
], | |
[ | |
'value', | |
[ | |
'number', | |
'0001' | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'Name.First' | |
], | |
[ | |
'value', | |
[ | |
'string', | |
'"Joe"' | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'Name.Last' | |
], | |
[ | |
'value', | |
[ | |
'string', | |
'"Burger"' | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'DOB' | |
], | |
[ | |
'value', | |
[ | |
'string', | |
'"01/01/2000"' | |
] | |
] | |
] | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'School' | |
], | |
[ | |
'value', | |
[ | |
'string', | |
'"West High"' | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'Address' | |
], | |
[ | |
'value', | |
[ | |
'pairs', | |
[ | |
'pair', | |
[ | |
'name', | |
'Str1' | |
], | |
[ | |
'value', | |
[ | |
'string', | |
'"001 Main St."' | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'Zip' | |
], | |
[ | |
'value', | |
[ | |
'number', | |
'12345' | |
] | |
] | |
] | |
] | |
] | |
] | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'Student' | |
], | |
[ | |
'value', | |
[ | |
'pairs', | |
[ | |
'pair', | |
[ | |
'name', | |
'PInfo' | |
], | |
[ | |
'value', | |
[ | |
'pairs', | |
[ | |
'pair', | |
[ | |
'name', | |
'ID' | |
], | |
[ | |
'value', | |
[ | |
'number', | |
'0002' | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'Name.First' | |
], | |
[ | |
'value', | |
[ | |
'string', | |
'"John"' | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'Name.Last' | |
], | |
[ | |
'value', | |
[ | |
'string', | |
'"Smith"' | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'DOB' | |
], | |
[ | |
'value', | |
[ | |
'string', | |
'"02/02/2002"' | |
] | |
] | |
] | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'School' | |
], | |
[ | |
'value', | |
[ | |
'string', | |
'"East High"' | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'Address' | |
], | |
[ | |
'value', | |
[ | |
'pairs', | |
[ | |
'pair', | |
[ | |
'name', | |
'Str1' | |
], | |
[ | |
'value', | |
[ | |
'string', | |
'"001 40nd St."' | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'Zip' | |
], | |
[ | |
'value', | |
[ | |
'number', | |
'12346' | |
] | |
] | |
] | |
] | |
] | |
], | |
[ | |
'pair', | |
[ | |
'name', | |
'Club' | |
], | |
[ | |
'value', | |
[ | |
'string', | |
'"Football"' | |
] | |
] | |
] | |
] | |
] | |
] | |
] |
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
use 5.010; | |
use strict; | |
use warnings; | |
use Data::Dumper; | |
$Data::Dumper::Indent = 1; | |
$Data::Dumper::Terse = 1; | |
$Data::Dumper::Deepcopy = 1; | |
use Marpa::R2; | |
my $g = Marpa::R2::Scanless::G->new( { source => \(<<'END_OF_SOURCE'), | |
:default ::= action => [ name, value] | |
lexeme default = action => [ name, value] latm => 1 | |
pairs ::= pair+ | |
pair ::= name ('=') value (';') | |
name ~ [\w\.]+ | |
value ::= ('{') pairs ('}') | |
value ::= number | |
value ::= string | |
number ~ [\d]+ | |
string ~ quote in_string quote | |
quote ~ ["] | |
in_string ~ in_string_char* | |
in_string_char ~ [^"] | '\"' | |
:discard ~ whitespace | |
whitespace ~ [\s]+ | |
END_OF_SOURCE | |
} ); | |
my $input = <<EOI; | |
Student = { | |
PInfo = { | |
ID = 0001; | |
Name.First = "Joe"; | |
Name.Last = "Burger"; | |
DOB = "01/01/2000"; | |
}; | |
School = "West High"; | |
Address = { | |
Str1 = "001 Main St."; | |
Zip = 12345; | |
}; | |
}; | |
Student = { | |
PInfo = { | |
ID = 0002; | |
Name.First = "John"; | |
Name.Last = "Smith"; | |
DOB = "02/02/2002"; | |
}; | |
School = "East High"; | |
Address = { | |
Str1 = "001 40nd St."; | |
Zip = 12346; | |
}; | |
Club = "Football"; | |
}; | |
EOI | |
say Dumper $g->parse( \$input ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment