{"id":4375,"library":"parsley","title":"Parsley","description":"Parsley is a Python parsing library designed to simplify parsing and pattern matching. It implements the Parsing Expression Grammar (PEG) algorithm, compiling grammar definitions into Python classes where rules become methods. This approach aims to make parsing expressions behave similarly to standard Python expressions. It is an implementation of OMeta, an object-oriented pattern-matching language. The current version is 1.3, released in 2017.","status":"abandoned","version":"1.3","language":"en","source_language":"en","source_url":"https://github.com/pyga/parsley","tags":["parsing","grammar","peg","parser-generator","ometa"],"install":[{"cmd":"pip install parsley","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"While 'from parsley import makeGrammar' works, the common pattern in examples is to import the whole 'parsley' module and then call 'parsley.makeGrammar'.","wrong":"from parsley import makeGrammar","symbol":"makeGrammar","correct":"import parsley\nparser_class = parsley.makeGrammar(grammar_source, bindings)"}],"quickstart":{"code":"import parsley\n\ngrammar_source = \"\"\"\n    integer = <digit+>:ds -> int(ds)\n    sum = integer:left '+' integer:right -> left + right\n    product = integer:left '*' integer:right -> left * right\n    expression = sum | product | integer\n\"\"\"\n\ncalculator_grammar = parsley.makeGrammar(grammar_source, {})\n\n# Parse a sum\nparser_sum = calculator_grammar(\"10+20\")\nresult_sum = parser_sum.sum()\nprint(f\"10+20 = {result_sum}\") # Expected: 30\n\n# Parse a product\nparser_product = calculator_grammar(\"5*6\")\nresult_product = parser_product.product()\nprint(f\"5*6 = {result_product}\") # Expected: 30\n\n# Parse a single integer\nparser_int = calculator_grammar(\"123\")\nresult_int = parser_int.integer()\nprint(f\"123 = {result_int}\") # Expected: 123","lang":"python","description":"This quickstart defines a simple grammar for basic arithmetic (addition, multiplication, and integers). It demonstrates how to create a grammar, instantiate a parser with input, and execute a rule to get the result. Note the use of `-> int(ds)` to convert matched digit strings to integers and `-> left + right` for performing calculations within the grammar itself."},"warnings":[{"fix":"Consider migrating to actively maintained parsing libraries such as `lark`, `pyparsing`, or `parsy` for projects requiring ongoing support and compatibility with modern Python environments.","message":"The Parsley project has seen no new releases since version 1.3 in April 2017, and its GitHub repository shows no recent activity. This indicates the project is effectively abandoned, meaning no new features, bug fixes, security updates, or official support for newer Python versions should be expected.","severity":"breaking","affected_versions":"All versions (due to lack of future maintenance)"},{"fix":"Always place more specific or 'longer' matching rules before more general or 'shorter' matching rules when using alternatives (`|`) to ensure the desired rule is matched first.","message":"Parsley's PEG (Parsing Expression Grammar) parser evaluates alternatives (`|`) strictly in order, unlike traditional LL/LR parsers (e.g., Yacc, PLY) which might use longest match or other lookahead strategies. This can lead to unexpected parsing results if the order of alternatives is not carefully considered, as an earlier, less specific rule might consume input that a later, more specific rule was intended to handle.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Thoroughly test Parsley-based parsers on your target Python 3.x environment. Be prepared to fix potential compatibility issues or consider alternatives for new projects.","message":"Although some community efforts (e.g., operating system packages) exist for Python 3 compatibility, the last official release of Parsley (v1.3 in 2017) pre-dates broad adoption and dedicated testing for recent Python 3.x versions. Users might encounter subtle compatibility issues, unaddressed bugs, or missing features when running Parsley on modern Python 3.8+ environments.","severity":"gotcha","affected_versions":"All versions, especially with Python 3.8+"},{"fix":"Explicitly manage list accumulation or aggregation within your Python actions. For example, collect intermediate results into a list and return the final list from a rule, or use helper functions bound to the grammar.","message":"When using repetition operators (`*` for zero or more, `+` for one or more) with rules that incorporate Python actions (`-> pythonExpression`) for transformation or aggregation, results from chained matches may overwrite previous results instead of accumulating into a list. Parsley does not automatically manage list accumulation in all such scenarios.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}