Skip to main content

"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

Release files for layercparse 0.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for layercparse 0.4.3
File Interpreter ABI Platform
layercparse-0.4.3-py3-none-any.whl Python 3 none any Details

Release files / layercparse-0.4.3-py3-none-any.whl

Download URL layercparse-0.4.3-py3-none-any.whl
Size 57.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bfdd3994e84cbecfa29e5d865e1c1fedae0d233ddb9b62173d4a9eab0b3cffb
BLAKE2b-256 checksum
How to use checksums
b2304f1bb96eb844232bcf5ecde9dd5eb8ca62364290257d2536888967f68f50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.4.3 This release

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page