Skip to main content

Caustic's parsing framework

Project description

Caustic's Parser -- uses grammar specification to compile Caustic source code into a CST (Caustic AST)

Uses ParGlare for parsing, meant to work with CausticGrammar to create a CST (Caustic AST)

CLI usage

See cap --help

Module usage

import sys
import parglare
from pprint import pprint
from pathlib import Path

from caustic import parser

grammar = parglare.Grammar.from_file(parser.builtin_grammar('canonical/canonical.pg'))
#                                           ^ builtin_grammar fetches the builtin grammar path from caustic.grammar,
#                                             optionally adding a subdirectory and checking if it exists


parser_ = parglare.GLRParser(grammar, lexical_disambiguation=True,
                             actions=parser.actions.action.all)
#                                           ^ the actions module supplies some generally useful actions,
#                                             as well as actions specifically for creating CST nodes

try:
    forest = parser_.parse(input())
except parglare.ParseError as e:
    # custom error formatting
    print(parser.errors.format_exc(e), file=sys.stderr)

cst = parser_.call_actions(forest.get_first_tree())
pprint(cst)

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

caustic.parser-3.0.0.tar.gz (11.6 kB view hashes)

Uploaded Source

Built Distribution

caustic.parser-3.0.0-py3-none-any.whl (12.2 kB view hashes)

Uploaded Python 3

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