Skip to content

Commit 2a062f7

Browse files
authored
Escape dollar signs in record field labels, cont'd (#18)
* fix: normalize keys that include $ * fix: export Meta from the Resume package
1 parent 3de451a commit 2a062f7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Resume/package.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
, Interest = ./Interest.dhall
77
, Language = ./Language.dhall
88
, Location = ./Location.dhall
9+
, Meta = ./Meta.dhall
910
, Profile = ./Profile.dhall
1011
, Project = ./Project.dhall
1112
, Publication = ./Publication.dhall

scripts/schemastore-to-dhall.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
),
4141
)
4242

43-
4443
def capitalize(name: str) -> str:
4544
return "".join(map(lambda x: x[0].upper() + x[1:], name.split('_')))
4645

@@ -102,9 +101,19 @@ def dhall_record(obj: Object, name: str, defs: Defs) -> Types:
102101
dt = dhall_type(value, key, types, defs)
103102
if dt:
104103
dhall_type_str, types = dt
105-
new_type[key] = dhall_type_str
104+
key_normalized = normalize_key(key)
105+
new_type[key_normalized] = dhall_type_str
106106
return types + [(capitalize(name), new_type)]
107107

108+
def normalize_key(key: str) -> str:
109+
"""Normalize a key to make it suitable to use as a record field.
110+
111+
For the time being this only escapes dollar sign.
112+
"""
113+
if '$' in key:
114+
return '`' + key + '`'
115+
else:
116+
return key
108117

109118
SchemasFiles = List[Tuple[str, str]]
110119

0 commit comments

Comments
 (0)