Skip to content

Pya2l fails to parse the a2l file which was generated by itself #88

@BlueDay137

Description

@BlueDay137

I have python 10.8 and pya2l 0.17.5.
I implement some code to read "ASAP2_Demo_V161.a2l" file and generate another file "ASAP2_Demo_V161.a2l" immediately, without changing any content of a2ldb.
But the generated a2l cannot be parsed again by the same code!?

`
from pya2l import DB
from pya2l.api.inspect import Project
import pya2l.model as model
from pya2l import export_a2l

import sys
import warnings
if not sys.warnoptions:
warnings.simplefilter("ignore")

def list_a2l_measurements_and_params(a2l_file: str):
db = DB()
try:
# Step 1: Import A2L -> creates a database (e.g. Mon.a2ldb)
session = db.open_create(f"{a2l_file}.a2l", encoding="utf-8")
print(f"Imported {a2l_file}.a2l into database.")
except Exception as e:
print(f"Error importing A2L file: {e}")
return

# Create a Project instance
project = Project(session)

# Access project attributes
print(f"Project name: {project.name}")
# print(project.header.version)

try:
    export_a2l("ASAP2_Demo_V161.a2ldb", "ASAP2_Demo_V161.a2l", encoding="utf-8")
    print("Exported database done!")
except Exception as e:
    print(f"Error exporting A2L: {e}")

try:
    session.close()
except Exception as e:
    print(f"Error closing database: {e}")

if name == "main":
# Replace with the path to your A2L file
list_a2l_measurements_and_params("ASAP2_Demo_V161")
`

Error when parsing the generated file:

[2025-10-25 22:39:50.042] [preprocessor] [info] Preprocessing and tokenizing 'ASAP2_Demo_V161_2.a2l'. [2025-10-25 22:39:50.059] [a2l] [info] Elapsed Time: 0.017[s] [2025-10-25 22:39:50.060] [a2l] [info] Start parsing... [2025-10-25 22:39:50.062] [a2lparser] [error] END token mismatch: expected 'MODULE', got 'A2ML' [2025-10-25 22:39:50.066] [a2lparser] [warning] IF_DATA is missing one or more required parameters: [2025-10-25 22:39:50.066] [a2lparser] [warning] name [2025-10-25 22:39:50.066] [a2lparser] [error] END token mismatch: expected 'MODULE', got 'IF_DATA' [2025-10-25 22:39:50.068] [a2lparser] [warning] IF_DATA is missing one or more required parameters: [2025-10-25 22:39:50.068] [a2lparser] [warning] name [2025-10-25 22:39:50.068] [a2lparser] [error] END token mismatch: expected 'MEMORY_SEGMENT', got 'IF_DATA' [2025-10-25 22:39:50.069] [a2l] [info] Elapsed Time: 0.009[s] [2025-10-25 22:39:50.069] [a2l] [info] Number of keywords: 440 Unexpected token (not an AML type)

What can be the issue here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions