{"id":9123,"library":"mo-parsing","title":"mo-parsing","description":"mo-parsing is a Python PEG (Parsing Expression Grammar) parsing tool. It is a fork of `pyparsing`, designed for faster parsing, and allows users to define parsers using predefined patterns and Python operators. The library is currently at version 8.694.25301, with its latest release uploaded on October 27, 2025 (likely 2024, indicating active development with frequent updates).","status":"active","version":"8.694.25301","language":"en","source_language":"en","source_url":"https://github.com/klahnakoski/mo-parsing","tags":["parsing","PEG","parser generator","text processing","pyparsing fork"],"install":[{"cmd":"pip install mo-parsing","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"Word","correct":"from mo_parsing import Word"},{"symbol":"Literal","correct":"from mo_parsing import Literal"},{"symbol":"Keyword","correct":"from mo_parsing import Keyword"},{"symbol":"Group","correct":"from mo_parsing import Group"},{"symbol":"Regex","correct":"from mo_parsing import Regex"},{"symbol":"alphas","correct":"from mo_parsing.utils import alphas"},{"note":"Whitespace context manager is in its own submodule.","wrong":"from mo_parsing import Whitespace","symbol":"Whitespace","correct":"from mo_parsing.whitespaces import Whitespace"}],"quickstart":{"code":"from mo_parsing import Word, Literal\nfrom mo_parsing.utils import alphas\nfrom mo_parsing.whitespaces import Whitespace\n\n# Define a simple grammar for 'Hello, World!' with a custom whitespace rule\nwith Whitespace(' \\t') as whitespace_context:\n    greet = Word(alphas)('greeting') + Literal(',') + Word(alphas)('person') + Literal('!')\n\n    # Parse a string\n    result = greet.parse_string('Hello, World!')\n\n    # Access results as a list\n    print(f\"List view: {list(result)}\")\n    # Access results as a dictionary (for named tokens)\n    print(f\"Dict view: {dict(result)}\")\n\n    # Example with different input\n    result_named = greet.parse_string('Hi, There!')\n    print(f\"Named tokens: {result_named.greeting}, {result_named.person}\")","lang":"python","description":"This quickstart demonstrates defining a simple grammar using `Word` and `Literal`, managing whitespace with `Whitespace` context, and parsing a string. It shows how to access the parsed results as both a list and a dictionary."},"warnings":[{"fix":"Always reassign the result of methods that modify ParserElements: `my_parser = my_parser.add_parse_action(my_action)`","message":"ParserElements are static. Methods like `.add_parse_action(action)` create and return a *new* ParserElement. If the result is not assigned back to a variable, the parse action (or any other modification) will be lost.","severity":"breaking","affected_versions":"All versions (since fork from pyparsing)"},{"fix":"Use the `with Whitespace(...) as context:` block or `Whitespace().use()` for language definition.","message":"Whitespace handling has been refactored. `mo-parsing` uses the `mo_parsing.whitespaces.Whitespace` context manager to define ignored characters, replacing `pyparsing`'s global `whitespace_chars` or `parser.set_whitespace_chars()` methods, which are removed.","severity":"breaking","affected_versions":"All versions (since fork from pyparsing)"},{"fix":"Adjust your parse action signatures to `def my_action(tokens, loc, string):` or `lambda t, l, s: ...`","message":"The parameter order for parse actions is `(tokens, index, string)`, which is the opposite of `pyparsing`'s `(string, location, tokens)`.","severity":"gotcha","affected_versions":"All versions (since fork from pyparsing)"},{"fix":"Use `Literal('exact string')` for a fixed string match, or `Keyword('exact word')` for a fixed string that must be a whole word (with word boundaries).","message":"Do not confuse `Word()`, `Literal()`, and `Keyword()` for exact string matching. `Word(string_of_characters)` matches any contiguous sequence of *characters found within* `string_of_characters`, not the exact `string_of_characters` itself.","severity":"gotcha","affected_versions":"All versions (inherited from pyparsing behavior)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Remember that `ParserElement` methods like `add_parse_action` return a *new* ParserElement object. Always assign the result back to the variable: `my_parser = my_parser.add_parse_action(my_func)`.","cause":"You likely applied a parse action to a ParserElement without reassigning the result, e.g., `some_parser.add_parse_action(my_func)` instead of `some_parser = some_parser.add_parse_action(my_func)`.","error":"TypeError: 'NoneType' object is not callable (when a parse action doesn't seem to run)"},{"fix":"If you need to match a specific string exactly, use `Literal('your_string')`. If it must be a whole word, use `Keyword('your_word')`.","cause":"A common cause is misusing `Word(chars)` where `Literal(exact_string)` or `Keyword(exact_word)` was intended. `Word('abc')` will match 'apple', 'banana', 'cat' because 'a', 'b', 'c' are in its character set, not just 'abc'.","error":"mo_parsing.exceptions.ParseException: Expected 'something_else' (when parser consumes too much or wrong input)"},{"fix":"For phrases with spaces that should allow for arbitrary whitespace (and comments if configured), split them into separate `Literal` or `Keyword` elements: `Literal('first') + Literal('second')`.","cause":"Using `Literal('multiple words')` will attempt to match the entire string literally, including spaces, without allowing for intervening whitespace skipping behavior.","error":"mo_parsing.exceptions.ParseException: Expected ... (when trying to match a literal phrase with spaces)"}]}