Skip to content

Instantly share code, notes, and snippets.

@jasonmay
Created December 29, 2010 23:48
Show Gist options
  • Save jasonmay/759236 to your computer and use it in GitHub Desktop.
Save jasonmay/759236 to your computer and use it in GitHub Desktop.
my $parser = qr{
<logfile:debug.log>
# <debug:run>
(
<.ZoneDirective>?
<[ZoneData]>*
<Zone>?
)+
############################################
############################################
############################################
<token: eol>
\n
<token: ws>
\s*
<rule: ZoneDirective>
%zone: <ZoneName=Word>
<rule: ZoneData>
%<zone_key=ZoneFields> : <zone_value=Word>
<token: ZoneFields>
rainfall | latitude
<rule: Zone>
(?: <Mobiles> | <Objects> | <Locations> )+
<rule: Mobiles>
%(?i:mobiles)
<[Mobile]>+
<rule: Objects>
%(?i:objects)
<[Object]>+
<rule: Locations>
%(?i:locations)
<[Location]>+
# MOBILES
#################################################
<rule: Mobile>
<[Statement]>+
[Ee]nd = <StmtValue>
<rule: Statement>
<key=Keyword> =? (?: <value=StmtValue> | <value=Flag> )
<token: Keyword>
(?![Ee]nd)<.Word>
<token: StmtValue>
<.Number> | <.FullLocID> | <.Word> | <Quoted>
<token: Flag>
\{<.ws>?<[FlagItem]>*<.ws>?\}
<token: FlagItem>
<Word> <.ws>?
<token: Word>
[\w\[\]]+
<token: Quoted>
<ApostropheString> | <QuoteString> | <CaretString>
<token: ApostropheString>
' <Inside=ApostropheInside> '
<token: ApostropheInside>
(?: <.escape> | <.NonApostrophe> )*
<token: NonApostrophe>
[^']
<token: QuoteString>
" <Inside=QuoteInside> "
<token: QuoteInside>
(?: <.escape> | <.NonQuote> )*
<token: NonQuote>
[^"]
<token: CaretString>
\^ <Inside=CaretInside> \^
<token: CaretInside>
(?: <.escape> | <.NonCaret>)*
<token: NonCaret>
[^^]+
<token: escape>
\\ .
# OBJECTS
#################################################
<rule: Object>
<[ObjectStatement]>+
[Ee]nd = <StmtValue>
<rule: ObjectStatement>
<key=Keyword> =? (?: <value=ObjectStmtValue> | <value=Flag> )
<token: ObjectStmtValue>
<.Number> | <.ObjectLocation> | <.Word> | <Quoted>
<token: ObjectLocation>
(?: <.LocationOptions> : )? <.FullLocID>
<token: ObjectID>
<.Word> (?: @ <.Word> )?
<token: LocationOptions>
IN_ROOM | CARRIED_BY | WIELDED_BY | WORN_BY | BOTH_BY | IN_CONTAINER
# LOCATIONS
#################################################
<rule: Location>
<Map>
<AltitudeLine>?
<LocFlags>
<LocTitle> <LocDescription>
<rule: Map>
<LocID> <[Exit]>* ;
<rule: AltitudeLine>
Altitude = <alt=Number>
<rule: LocFlags>
(?i:lflags?) <lflags=Flag>
<rule: Exit>
<ExitLetter> : (?: <exit_dest=Door> | <exit_dest=FullLocID> )
<token: ExitLetter>
[nsewudNSEWUD]
<token: LocID>
<.Word>
<token: FullLocID>
(?: <.Word> @ )? <.LocID>
<token: Door>
\^ <.ObjectID>
<rule: LocTitle>
<.NonCaret>
<rule: LocDescription>
<CaretString>
<token: Number>
[-\d]+
}xs;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment