Skip to main content

This module provides a get_tree function to obtain an ANTLR parse-tree from a UVL-defined feature model

Project description

UVL parser

Documentation

Documentation for UVL can be found in the project's wiki

Dev

This python UVL parser for diverso project is generated by ANTLR from the UVL.g4 file, where the grammar is defined. In order to generate the UVL*.py files, first we need to install antlr python runtime:

pip install antlr4-python3-runtime

Then, this command should generate the files we need for the parser to work:

antlr4 -Dlanguage=Python3 -no-listener UVL.g4

With this, any grammar change or update done to the UVL.g4 file will be effective.

Usage and integration

With the grammar defined and the parser generated, get_tree.py gives us a method that, returns a ParseTree object given an uvl file via absolute path. ParseTree is an ANTLR object which represents an AST-ish structure of the file we read with the defined grammar.

This file performs a transformation from an ANTLR ParseTree to a fm_metamodel-structured FM. Pretty much every way to obtain data from this ParseTree can be seen there. However, we will give some insight into its structure for easier usage and integration.

First, these dependencies must be installed:

apt install antlr4
pip3 install antlr-denter

Now, after getting our ParseTree object from the parser:

Features and relations

root_feature = parse_tree.features().child() #Returns a ChildContext object which contains the model root feature

For any ChildContext object:

child_context.feature_spec() # Returns the feature contained in the node
child_context.feature_spec().ref() # From the feature, return the node containing its name
child_context.feature_spec().ref().WORD()[0].getText() # From feature ref, obtain its actual name. We have to get the first element from WORD() as, in imports (yet to be supported), multiple WORDs are allowed on the same ref. getText() function returns a string with the text from the node called.

child_context.feature_spec().relation() # Returns the list of RelationContext objects children of the feature called

For any RelationContext object:

relation_context.relation_spec() # Return the node containing the relation
relation_context.relation_spec().RELATION_WORD().getText() # Return a string containing the relation's name
relation_context.relation_spec().child() # Return the list of ChildContext objects the relation is parent of, with each one being processed as described above

Constraints

constraints_node = parse_tree.constraints() # Returns ConstraintsContext object
constraints_node.constraint() # Returns list of ConstraintContext objects, with each node containing a constraint

For any ConstraintContext object:

list(constraint_context.getChildren())[0] # Returns the constraint itself, it is a bit tricky due to its structure in the parser
constraint.WORD[0].getText() # Returns the left node of the constraint, [1] returns the right node
constraint.getChild(1).getText() # Returns constraint operator

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

uvlparser-0.8.5.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

uvlparser-0.8.5-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file uvlparser-0.8.5.tar.gz.

File metadata

  • Download URL: uvlparser-0.8.5.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for uvlparser-0.8.5.tar.gz
Algorithm Hash digest
SHA256 9f8fa720526f21e5c3f9a34e84765a4f1e7f0be2888c24ba9735a92687fb1690
MD5 34d6a1fe8db1cdf20283001a60254e73
BLAKE2b-256 6bc83a429e5b7216ac6309506264cb714def27872cb6232997ff77cdaef1a4af

See more details on using hashes here.

File details

Details for the file uvlparser-0.8.5-py3-none-any.whl.

File metadata

  • Download URL: uvlparser-0.8.5-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for uvlparser-0.8.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ceb73e15635988eb3d7ac1e1cb37f1bb068d283bd5cc532c80ea854f9e1bec10
MD5 95a1220ed7cf80c9d8ce07d0ffb049cc
BLAKE2b-256 5ebfbe23a7063d3390806a67acf0a8506fdc4af569e6eef48a5217ed60af4149

See more details on using hashes here.

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