Skip to main content

Layered C parser

Project description

"Fat Token" Parser and Modularity Checker for C Code

This library provides a parser for C code that extracts tokens and checks the modularity of the code based on the rules defined in the Modularity document.

The core concept of the library is the "Fat Token" which represents a higher-level abstraction of elements in C code rather than a simple sequence of characters. A Fat Token can represent items such as "words", "comments", "strings", "expressions within parentheses", etc.

With this this higher-level representation, the library enables a layered approach to parsing, focusing on high level structures without getting bogged down in unnecessary details. The parser extracts Fat Tokens from the C code and groups them into "statements" representing logical units like function definitions, struct declarations, variable declarations, etc.

For example, a function definition might be represented as a sequence of: "comment", "word", "word", "expression in parentheses", and "expression in curly braces". We can recognize this as a function definition without needing to parse the internal details of the function body or arguments list.

This approach makes it possible to perform a variety of analyses on C code or other languages with clear syntax rules.

Implementation details are described in the Implementation document.

Installation

$ pip install layercparse

Usage

import os
from layercparse import *

def main():
    # setLogLevel(LogLevel.WARNING)
    setRootPath(os.path.realpath(sys.argv[1]))
    setModules([
        Module("module1"),
        Module("module2", fileAliases=["m2"], sourceAliases = ["mod2", "m2"]),
    ])

    code = Codebase()
    code.scanFiles(get_files(), twopass=True, multithread=True)
    AccessCheck(code).checkAccess(multithread=True)

    return not workspace.errors

if __name__ == "__main__":
    # When using multithreaded processing, it's criticak to check __name__
    # rather than doing things directly in the global scope.
    sys.exit(main())

Links

Project details


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

If you're not sure about the file name format, learn more about wheel file names.

layercparse-0.2.0-py3-none-any.whl (52.6 kB view details)

Uploaded Python 3

File details

Details for the file layercparse-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: layercparse-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 52.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for layercparse-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dcb095d2da802e14957f902eaca5fba8b758b1e399b8a7a7c9c54e613e0dc0e1
MD5 c12295083ebde2b60fc82c1a83f27d54
BLAKE2b-256 93dd0d2b96ffdb91a90a2f23666f332ff0d08cb6e774114f58f39822d4a23639

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page