Skip to content

parser.py

from pymwp import Parser

Parser implementation is not a native part of pymwp. Parsing is implemented with pycparser. The Parser module is simply a convenient wrapper. Enhancements and issues with C-file parsing are out of scope of pymwp.

ParserInterface

Bases: Nodes

Interface for C code parser.

LoopT abstractmethod property

LoopT: Type

Loop type.

Node abstractmethod property

Node: Type

Base type for all AST nodes.

is_func abstractmethod

is_func(node: Any) -> bool

True if node is a function implementation.

is_loop abstractmethod

is_loop(node: Any) -> bool

True is node is a loop statement.

parse abstractmethod staticmethod

parse(full_file_name: str, **kwargs) -> dict

Extract text from the currently loaded file.

to_c abstractmethod

to_c(node: Any) -> str

Translate node back to C code.

PyCParser

Bases: ParserInterface

Implementation of the parser interface using pycparser.

LoopT property

LoopT: Type

Loop type.

Node property

Node: Type

Base type for all AST nodes.

add_attr_x staticmethod

add_attr_x(text: str) -> str

Conditionally add #define __attribute__(x) to C file for pycparser.

See: https://github.com/eliben/pycparser/wiki/FAQ#what-do-i-do -about-__attribute__/

Parameters:

Name Type Description Default
text str

C program file content as a string

required

Returns:

Type Description
str

contents of C file, with #define __attribute__(x) included.

is_func

is_func(node: Node) -> bool

True if node is a (non-empty) function implementation.

is_loop

is_loop(node: Node) -> bool

True is node is a (non-empty) loop statement.

to_c

to_c(node: Any, compact: bool = False) -> str

Translate node back to C code.