commit d98b5711eb943d09e6ed701d1d6d006bbf2d0205 from: Sergey Bronnikov date: Thu Dec 24 16:11:35 2020 UTC Add grammar for iso-8601 commit - 83c53863507492a17cf4080a743b1950959bb46d commit + d98b5711eb943d09e6ed701d1d6d006bbf2d0205 blob - 058f177ca337d42ca5a27ff0374f9d56ca096af7 blob + 425fb146da64d53bc2af9e49b54e2a757fcf80b4 --- README.md +++ README.md @@ -7,6 +7,7 @@ Grammars suitable for [lark](https://github.com/lark-p - [bc](https://man.openbsd.org/bc), an arbitrary precision calculator language (```bc.lark```) - [The GEDCOM Standard](http://user.it.uu.se/~andersa/gedcom/) (```gedcom.lark```) - [eqn](https://man.openbsd.org/eqn), language reference for mandoc (```eqn.lark```) +- [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html), Date and time format ```iso-8601.lark```) - [mdoc](https://man.openbsd.org/mdoc.7), semantic markup language for formatting manual pages (```mdoc.lark```) - MIME [Media Types](https://www.iana.org/assignments/media-types/media-types.xhtml) (```mime.lark```) - Lua 5.1 language grammar specification (```lua.lark```) blob - /dev/null blob + 635836f9d075a5b283771731b159750d7064acba (mode 644) --- /dev/null +++ lark_grammars/grammars/iso-8601.lark @@ -0,0 +1,51 @@ +DIGIT : "0".."9" +NOZERO : "1".."9" +NUMBER : NOZERO?DIGIT+ + +start : datetime + +year : DIGIT DIGIT DIGIT DIGIT +month : "0" "1".."9" + | "1" "1".."2" +day : "0" DIGIT + | "1" DIGIT + | "2" DIGIT + | "3" "0".."1" + +// Dates +calendar_date : year "-"? month "-"? day + | year "-" month + | "--" month "-"? day + +week_number : "0".."4" DIGIT + | "5" "0".."3" +prefixed_week_number : "W" week_number +weekday_number : "1".."7" +week_date : year "-"? prefixed_week_number + | year "-"? prefixed_week_number "-"? weekday_number + +day_number : "1".."2" DIGIT DIGIT + | "3" "0".."5" DIGIT + | "3" "6" "0".."6" // leap day +ordinal_date : year "-"? day_number + +date : ordinal_date + | calendar_date + | week_date + +// Time primitives +hour : "0".."1" DIGIT + | "2" "0".."4" +minute : "0".."5" DIGIT +second : "0".."5" DIGIT + | "60" // leap second +fractional : "." DIGIT+ + +// Time +time : "T"? hour ":"? minute ":"? second fractional? +prefixed_time: "T" hour ":"? minute ":"? second fractional? +time_zone : "Z" + | ("+"|"-") hour (":"? minute) + +// Combined +datetime : date prefixed_time time_zone? blob - 5278687883a81236eada5f31c335547d046038ff blob + 010b05a5911519356806008131bbcc8ae4284f91 --- lark_grammars/grammars.py +++ lark_grammars/grammars.py @@ -22,6 +22,7 @@ def _build_path(name): grammar_files = {'bc': _build_path('bc.lark'), 'gedcom': _build_path('gedcom.lark'), 'eqn': _build_path('eqn.lark'), + 'iso-8601': _build_path('iso-8601.lark'), 'lua': _build_path('lua.lark'), 'mdoc': _build_path('mdoc.lark'), 'mime': _build_path('mime.lark'),