Skip to content

Instantly share code, notes, and snippets.

@librasteve
Created January 1, 2024 17:18
Show Gist options
  • Save librasteve/3fc8e23490702b8c1e12d863b4d260b2 to your computer and use it in GitHub Desktop.
Save librasteve/3fc8e23490702b8c1e12d863b4d260b2 to your computer and use it in GitHub Desktop.
GrammarConsumptionExample1
use Grammar::Tracer;
grammar Timestamp {
token TOP{^<y><m><d>T<hr><mn>$}
token y {\d**4}
token m {\d**2}
token d {\d**2}
token hr {\d**2}
token mn {\d**2}
}
#say Timestamp.parse: '20130304T0102';
grammar TimestampExp is Timestamp {
token tsx{<y><m><d>T<hr><mn>}
}
grammar TimestampedFile is TimestampExp {
token TOP{^<name> '-' <tsx> '.' <ext>$}
token name{<[a..z]>+}
token ext{<[a..z]>**3}
}
say TimestampedFile.parse: 'xxx-20130304T0102.csv';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment