Created
July 18, 2011 23:21
-
-
Save adamsanderson/1090935 to your computer and use it in GitHub Desktop.
PEG for LiquidPlanner Ranged Estimate
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
// Just playing around... | |
// http://pegjs.majda.cz/online | |
start | |
= '[' _ est:estimate _ ']' { return est; } | |
/ est:estimate { return est; } | |
estimate | |
= low:duration _ '-' _ high:duration {return [low, high]} | |
/ fixed:duration { return [fixed, fixed]; } | |
duration | |
= n:number _ u:unit { return [n,u] } | |
/ n:number { return [n,'h'] } | |
unit | |
= [hdm] | |
number "number" | |
= int_:int frac:frac exp:exp _ { return parseFloat(int_ + frac + exp); } | |
/ int_:int frac:frac _ { return parseFloat(int_ + frac); } | |
/ int_:int exp:exp _ { return parseFloat(int_ + exp); } | |
/ int_:int _ { return parseFloat(int_); } | |
int | |
= digit19:digit19 digits:digits { return digit19 + digits; } | |
/ digit:digit | |
/ "-" digit19:digit19 digits:digits { return "-" + digit19 + digits; } | |
/ "-" digit:digit { return "-" + digit; } | |
frac | |
= "." digits:digits { return "." + digits; } | |
exp | |
= e:e digits:digits { return e + digits; } | |
digits | |
= digits:digit+ { return digits.join(""); } | |
e | |
= e:[eE] sign:[+-]? { return e + sign; } | |
/* | |
* The following rules are not present in the original JSON gramar, but they are | |
* assumed to exist implicitly. | |
* | |
* FIXME: Define them according to ECMA-262, 5th ed. | |
*/ | |
digit | |
= [0-9] | |
digit19 | |
= [1-9] | |
hexDigit | |
= [0-9a-fA-F] | |
/* ===== Whitespace ===== */ | |
_ "whitespace" | |
= whitespace* | |
// Whitespace is undefined in the original JSON grammar, so I assume a simple | |
// conventional definition consistent with ECMA-262, 5th ed. | |
whitespace | |
= [ \t\n\r] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment