Last active
October 11, 2015 08:08
-
-
Save phred/3828935 to your computer and use it in GitHub Desktop.
EBNF for FoxyCart discount strings
This file contains hidden or 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: peg.ebnf | |
#! throw this in the listener to see the example parse tree | |
"discount_quantity_amount=Discount_Name{repeat|1-5.42|2-5|6-0}" | |
[EBNF | |
number = [0-9]+ => [[ string>number ]] | |
amount = number ("." number)? | |
type = "allunits" | "incremental" | "repeat" | "single" | |
tier = number "-" amount | |
method = "discount" "_" ("quantity" | "price") "_" ("amount" | "percentage") | |
name = [A-Za-z0-9_ ]+ => [[ >string ]] | |
discount = method "=" name "{" type "|" tier ( "|" tier )+ "}" | |
EBNF] | |
#! example parse tree | |
V{ | |
V{ "discount" "_" "quantity" "_" "amount" } | |
"=" | |
"Discount_Name" | |
"{" | |
"repeat" | |
"|" | |
V{ 1 "-" V{ 5 V{ "." 42 } } } | |
V{ | |
V{ "|" V{ 2 "-" V{ 5 f } } } | |
V{ "|" V{ 6 "-" V{ 0 f } } } | |
} | |
"}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment