PyDAXLexer


NamePyDAXLexer JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryPyDAX is designed to analyze DAX, it can extract comments, remove comments, and identify columns and measures referenced in DAX expressions.
upload_time2024-10-26 09:27:32
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements antlr4-python3-runtime
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyDAX

`PyDAX` is a package designed to analyze DAX expressions. It can extract comments, remove comments, and identify columns and measures referenced in DAX expressions.


## Installation

To install the package, use pip:

```bash
pip install PyDAXLexer
```
## Usage

Here's a how to use PyDAXLexer. This example shows how to create a DAXExpression object and extract information.

```python
from PyDAX import DAXExpression

if __name__ == '__main__':
    # DAX expression as string:
    dax_expression = """
    // Calculate average sales per customer, considering only active customers
    VAR SalesPerCustomer = 
        DIVIDE(
            SUM(Sales[TotalAmount]), 
            COUNTROWS(VALUES(Customers[CustomerID]))
        )
        
    // Calculate discount impact
    VAR DiscountImpact = 
        SUMX(
            FILTER(
                Sales,
                Sales[Discount] > 0
            ),
            Sales[DiscountAmount]
        )

    RETURN 
        IF(
            SalesPerCustomer > 500 && DiscountImpact < 1000,
            "High Value Customer",
            "Standard Customer"
        )
    """
    
    # Initialize the DAXExpression object
    expression = DAXExpression(dax_expression)
    
    # Access various properties
    print("Original Expression:", expression.dax_expression)
    print("Expression without Comments:", expression.dax_expression_no_comments)
    print("Table and Column References:", expression.table_column_references)
    print("Extracted Comments:", expression.comments)
    print("Cleaned Expression:", expression.clean_dax_expression)
    print("Contains Division Operator:", expression.contains_div)
```

## Additional Features

The DAXExpression class provides several utility methods:

- `remove_comments()`: Removes comments from the DAX expression.
- `extract_comments()`: Extracts all comments in the expression.
- `extract_artifact_references()`: Extracts table and column references.
- `generate_html(light: bool)`: Generates HTML output of the expression with syntax coloring.
- `save_html_to_file(file_name: str)`: Saves the syntax-colored HTML output to a file.

## License

This project is licensed under the MIT License.

## Acknowledgments

### TabularEditor

The lexer grammar used in this project is adapted from the TabularEditor GitHub repository.

- **Source**: [TabularEditor GitHub Repository](https://github.com/TabularEditor/TabularEditor/blob/master/AntlrGrammars/DAXLexer.g4)
- **License**: MIT License

### ANTLR

This project uses ANTLR (ANother Tool for Language Recognition) to generate the lexer and parser for DAX expressions. 

- **Project**: The ANTLR Project
- **License**: BSD-3-Clause License



            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "PyDAXLexer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Klaus J\u00fcrgen Folz <klausjurgenfolz@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/25/0b/1ed3976356585b2cbc63ea4e140014e72476c4fffe89b0cc15dcd7542a49/pydaxlexer-0.1.2.tar.gz",
    "platform": null,
    "description": "# PyDAX\n\n`PyDAX` is a package designed to analyze DAX expressions. It can extract comments, remove comments, and identify columns and measures referenced in DAX expressions.\n\n\n## Installation\n\nTo install the package, use pip:\n\n```bash\npip install PyDAXLexer\n```\n## Usage\n\nHere's a how to use PyDAXLexer. This example shows how to create a DAXExpression object and extract information.\n\n```python\nfrom PyDAX import DAXExpression\n\nif __name__ == '__main__':\n    # DAX expression as string:\n    dax_expression = \"\"\"\n    // Calculate average sales per customer, considering only active customers\n    VAR SalesPerCustomer = \n        DIVIDE(\n            SUM(Sales[TotalAmount]), \n            COUNTROWS(VALUES(Customers[CustomerID]))\n        )\n        \n    // Calculate discount impact\n    VAR DiscountImpact = \n        SUMX(\n            FILTER(\n                Sales,\n                Sales[Discount] > 0\n            ),\n            Sales[DiscountAmount]\n        )\n\n    RETURN \n        IF(\n            SalesPerCustomer > 500 && DiscountImpact < 1000,\n            \"High Value Customer\",\n            \"Standard Customer\"\n        )\n    \"\"\"\n    \n    # Initialize the DAXExpression object\n    expression = DAXExpression(dax_expression)\n    \n    # Access various properties\n    print(\"Original Expression:\", expression.dax_expression)\n    print(\"Expression without Comments:\", expression.dax_expression_no_comments)\n    print(\"Table and Column References:\", expression.table_column_references)\n    print(\"Extracted Comments:\", expression.comments)\n    print(\"Cleaned Expression:\", expression.clean_dax_expression)\n    print(\"Contains Division Operator:\", expression.contains_div)\n```\n\n## Additional Features\n\nThe DAXExpression class provides several utility methods:\n\n- `remove_comments()`: Removes comments from the DAX expression.\n- `extract_comments()`: Extracts all comments in the expression.\n- `extract_artifact_references()`: Extracts table and column references.\n- `generate_html(light: bool)`: Generates HTML output of the expression with syntax coloring.\n- `save_html_to_file(file_name: str)`: Saves the syntax-colored HTML output to a file.\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Acknowledgments\n\n### TabularEditor\n\nThe lexer grammar used in this project is adapted from the TabularEditor GitHub repository.\n\n- **Source**: [TabularEditor GitHub Repository](https://github.com/TabularEditor/TabularEditor/blob/master/AntlrGrammars/DAXLexer.g4)\n- **License**: MIT License\n\n### ANTLR\n\nThis project uses ANTLR (ANother Tool for Language Recognition) to generate the lexer and parser for DAX expressions. \n\n- **Project**: The ANTLR Project\n- **License**: BSD-3-Clause License\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "PyDAX is designed to analyze DAX, it can extract comments, remove comments, and identify columns and measures referenced in DAX expressions.",
    "version": "0.1.2",
    "project_urls": {
        "GitHub": "https://github.com/jurgenfolz/PyDAXLexer",
        "Linkedin": "https://www.linkedin.com/in/klausjfolz/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6516140ce5eb9cc5d627051c4407c7cc087b6478ca66bab1480dec1e9e8613ee",
                "md5": "099dc81c8f49cb1a41f3dca533167f73",
                "sha256": "0ab22c6438464c918208c60efbb78687e6412d27a835ee4de9da46d5d9712fc9"
            },
            "downloads": -1,
            "filename": "PyDAXLexer-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "099dc81c8f49cb1a41f3dca533167f73",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 51042,
            "upload_time": "2024-10-26T09:27:30",
            "upload_time_iso_8601": "2024-10-26T09:27:30.687668Z",
            "url": "https://files.pythonhosted.org/packages/65/16/140ce5eb9cc5d627051c4407c7cc087b6478ca66bab1480dec1e9e8613ee/PyDAXLexer-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "250b1ed3976356585b2cbc63ea4e140014e72476c4fffe89b0cc15dcd7542a49",
                "md5": "9543e404b2f3e35312c5af9cd8014b5c",
                "sha256": "2acfb1541d55611a49c8c90b702f7a779c5908c92ade1ea1e3f395bf81b8ee08"
            },
            "downloads": -1,
            "filename": "pydaxlexer-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "9543e404b2f3e35312c5af9cd8014b5c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 53214,
            "upload_time": "2024-10-26T09:27:32",
            "upload_time_iso_8601": "2024-10-26T09:27:32.261888Z",
            "url": "https://files.pythonhosted.org/packages/25/0b/1ed3976356585b2cbc63ea4e140014e72476c4fffe89b0cc15dcd7542a49/pydaxlexer-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-26 09:27:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jurgenfolz",
    "github_project": "PyDAXLexer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "antlr4-python3-runtime",
            "specs": [
                [
                    "==",
                    "4.13.1"
                ]
            ]
        }
    ],
    "lcname": "pydaxlexer"
}
        
Elapsed time: 0.40327s