Skip to content

Commit 319f65e

Browse files
authored
feat!: add form grouping, labels, and named references (CDL v1.3) (#1)
Phase 3 of CDL v2 implementation. Adds FormGroup for parenthesized form grouping with shared features, form labels, @name/$name definitions and references, flat_forms() backwards-compatible flattening, and 43 new tests (163 total). BREAKING CHANGE: CrystalDescription.forms type changed from list[CrystalForm] to list[FormNode]. Use flat_forms() for backwards-compatible flat list access.
1 parent 40fda97 commit 319f65e

7 files changed

Lines changed: 1413 additions & 25 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "gemmology-cdl-parser"
3-
version = "1.0.1"
3+
version = "1.3.0"
44
description = "Crystal Description Language (CDL) parser for crystallographic visualization"
55
readme = "README.md"
66
license = { text = "MIT" }

src/cdl_parser/__init__.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
cubic[m3m]:{111} | twin(spinel) # Spinel-law twin
2323
"""
2424

25-
__version__ = "1.0.0"
25+
__version__ = "1.3.0"
2626
__author__ = "Fabian Schuh"
2727
__email__ = "fabian@gemmology.dev"
2828

@@ -32,8 +32,10 @@
3232
ALL_POINT_GROUPS,
3333
CRYSTAL_SYSTEMS,
3434
DEFAULT_POINT_GROUPS,
35+
FEATURE_NAMES,
3536
MODIFICATION_TYPES,
3637
NAMED_FORMS,
38+
PHENOMENON_TYPES,
3739
POINT_GROUPS,
3840
TWIN_LAWS,
3941
TWIN_TYPES,
@@ -46,13 +48,18 @@
4648
from .models import (
4749
CrystalDescription,
4850
CrystalForm,
51+
Definition,
52+
Feature,
53+
FormGroup,
54+
FormNode,
4955
MillerIndex,
5056
Modification,
57+
PhenomenonSpec,
5158
TwinSpec,
5259
)
5360

5461
# Lexer/Parser internals (for advanced use)
55-
from .parser import Lexer, Parser, Token, TokenType, parse_cdl, validate_cdl
62+
from .parser import Lexer, Parser, Token, TokenType, parse_cdl, strip_comments, validate_cdl
5663

5764
__all__ = [
5865
# Version
@@ -63,8 +70,13 @@
6370
# Data classes
6471
"CrystalDescription",
6572
"CrystalForm",
73+
"Definition",
74+
"Feature",
75+
"FormGroup",
76+
"FormNode",
6677
"MillerIndex",
6778
"Modification",
79+
"PhenomenonSpec",
6880
"TwinSpec",
6981
# Exceptions
7082
"CDLError",
@@ -74,8 +86,10 @@
7486
"ALL_POINT_GROUPS",
7587
"CRYSTAL_SYSTEMS",
7688
"DEFAULT_POINT_GROUPS",
89+
"FEATURE_NAMES",
7790
"MODIFICATION_TYPES",
7891
"NAMED_FORMS",
92+
"PHENOMENON_TYPES",
7993
"POINT_GROUPS",
8094
"TWIN_LAWS",
8195
"TWIN_TYPES",
@@ -84,4 +98,5 @@
8498
"Parser",
8599
"Token",
86100
"TokenType",
101+
"strip_comments",
87102
]

src/cdl_parser/constants.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"truncate", # Cut off corners/edges
121121
"taper", # Make narrower in one direction
122122
"bevel", # Add beveled edges
123+
"flatten", # Compress along an axis
123124
}
124125

125126
# =============================================================================
@@ -131,3 +132,29 @@
131132
"penetration", # Penetration twin (interpenetrating)
132133
"cyclic", # Cyclic twin (multiple individuals)
133134
}
135+
136+
# =============================================================================
137+
# Feature Names (CDL v1.2)
138+
# =============================================================================
139+
140+
FEATURE_NAMES: set[str] = {
141+
# Growth features
142+
"phantom", "sector", "zoning", "skeletal", "dendritic",
143+
# Surface features
144+
"striation", "trigon", "etch_pit", "growth_hillock",
145+
# Inclusion features
146+
"inclusion", "needle", "silk", "fluid", "bubble",
147+
# Color features
148+
"colour", "colour_zone", "pleochroism",
149+
# Other
150+
"lamellar", "banding",
151+
}
152+
153+
# =============================================================================
154+
# Phenomenon Types (CDL v1.2)
155+
# =============================================================================
156+
157+
PHENOMENON_TYPES: set[str] = {
158+
"asterism", "chatoyancy", "adularescence", "labradorescence",
159+
"play_of_color", "colour_change", "aventurescence", "iridescence",
160+
}

0 commit comments

Comments
 (0)