magelang


Namemagelang JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryA lexer/parser generator for a growing number of languages
upload_time2024-02-23 12:33:06
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords text-analysis scanner lexer parser code-generator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Mage: Text Analysis Made Easy
=============================

Mage is tool for performing text analysis. It does so by generating a _lexer_,
_parser_ and _parse tree_ for you. Whether it is a piece of programming code or
some tabular data in a fringe format, Mage has got you covered!

 - 🚀 Full support for Python typings. Avoid runtime errors while building your language!
 - ➕ Add your own languages through the use of a powerful template engine!

👀 Mage is written in itself. Check out the [generated code][1] of our Python generator!

Here is the status of the various languages supported by Mage:

**Python**

| Name   | Description | Status |
|--------|-------------|--------|
| CST    | Create a parse tree from a grammar | ✅ |
| AST    | Create an AST that is derived from a CST | ⏳ |
| Lexer  | Create a fully functioning lexer from a grammar | ⏳ |
| Parser | Create a fully functioning parser from a grammmar | ⏳ |

[1]: https://github.com/samvv/mage/blob/main/src/magelang/lang/python/cst.py

## Installation

```
$ pip3 install --user -U magelang
```

## Usage

### `mage generate <filename>`

Generate a parser for the given grammar in a language that you specify.

**Example**
```
mage generate foo.mage python --prefix foo --out-dir src/foolang
```

### `mage test <filename..>`

**🚧 This command is under construction.**

Run all tests inside the documentation of the given grammar.

## Grammar

### `pub <name> = <expr>`

Define a new node or token that must be parsed according the given expression.

You can use both inline rules and other node rules inside `expr`. When
referring to another node, that node will become a field in the node that
referred to it. Nodes that have no fields are converted to a special token type
that is more efficient to represent.

```
pub var_decl = 'var' name:ident '=' type_expr
```

### `<name> = <expr>`

Define a new inline rule that can be used inside other rules.

As the name suggests, this type of rule is merely syntactic sugar and gets
inlined whenever it is referred to inside another rule.

```
digits = [0-9]+
```

### `extern <name>`

Defines a new parsing rule that is defined somewhere else, possibly in a different language.

### `extern token <name>`

Defines a new lexing rule that is defined somewhere else, possibly in a different language.

### `pub token <name> = <expr>`

Like `pub <name> = <expr>` but forces the rule to be a token.

Mage will show an error when the rule could not be converted to a token rule.
This usually means that the rule references another rule that is `pub`.

```
pub token float_expression
  = digits? '.' digits
```

### `expr1 expr2`

First parse `expr1` and continue to parse `expr2` immediately after it.

```
pub two_column_csv_line
  = text ',' text '\n'
```

### `expr1 | expr2`

First try to parse `expr1`. If that fails, try to parse `expr2`. If none of the
expressions matched, the parser fails.

```
pub declaration
  = function_declaration
  | let_declaration
  | const_declaration
```

### `expr?`

Parse or skip the given expression, depending on whether the expression can be
parsed.

```
pub singleton_or_pair
  = value (',' value)?
```

### `expr*`

Parse the given expression as much as possible.

```
skip = (multiline_comment | whitespace)*
```

### `expr+`

Parse the given expression one or more times.

For example, in Python, there must always be at least one statement in the body of a class or function:

```
body = stmt+
```

### `\expr`

Escape an expression by making it hidden. The expression will be parsed, but
not be visible in the resulting CST/AST.

### `expr{n,m}`

Parse the expression at least `n` times and at most `m` times.

```
unicode_char = 'U+' hex_digit{4,4}
```

## Contributing

Run the following command in a terminal to link the `mage` command to your checkout:

```
pip3 install -e '.[dev]'
```

## License

This code is generously licensed under the MIT license.


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "magelang",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Sam Vervaeck <samvv@pm.me>",
    "keywords": "text-analysis,scanner,lexer,parser,code-generator",
    "author": "",
    "author_email": "Sam Vervaeck <samvv@pm.me>",
    "download_url": "https://files.pythonhosted.org/packages/8d/6e/44582fc2e12e53a384f1b5ec14b3d38fcdc6c9b68cf9e175de9057d17ae6/magelang-0.1.0.tar.gz",
    "platform": null,
    "description": "Mage: Text Analysis Made Easy\n=============================\n\nMage is tool for performing text analysis. It does so by generating a _lexer_,\n_parser_ and _parse tree_ for you. Whether it is a piece of programming code or\nsome tabular data in a fringe format, Mage has got you covered!\n\n - \ud83d\ude80 Full support for Python typings. Avoid runtime errors while building your language!\n - \u2795 Add your own languages through the use of a powerful template engine!\n\n\ud83d\udc40 Mage is written in itself. Check out the [generated code][1] of our Python generator!\n\nHere is the status of the various languages supported by Mage:\n\n**Python**\n\n| Name   | Description | Status |\n|--------|-------------|--------|\n| CST    | Create a parse tree from a grammar | \u2705 |\n| AST    | Create an AST that is derived from a CST | \u23f3 |\n| Lexer  | Create a fully functioning lexer from a grammar | \u23f3 |\n| Parser | Create a fully functioning parser from a grammmar | \u23f3 |\n\n[1]: https://github.com/samvv/mage/blob/main/src/magelang/lang/python/cst.py\n\n## Installation\n\n```\n$ pip3 install --user -U magelang\n```\n\n## Usage\n\n### `mage generate <filename>`\n\nGenerate a parser for the given grammar in a language that you specify.\n\n**Example**\n```\nmage generate foo.mage python --prefix foo --out-dir src/foolang\n```\n\n### `mage test <filename..>`\n\n**\ud83d\udea7 This command is under construction.**\n\nRun all tests inside the documentation of the given grammar.\n\n## Grammar\n\n### `pub <name> = <expr>`\n\nDefine a new node or token that must be parsed according the given expression.\n\nYou can use both inline rules and other node rules inside `expr`. When\nreferring to another node, that node will become a field in the node that\nreferred to it. Nodes that have no fields are converted to a special token type\nthat is more efficient to represent.\n\n```\npub var_decl = 'var' name:ident '=' type_expr\n```\n\n### `<name> = <expr>`\n\nDefine a new inline rule that can be used inside other rules.\n\nAs the name suggests, this type of rule is merely syntactic sugar and gets\ninlined whenever it is referred to inside another rule.\n\n```\ndigits = [0-9]+\n```\n\n### `extern <name>`\n\nDefines a new parsing rule that is defined somewhere else, possibly in a different language.\n\n### `extern token <name>`\n\nDefines a new lexing rule that is defined somewhere else, possibly in a different language.\n\n### `pub token <name> = <expr>`\n\nLike `pub <name> = <expr>` but forces the rule to be a token.\n\nMage will show an error when the rule could not be converted to a token rule.\nThis usually means that the rule references another rule that is `pub`.\n\n```\npub token float_expression\n  = digits? '.' digits\n```\n\n### `expr1 expr2`\n\nFirst parse `expr1` and continue to parse `expr2` immediately after it.\n\n```\npub two_column_csv_line\n  = text ',' text '\\n'\n```\n\n### `expr1 | expr2`\n\nFirst try to parse `expr1`. If that fails, try to parse `expr2`. If none of the\nexpressions matched, the parser fails.\n\n```\npub declaration\n  = function_declaration\n  | let_declaration\n  | const_declaration\n```\n\n### `expr?`\n\nParse or skip the given expression, depending on whether the expression can be\nparsed.\n\n```\npub singleton_or_pair\n  = value (',' value)?\n```\n\n### `expr*`\n\nParse the given expression as much as possible.\n\n```\nskip = (multiline_comment | whitespace)*\n```\n\n### `expr+`\n\nParse the given expression one or more times.\n\nFor example, in Python, there must always be at least one statement in the body of a class or function:\n\n```\nbody = stmt+\n```\n\n### `\\expr`\n\nEscape an expression by making it hidden. The expression will be parsed, but\nnot be visible in the resulting CST/AST.\n\n### `expr{n,m}`\n\nParse the expression at least `n` times and at most `m` times.\n\n```\nunicode_char = 'U+' hex_digit{4,4}\n```\n\n## Contributing\n\nRun the following command in a terminal to link the `mage` command to your checkout:\n\n```\npip3 install -e '.[dev]'\n```\n\n## License\n\nThis code is generously licensed under the MIT license.\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A lexer/parser generator for a growing number of languages",
    "version": "0.1.0",
    "project_urls": {
        "Bug Reports": "https://github.com/samvv/mage/issues",
        "Homepage": "https://github.com/samvv/mage",
        "Source": "https://github.com/samvv/mage/"
    },
    "split_keywords": [
        "text-analysis",
        "scanner",
        "lexer",
        "parser",
        "code-generator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e030c47b451411545f1d475e0dc6c14b52c564410ad8a26c0789c80ee2e95316",
                "md5": "79e02ee3b299bee0ceeab5bee0811044",
                "sha256": "5f025dba362ec0d244c230efa0e793496f6d05307cad8220cbe38f79eed73cdf"
            },
            "downloads": -1,
            "filename": "magelang-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "79e02ee3b299bee0ceeab5bee0811044",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 22886,
            "upload_time": "2024-02-23T12:33:03",
            "upload_time_iso_8601": "2024-02-23T12:33:03.620453Z",
            "url": "https://files.pythonhosted.org/packages/e0/30/c47b451411545f1d475e0dc6c14b52c564410ad8a26c0789c80ee2e95316/magelang-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8d6e44582fc2e12e53a384f1b5ec14b3d38fcdc6c9b68cf9e175de9057d17ae6",
                "md5": "d67d3bbc12f6aa8e0222c22c8ddb92c3",
                "sha256": "1849ee473f4084a939d9106a994c4d3ee2a8158fda7daf7523941e02b077c02e"
            },
            "downloads": -1,
            "filename": "magelang-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d67d3bbc12f6aa8e0222c22c8ddb92c3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 24210,
            "upload_time": "2024-02-23T12:33:06",
            "upload_time_iso_8601": "2024-02-23T12:33:06.861100Z",
            "url": "https://files.pythonhosted.org/packages/8d/6e/44582fc2e12e53a384f1b5ec14b3d38fcdc6c9b68cf9e175de9057d17ae6/magelang-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-23 12:33:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "samvv",
    "github_project": "mage",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "magelang"
}
        
Elapsed time: 0.19009s