C Parser writen in pure Python
Project description
A C parser based on parglare - a pure Python scannerless LR/GLR parser.
Quick intro
cparser is a parser for C language. This example shows how to
collect all IDs from a simple C code.
from cparser import CParser
from cparser.visitor import ASTVisitor
code = """
typedef struct {
int element;
int weight;
} Atom;
Atom helium;
"""
class IDVisitor(ASTVisitor):
"""Visitor that collects all identifiers in the code."""
def visit_id(self, node):
print(node.value)
return node
parser = CParser()
ast = parser.parse(code)
visitor = IDVisitor()
visitor.visit(ast)
# Output should look like this:
# element
# weight
# Atom
# Atom
# helium
Installation
Stable version:
$ pip install cparser
Development version:
$ git clone https://github.com/typhoon-hil/cparser.git
$ pip install -e cparser
Licence
MIT
Python versions
Tested with 3.6-3.9
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
cparser-0.5.0-py3-none-any.whl
(18.5 kB
view details)
File details
Details for the file cparser-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: cparser-0.5.0-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ef1d2ef688545cae4c87d0dd2a5fcdc3be08aa1a011b9fb5984a2e045c532da |
|
MD5 | 118b994b0ae503f894a36c0466a3db12 |
|
BLAKE2b-256 | e5ea92caf19ca907924b09af889af300fd7d679eab007510fd9b3e0b2611ca7a |