Skip to main content

ASDL Parser

Project description

PyASDL

A new ASDL parser for Zephyr's ASDL format.

Stub Generator Example

For understanding the parse tree and the visitors, you can check out the stub generator example. Basically it generates a typing stub for the AST module itself (when the Python's ASDL is given) in a straight forward way.

Reference

  • parse(source: str, *, filename: str = "<pyasdl>") -> Module Takes the source code (and optionally the filename, to be used in syntax errors) and outputs an pyasdl.Module instance that represents the AST of the given ASDL schema.

  • ASDLVisitor A base class to be used with visitor-pattern applications. The interface is similiar with the ast.NodeVisitor.

    import pyasdl as asdl
    
    class CollectNamesVisitor(asdl.ASDLVisitor):
        def __init__(self):
            self.names = set()
    
        def visit_Module(self, node: asdl.Module) -> None:
            self.names.add(node.name)
    
    visitor = DummyVisitor()
    for source in sources:
        tree = asdl.parse(source)
        visitor.visit(tree)
    print(visitor.names)
    
  • Module

  • Type

  • Sum

  • Constructor

  • FieldQualifier

  • Field

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyasdl-0.3.1.tar.gz (5.9 kB view hashes)

Uploaded Source

Supported by

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