wrlparser
Python library to parse VRML files (.wrl) using an LALR parser with a Context-Free Grammar.
Getting started
Installing
pip install wrlparser
Sample program
This program parses the file which name has been given as a command line argument. Two sample models have been provided in the tests/models folder.
from wrlparser import parse
import sys
file = sys.argv[1]
with open(file) as f:
l = "".join(f.readlines())
f.close()
scene = parse(l)
Documentation
Context-Free Grammar
This parser is based on the grammar provided by the VRML97 specification. The grammar described in the specification is a Context-Sensitive Grammar which isn't deterministic. The following changes have been made to make it a Context-Free Grammar.
- Recursive rules have been generalized to allow collections to be empty as this will resolve shift/reduce conflicts. This should only broaden the spectrum of parsable files.
elements : element elements : element elements
| element elements -> | empty
| empty
-
IDs have been optimized to the raw ID type
-
Field values have been optimized to the raw type
sffloatValue :
sfcolorValue :
sfvec2fValue : -> sffloatValues : FLOAT sffloatValues
sfvec3fValue : | empty
...
Intermediate Representation (IR)
Once parsed, the file's content is returned to the user as classes. Their structure strictly corresponds to the one described in the specification.
For instance, a material node has the following fields :
- ambientIntensity : float
- diffuseColor : list[3]
- specularColor : list[3]
- emissiveColor : list[3]
- transparency : float
- shininess : float
It should be noted that the specification doesn't require a file to specify every field of a node. They should therefore be check before accessed as follows:
m = Material()
if m.ambientIntensity != None:
# Use the value
Tests
This parser has been tester with models from the KiCad catalog.
Issues
Even though the parser fully supports VRML's grammar, a very small subset of the intermediate representation has been implemented. This is due to the lack of test models for specific node types.
If you every need to parse a file which has an unimplemented feature, feel free to share the file in a ticket so that I can support it.
Metadata
Release files for wrlparser 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wrlparser-1.0.tar.gz | 75.9 kB | Without provenance | Details for wrlparser-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wrlparser-1.0-py3-none-any.whl | Python 3 | none | any | Details for wrlparser-1.0-py3-none-any.whl |
Total release size: 141.5 kB
Release files / wrlparser-1.0.tar.gz
| Download URL | wrlparser-1.0.tar.gz |
|---|---|
| Size | 75.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd13a14b45b050516a9cf34d2d2f4364ca1cd15b371ce625bb7399250e8c55fa
|
|
BLAKE2b-256 checksum How to use checksums |
91ebd3b11e00c17c2432f9557bbb38b9997f8af69e53402c7b5334e0ee9f3b99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Release files / wrlparser-1.0-py3-none-any.whl
| Download URL | wrlparser-1.0-py3-none-any.whl |
|---|---|
| Size | 65.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
89ea20615b755f1d36f83ded9d20d3d13c1927f5a44d0b0199cf702dee4e488d
|
|
BLAKE2b-256 checksum How to use checksums |
dc0321b61bd0d06e952161766f941b6d2f6f6980d56a74b9872475500eeb30a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Security for wrlparser 1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.