{"id":17495666,"url":"https://github.com/iraikov/chicken-abnf","last_synced_at":"2026-01-05T15:48:16.972Z","repository":{"id":148366411,"uuid":"148261399","full_name":"iraikov/chicken-abnf","owner":"iraikov","description":"Parser combinators for Augmented BNF grammars (RFC 4234)","archived":false,"fork":false,"pushed_at":"2021-10-07T18:39:11.000Z","size":28,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-19T17:47:06.247Z","etag":null,"topics":["abnf","augmented-bnf-grammars","chicken-scheme","chicken-scheme-eggs","parsing","parsing-combinators","scheme","scheme-language","scheme-programming-language"],"latest_commit_sha":null,"homepage":null,"language":"Scheme","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iraikov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-11T04:43:54.000Z","updated_at":"2023-10-01T03:50:45.000Z","dependencies_parsed_at":"2023-05-19T21:30:47.996Z","dependency_job_id":null,"html_url":"https://github.com/iraikov/chicken-abnf","commit_stats":{"total_commits":17,"total_committers":3,"mean_commits":5.666666666666667,"dds":"0.11764705882352944","last_synced_commit":"fc596b5da79c5378b746440c9b1f067670740378"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iraikov%2Fchicken-abnf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iraikov%2Fchicken-abnf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iraikov%2Fchicken-abnf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iraikov%2Fchicken-abnf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iraikov","download_url":"https://codeload.github.com/iraikov/chicken-abnf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245525818,"owners_count":20629832,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abnf","augmented-bnf-grammars","chicken-scheme","chicken-scheme-eggs","parsing","parsing-combinators","scheme","scheme-language","scheme-programming-language"],"created_at":"2024-10-19T14:18:24.178Z","updated_at":"2026-01-05T15:48:16.919Z","avatar_url":"https://github.com/iraikov.png","language":"Scheme","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chicken-abnf\nParser combinators for Augmented BNF grammars (RFC 4234)\n\n## Documentation\n\nThe `abnf` library provides a collection of combinators to help constructing parsers\nfor Augmented Backus-Naur form (ABNF) grammars\n[RFC 4234](http://www.ietf.org/rfc/rfc4234.txt).\n\n## Library Procedures\n\nThe combinator procedures in this library are based on the interface\nprovided by the [lexgen](https://github.com/iraikov/chicken-lexgen) library.\n\n### Terminal values and core rules \n\n\u003cprocedure\u003e(char CHAR) =\u003e MATCHER\u003c/procedure\u003e\n\nProcedure `char` builds a pattern matcher function that matches a\nsingle character.\n\n\u003cprocedure\u003e(lit STRING) =\u003e MATCHER\u003c/procedure\u003e\n\n`lit` matches a literal string (case-insensitive).\n\nThe following primitive parsers match the rules described in RFC 4234, Section 6.1.\n\n\u003cprocedure\u003e(alpha STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches any character of the alphabet.\n\n\u003cprocedure\u003e(binary STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches [0..1].\n\n\u003cprocedure\u003e(decimal STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches [0..9].\n\n\u003cprocedure\u003e(hexadecimal STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches [0..9] and [A..F,a..f].\n\n\u003cprocedure\u003e(ascii-char STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches any 7-bit US-ASCII character except for NUL (ASCII value 0).\n\n\u003cprocedure\u003e(cr STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches the carriage return character.\n\n\u003cprocedure\u003e(lf STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches the line feed character.\n\n\u003cprocedure\u003e(crlf STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches the Internet newline.\n\n\u003cprocedure\u003e(ctl STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches any US-ASCII control character. That is, any character with a\ndecimal value in the range of [0..31,127].\n\n\u003cprocedure\u003e(dquote STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches the double quote character.\n\n\u003cprocedure\u003e(htab STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches the tab character.\n\n\u003cprocedure\u003e(lwsp STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches linear white-space. That is, any number of consecutive\n`wsp`, optionally followed by a `crlf` and (at least) one more\n`wsp`.\n\n\u003cprocedure\u003e(sp STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches the space character.\n\n\u003cprocedure\u003e(vspace STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches any printable ASCII character.  That is, any character in the\ndecimal range of [33..126].\n\n\u003cprocedure\u003e(wsp STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches space or tab.\n\n\u003cprocedure\u003e(quoted-pair STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches a quoted pair. Any characters (excluding CR and LF) may be\nquoted.\n\n\u003cprocedure\u003e(quoted-string STREAM-LIST) =\u003e STREAM-LIST\u003c/procedure\u003e\n\nMatches a quoted string. The slash and double quote characters must be\nescaped inside a quoted string; CR and LF are not allowed at all.\n\nThe following additional procedures are provided for convenience:\n\n\u003cprocedure\u003e(set CHAR-SET) =\u003e MATCHER\u003c/procedure\u003e\n\nMatches any character from an SRFI-14 character set.\n\n\u003cprocedure\u003e(set-from-string STRING) =\u003e MATCHER\u003c/procedure\u003e\n\nMatches any character from a set defined as a string.\n\n\n### Operators\n\n\u003cprocedure\u003e(concatenation MATCHER-LIST) =\u003e MATCHER\u003c/procedure\u003e\n\n`concatenation` matches an ordered list of rules. (RFC 4234, Section 3.1)\n\n\n\u003cprocedure\u003e(alternatives MATCHER-LIST) =\u003e MATCHER\u003c/procedure\u003e\n\n`alternatives` matches any one of the given list of rules. (RFC 4234, Section 3.2)\n\n\u003cprocedure\u003e(range C1 C2) =\u003e MATCHER\u003c/procedure\u003e\n\n`range` matches a range of characters. (RFC 4234, Section 3.4)\n\n\u003cprocedure\u003e(variable-repetition MIN MAX MATCHER) =\u003e MATCHER\u003c/procedure\u003e\n\n`variable-repetition` matches between `MIN` and `MAX` or more consecutive\nelements that match the given rule. (RFC 4234, Section 3.6)\n\n\u003cprocedure\u003e(repetition MATCHER) =\u003e MATCHER\u003c/procedure\u003e\n\n`repetition` matches zero or more consecutive elements that match the given rule. \n\n\u003cprocedure\u003e(repetition1 MATCHER) =\u003e MATCHER\u003c/procedure\u003e\n\n`repetition1` matches one or more consecutive elements that match the given rule. \n\n\u003cprocedure\u003e(repetition-n N MATCHER) =\u003e MATCHER\u003c/procedure\u003e\n\n`repetition-n` matches exactly `N` consecutive occurences of the given rule. (RFC 4234, Section 3.7)\n\n\n\u003cprocedure\u003e(optional-sequence MATCHER) =\u003e MATCHER\u003c/procedure\u003e\n\n`optional-sequence` matches the given optional rule. (RFC 4234, Section 3.8)\n\n\u003cprocedure\u003e(pass) =\u003e MATCHER\u003c/procedure\u003e\n\nThis matcher returns without consuming any input.\n\n\u003cprocedure\u003e(bind F P) =\u003e MATCHER\u003c/procedure\u003e\n\nGiven a rule `P` and function `F`, returns a matcher that first\napplies `P` to the input stream, then applies `F` to the returned\nlist of consumed tokens, and returns the result and the remainder of\nthe input stream.\n\nNote: this combinator will signal failure if the input stream is\nempty.\n\n\u003cprocedure\u003e(bind* F P) =\u003e MATCHER\u003c/procedure\u003e\n\nThe same as `bind`, but will signal success if the input stream is\nempty.\n\n\u003cprocedure\u003e(drop-consumed P) =\u003e MATCHER\u003c/procedure\u003e\n\nGiven a rule `P`, returns a matcher that always returns an empty\nlist of consumed tokens when `P` succeeds. \n\n### Abbreviated syntax\n\n`abnf` supports the following abbreviations for commonly used combinators:\n\n; `::` : `concatenation`\n; `:?` : `optional-sequence`\n; `:!` : `drop-consumed`\n; `:s` : `lit`\n; `:c` : `char`\n; `:*` : `repetition`\n; `:+` : `repetition1`\n\n\n## Examples\n\nThe following parser libraries have been implemented with `abnf`, in\norder of complexity:\n\n* csv\n* internet-timestamp\n* json-abnf\n* mbox\n* smtp\n* internet-message\n* mime\n\n### Parsing date and time\n\n```scheme\n\n(import abnf)\n\n(define fws\n  (concatenation\n   (optional-sequence \n    (concatenation\n     (repetition wsp)\n     (drop-consumed \n      (alternatives crlf lf cr))))\n   (repetition1 wsp)))\n\n(define (between-fws p)\n  (concatenation\n   (drop-consumed (optional-sequence fws)) p \n   (drop-consumed (optional-sequence fws))))\n\n;; Date and Time Specification from RFC 5322 (Internet Message Format)\n\n;; The following abnf parser combinators parse a date and time\n;; specification of the form\n;;\n;;   Thu, 19 Dec 2002 20:35:46 +0200\n;;\n; where the weekday specification is optional. \n\t\t\t     \n;; Match the abbreviated weekday names\n\n(define day-name \n  (alternatives\n   (lit \"Mon\")\n   (lit \"Tue\")\n   (lit \"Wed\")\n   (lit \"Thu\")\n   (lit \"Fri\")\n   (lit \"Sat\")\n   (lit \"Sun\")))\n\n;; Match a day-name, optionally wrapped in folding whitespace\n\n(define day-of-week (between-fws day-name))\n\n\n;; Match a four digit decimal number\n\n(define year (between-fws (repetition-n 4 decimal)))\n\n;; Match the abbreviated month names\n\n(define month-name (alternatives\n\t\t    (lit \"Jan\")\n\t\t    (lit \"Feb\")\n\t\t    (lit \"Mar\")\n\t\t    (lit \"Apr\")\n\t\t    (lit \"May\")\n\t\t    (lit \"Jun\")\n\t\t    (lit \"Jul\")\n\t\t    (lit \"Aug\")\n\t\t    (lit \"Sep\")\n\t\t    (lit \"Oct\")\n\t\t    (lit \"Nov\")\n\t\t    (lit \"Dec\")))\n\n;; Match a month-name, optionally wrapped in folding whitespace\n\n(define month (between-fws month-name))\n\n\n;; Match a one or two digit number\n\n(define day (concatenation\n\t     (drop-consumed (optional-sequence fws))\n\t     (alternatives \n\t      (variable-repetition 1 2 decimal)\n\t      (drop-consumed fws))))\n\n;; Match a date of the form dd:mm:yyyy\n(define date (concatenation day month year))\n\n;; Match a two-digit number \n\n(define hour      (repetition-n 2 decimal))\n(define minute    (repetition-n 2 decimal))\n(define isecond   (repetition-n 2 decimal))\n\n;; Match a time-of-day specification of hh:mm or hh:mm:ss.\n\n(define time-of-day (concatenation\n\t\t     hour (drop-consumed (char #\\:))\n\t\t     minute (optional-sequence \n\t\t\t     (concatenation (drop-consumed (char #\\:))\n \t\t\t\t\t isecond))))\n\n;; Match a timezone specification of the form\n;; +hhmm or -hhmm \n\n(define zone (concatenation \n\t      (drop-consumed fws)\n\t      (alternatives (char #\\-) (char #\\+))\n\t      hour minute))\n\n;; Match a time-of-day specification followed by a zone.\n\n(define itime (concatenation time-of-day zone))\n\n(define date-time (concatenation\n\t\t   (optional-sequence\n\t\t    (concatenation\n\t\t     day-of-week\n\t\t     (drop-consumed (char #\\,))))\n\t\t   date\n\t\t   itime\n\t\t   (drop-consumed (optional-sequence fws))))\n\n(define (err s)\n  (print \"lexical error on stream: \" s)\n  `(error))\n\n(print (lex date-time err \"Thu, 19 Dec 2002 20:35:46 +0200\"))\n\n```\n\n\n## Version History\n\n* 8.3 Removed unneeded dependency on yasos [thanks to Mario Domenech Goulart]\n* 8.0 Ported to CHICKEN 5 and yasos collections interface \n* 7.0 Added bind* variant of bind [thanks to Peter Bex]\n* 6.0 Using utf8 for char operations\n* 5.1 Improvements to the CharLex-\u003eCoreABNF constructor\n* 5.0 Synchronized with lexgen 5\n* 3.2 Removed invalid identifier :|\n* 3.0 Implemented typeclass interface\n* 2.9 Bug fix in consumed-objects (reported by Peter Bex)\n* 2.7 Added abbreviated syntax (suggested by Moritz Heidkamp)\n* 2.6 Bug fixes in consumer procedures\n* 2.5 Removed procedure memo\n* 2.4 Moved the definition of bind and drop to lexgen\n* 2.2 Added pass combinator\n* 2.1 Added procedure variable-repetition\n* 2.0 Updated to match the interface of lexgen 2.0\n* 1.3 Fix in drop\n* 1.2 Added procedures bind drop consume collect\n* 1.1 Added procedures set and set-from-string\n* 1.0 Initial release\n\n## License\n\n\u003e\n\u003e\n\u003e  Copyright 2009-2021 Ivan Raikov\n\u003e\n\u003e\n\u003e  This program is free software: you can redistribute it and/or\n\u003e  modify it under the terms of the GNU General Public License as\n\u003e  published by the Free Software Foundation, either version 3 of the\n\u003e  License, or (at your option) any later version.\n\u003e\n\u003e  This program is distributed in the hope that it will be useful, but\n\u003e  WITHOUT ANY WARRANTY; without even the implied warranty of\n\u003e  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n\u003e  General Public License for more details.\n\u003e\n\u003e  A full copy of the GPL license can be found at\n\u003e  \u003chttp://www.gnu.org/licenses/\u003e.\n\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firaikov%2Fchicken-abnf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Firaikov%2Fchicken-abnf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Firaikov%2Fchicken-abnf/lists"}