Skip to main content

Parse EXPRESS Schema (ISO 10303-11).

Project description

Continuous integration https://coveralls.io/repos/github/aas-core-works/express-schema/badge.svg?branch=main PyPI - version PyPI - Python Version

Parse EXPRESS Schema (ISO 10303-11).

Installation

Check out the repository and change to its directory.

Create a virtual environment:

python -m venv venv

Activate it (on Windows):

venv/Scripts/activate

… or on Unix:

source venv/bin/activate

Install the dependencies:

pip3 install express-schema

You can now use the modules express_schema.parse (see “Usage” section below) or run express-schema (see --help section below).

Usage

The Abstract Syntax Tree and parsing functionality lives in express_schema.parse module.

Example:

>>> import express_schema.parse as parse
>>>
>>> # Define a simple EXPRESS schema as a string
>>> schema_text = '''SCHEMA SimpleExample;
...
... ENTITY Person;
...   name : STRING;
...   age : INTEGER;
... END_ENTITY;
...
... END_SCHEMA;'''
>>>
>>> # Parse the schema
>>> schema, errors = parse.parse(schema_text)
>>>
>>> # Check for parsing errors
>>> if errors is not None:
...     print("Parsing errors occurred:")
...     for error in errors:
...         print(f"  Line {error.line}, Column {error.column}: {error.message}")
... else:
...     print("Schema parsed successfully!")
...     print(f"Schema name: {schema.identifier}")
...     print(f"Number of entities: {len(schema.entity_declarations)}")
...
...     # Dump the parsed schema back to text
...     dumped_text = parse.dump(schema)
...     print("Dumped schema:")
...     print(dumped_text)
Schema parsed successfully!
Schema name: SimpleExample
Number of entities: 1
Dumped schema:
Schema(
  position=1:1,
  identifier='SimpleExample',
  reference_clauses=[],
  use_clauses=[],
  constant_definitions=[],
  entity_declarations=[EntityDeclaration(
      position=3:1,
      identifier='Person',
      explicit_clauses=[
          ExplicitAttributeDefinition(
            position=4:3,
            attributes=[NameRef(
                position=4:3,
                identifier='name'
              )],
            optional=False,
            type_selection=StringType(
                position=4:10,
                fixed=False
              )
          ),
          ExplicitAttributeDefinition(
            position=5:3,
            attributes=[NameRef(
                position=5:3,
                identifier='age'
              )],
            optional=False,
            type_selection=IntegerType(
                position=5:9
              )
          )
        ],
      derive_clauses=[],
      inverse_clauses=[],
      unique_rules=[],
      domain_rules=[]
    )],
  function_declarations=[],
  procedure_declarations=[],
  type_declarations=[],
  rule_declarations=[]
)

If, for some reason, you only want to tokenize and not parse the schema, you can use express_schema.lex module.

Example:

>>> import express_schema.lex as lex
>>>
>>> # Define a simple EXPRESS schema text to tokenize
>>> schema_text = '''SCHEMA Example;
... ENTITY Person;
...   name : STRING;
... END_ENTITY;
... END_SCHEMA;'''
>>>
>>> # Tokenize the schema
>>> tokens, success = lex.lex(schema_text)
>>>
>>> # Check if tokenization was successful
>>> if success:
...     print("Tokenization successful!")
...     print(f"Number of tokens: {len(tokens)}")
...     print("First few tokens:")
...     for token in tokens[:5]:
...         print(f"  {token.kind.name} at {token.position}: {token.text!r}")
... else:
...     print("Tokenization failed!")
Tokenization successful!
Number of tokens: 14
First few tokens:
  SCHEMA at 1:1: 'SCHEMA'
  IDENTIFIER at 1:8: 'Example'
  SEMI at 1:15: ';'
  ENTITY at 2:1: 'ENTITY'
  IDENTIFIER at 2:8: 'Person'

--help

usage: express-schema [-h] --schema SCHEMA [--version]

Parse EXPRESS Schema (ISO 10303-11) and print the Abstract Syntax Tree.

options:
  -h, --help       show this help message and exit
  --schema SCHEMA  Path to the EXPRESS schema file
  --version        show the current version and exit

Contributing

See [CONTRIBUTING.rst](CONTRIBUTING.rst).

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

express_schema-1.0.0.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

express_schema-1.0.0-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

Details for the file express_schema-1.0.0.tar.gz.

File metadata

  • Download URL: express_schema-1.0.0.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for express_schema-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6987fbd73c3566f14905c8dfe13bb0e741fbca52ae822269a5f0c890e2ba79d1
MD5 a90bb9c0b3b3dff74145c580e4702a52
BLAKE2b-256 15b7a6c6c1590bad81c5028c52fd7b77ce7cd55093466e35d632ef8383025ddb

See more details on using hashes here.

File details

Details for the file express_schema-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: express_schema-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for express_schema-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b4fd49fa858908fe54037763d57687d67cab4c1226374c14dd10960588fb571
MD5 08b9fd3eaf32fdad4fe20669b9eff442
BLAKE2b-256 5c51ecd15c5e38cae812a3a772eff9641d93fc30b0003b06f9d362b87ed04100

See more details on using hashes here.

Supported by

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