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

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}: "
...             f"{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}: "
...             f"{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.

Change Log

1.0.2 (2026-01-07)

A very misleading reference to Git checkout is removed from the readme (the package is available on PyPI, so no checkout is necessary).

1.0.1 (2026-01-07)

We add the py.typed marker so that downstream clients can use this package with mypy.

1.0.0 (2026-01-07)

This is the first version where we successfully performed the experiments with IFC to AAS conversion.

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.2.tar.gz (35.5 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.2-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: express_schema-1.0.2.tar.gz
  • Upload date:
  • Size: 35.5 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.2.tar.gz
Algorithm Hash digest
SHA256 7632370fa092a9d795d4430d6f2f8aecf7bccd1b874fd2e3017032a039e25c17
MD5 6c6a6b21230c3e82447872c929f00a41
BLAKE2b-256 2af4108d8291d449131acfbb116bfdc4bf32f67900c6e8f77978da8f060fda67

See more details on using hashes here.

File details

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

File metadata

  • Download URL: express_schema-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 35.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 adb55a8472bf87677ea3d4c107076016d450f333080f9cb881c5e3ac90487680
MD5 ac959c2467bc6bbd7456a785d64dbbde
BLAKE2b-256 7c0fc9c2bf9eda1d8da67815bdccdaddcc6d9a82d83c64d4aded3489e4801a7f

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