parcom - Parser Combinators parcom is a consise Parser Combinator library in the style of Haskell’s parsec and Rust’s nom . ( in-package :parcom ) (parse (*> ( string " Tempus " ) #' space ( string " fugit " )) " Tempus fugit. " ) fugit parcom operates strictly on strings, not streamed byte data, but is otherwise “zero copy” in that extracted substrings of the original input are not reallocated. parcom has no dependencies. Table of Contents Compatibility Compiler Status SBCL ✅ ECL ✅ Clasp ❓ ABCL ✅ CCL ✅ Clisp ✅ Allegro ✅ LispWorks ❓ API The examples below use (in-package :parcom) for brevity, but it’s assumed that you’ll use a local nickname like pc in your actual code. Further, most examples run the parsers with parse , but occasionally funcall is used instead to demonstrate what the remaining input would be after the parse succeeded. You will generally be using parse in your own code. Types and Running Parsers All parsers have the function signature string -> parser , where parser is a struct that holds the value of the parsing success alongside the remaining input string. ( in-package :parcom ) ( funcall ( string " Hello " ) " Hello there " ) #S(PARSER :INPUT " there" :VALUE "Hello") Of course, a parser might fail, in which case a failure struct is returned: ( in-package :parcom ) ( funcall ( string " Hello " ) " Bye! " ) #S(FAILURE :EXPECTED "string: Hello" :ACTUAL "string: Bye!") In general though we call parse to fully run some combined parsers and yield the final output: ( in-package :parcom ) ( apply #' + (parse (sep ( char #\. ) #' unsigned) " 123.456.789! " )) 1368 parse otherwise ignores any final, unconsumed input. It will also raise a Condition if the parsing failed. Parsers A “parser” is a function that consumes some specific input and yields a single result. Characters and Strings char Parse a given character. ( in-package :parcom ) (parse ( char #\a ) " apple " ) #\a string Parse the given string. ( in-package :parcom ) (parse ( string " Hello " ) " ...
First seen: 2025-04-22 18:42
Last seen: 2025-04-22 20:42