Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niklasrosenstein/python-hcl2-ast
A HCL2 parser based on python-hcl2 that produces an Abstract Syntax Tree.
https://github.com/niklasrosenstein/python-hcl2-ast
ast hcl parser python
Last synced: 14 days ago
JSON representation
A HCL2 parser based on python-hcl2 that produces an Abstract Syntax Tree.
- Host: GitHub
- URL: https://github.com/niklasrosenstein/python-hcl2-ast
- Owner: NiklasRosenstein
- License: other
- Created: 2022-05-09T11:34:20.000Z (over 2 years ago)
- Default Branch: develop
- Last Pushed: 2024-04-03T16:16:26.000Z (7 months ago)
- Last Synced: 2024-10-08T15:41:48.185Z (about 1 month ago)
- Topics: ast, hcl, parser, python
- Language: Python
- Homepage:
- Size: 52.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# hcl2-ast
A [HCL2][] parser and evaluator based on [python-hcl2][] that produces an Abstract Syntax Tree.
[HCL2]: https://github.com/hashicorp/hcl/blob/main/README.md
[python-hcl2]: https://pypi.org/project/python-hcl2/
[hcl2-eval]: https://pypi.org/project/hcl2-eval/> __Note__: This project is in an early stage. It does not currently cover all HCL2 syntax features
> and does not have good test coverage.## Usage
```py
from hcl2_ast import parse_stringmodule = parse_string("""
hello {
name = "World"
}
""")print(module.pformat())
```Outputs:
```py
Module(body=[
Block(
name='hello',
args=[],
body=[
Attribute(key='name', value=Literal(value='World')),
]
),
])
```Also check out the [hcl2-eval][] package to evaluate HCL2 configuration ASTs.
## Compatibility
hcl2-ast requires Python 3.6 or higher.
## Known issues
* No understanding of operator precedence in expressions (grouping with parentheses works as expected)