phig 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- phig-0.1.0/.gitignore +31 -0
- phig-0.1.0/.gitmodules +3 -0
- phig-0.1.0/Cargo.lock +219 -0
- phig-0.1.0/Cargo.toml +12 -0
- phig-0.1.0/LICENSE +7 -0
- phig-0.1.0/PKG-INFO +8 -0
- phig-0.1.0/phig/__init__.py +60 -0
- phig-0.1.0/pyproject.toml +19 -0
- phig-0.1.0/src/lib.rs +133 -0
- phig-0.1.0/tests/test_api.py +120 -0
- phig-0.1.0/tests/test_conformance.py +37 -0
- phig-0.1.0/tests/testdata/LICENSE +7 -0
- phig-0.1.0/tests/testdata/bare_semicolon_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/bare_special_chars.json +7 -0
- phig-0.1.0/tests/testdata/bare_special_chars.phig +5 -0
- phig-0.1.0/tests/testdata/comment_in_bare.json +4 -0
- phig-0.1.0/tests/testdata/comment_in_bare.phig +2 -0
- phig-0.1.0/tests/testdata/comment_only.json +1 -0
- phig-0.1.0/tests/testdata/comment_only.phig +2 -0
- phig-0.1.0/tests/testdata/comments.json +8 -0
- phig-0.1.0/tests/testdata/comments.phig +9 -0
- phig-0.1.0/tests/testdata/complex.json +33 -0
- phig-0.1.0/tests/testdata/complex.phig +27 -0
- phig-0.1.0/tests/testdata/consecutive_semicolons_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/crlf.json +4 -0
- phig-0.1.0/tests/testdata/crlf.phig +2 -0
- phig-0.1.0/tests/testdata/deeply_nested.json +9 -0
- phig-0.1.0/tests/testdata/deeply_nested.phig +7 -0
- phig-0.1.0/tests/testdata/duplicate_keys_FAIL.phig +2 -0
- phig-0.1.0/tests/testdata/duplicate_keys_nested_FAIL.phig +4 -0
- phig-0.1.0/tests/testdata/empty.json +1 -0
- phig-0.1.0/tests/testdata/empty.phig +0 -0
- phig-0.1.0/tests/testdata/empty_containers.json +4 -0
- phig-0.1.0/tests/testdata/empty_containers.phig +2 -0
- phig-0.1.0/tests/testdata/empty_strings.json +4 -0
- phig-0.1.0/tests/testdata/empty_strings.phig +2 -0
- phig-0.1.0/tests/testdata/empty_unicode_escape_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/escape_sequences.json +8 -0
- phig-0.1.0/tests/testdata/escape_sequences.phig +6 -0
- phig-0.1.0/tests/testdata/extra_close_brace_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/extra_close_bracket_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/formfeed_ws_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/inline_map.json +6 -0
- phig-0.1.0/tests/testdata/inline_map.phig +1 -0
- phig-0.1.0/tests/testdata/invalid_escape_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/invalid_unicode_codepoint_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/key_without_value_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/line_continuation.json +4 -0
- phig-0.1.0/tests/testdata/line_continuation.phig +5 -0
- phig-0.1.0/tests/testdata/line_continuation_crlf.json +4 -0
- phig-0.1.0/tests/testdata/line_continuation_crlf.phig +5 -0
- phig-0.1.0/tests/testdata/list_basic.json +7 -0
- phig-0.1.0/tests/testdata/list_basic.phig +1 -0
- phig-0.1.0/tests/testdata/list_empty_strings.json +7 -0
- phig-0.1.0/tests/testdata/list_empty_strings.phig +1 -0
- phig-0.1.0/tests/testdata/list_mixed_separators.json +8 -0
- phig-0.1.0/tests/testdata/list_mixed_separators.phig +2 -0
- phig-0.1.0/tests/testdata/list_mixed_types.json +11 -0
- phig-0.1.0/tests/testdata/list_mixed_types.phig +1 -0
- phig-0.1.0/tests/testdata/list_nested.json +12 -0
- phig-0.1.0/tests/testdata/list_nested.phig +1 -0
- phig-0.1.0/tests/testdata/list_newline.json +7 -0
- phig-0.1.0/tests/testdata/list_newline.phig +5 -0
- phig-0.1.0/tests/testdata/list_semicolons.json +7 -0
- phig-0.1.0/tests/testdata/list_semicolons.phig +1 -0
- phig-0.1.0/tests/testdata/list_single.json +5 -0
- phig-0.1.0/tests/testdata/list_single.phig +1 -0
- phig-0.1.0/tests/testdata/list_triple_nested.json +9 -0
- phig-0.1.0/tests/testdata/list_triple_nested.phig +1 -0
- phig-0.1.0/tests/testdata/list_with_maps.json +12 -0
- phig-0.1.0/tests/testdata/list_with_maps.phig +4 -0
- phig-0.1.0/tests/testdata/map_comments.json +6 -0
- phig-0.1.0/tests/testdata/map_comments.phig +7 -0
- phig-0.1.0/tests/testdata/map_single.json +5 -0
- phig-0.1.0/tests/testdata/map_single.phig +1 -0
- phig-0.1.0/tests/testdata/map_with_list.json +9 -0
- phig-0.1.0/tests/testdata/map_with_list.phig +4 -0
- phig-0.1.0/tests/testdata/mismatched_brace_bracket_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/mismatched_bracket_brace_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/mixed_separators.json +7 -0
- phig-0.1.0/tests/testdata/mixed_separators.phig +3 -0
- phig-0.1.0/tests/testdata/multiple_pairs.json +5 -0
- phig-0.1.0/tests/testdata/multiple_pairs.phig +3 -0
- phig-0.1.0/tests/testdata/nbsp_ws_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/nested_maps.json +10 -0
- phig-0.1.0/tests/testdata/nested_maps.phig +8 -0
- phig-0.1.0/tests/testdata/nested_unclosed_map_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/no_hspace.json +13 -0
- phig-0.1.0/tests/testdata/no_hspace.phig +4 -0
- phig-0.1.0/tests/testdata/pair_semicolons.json +5 -0
- phig-0.1.0/tests/testdata/pair_semicolons.phig +1 -0
- phig-0.1.0/tests/testdata/quoted_keys.json +4 -0
- phig-0.1.0/tests/testdata/quoted_keys.phig +2 -0
- phig-0.1.0/tests/testdata/quoted_literal_newline.json +3 -0
- phig-0.1.0/tests/testdata/quoted_literal_newline.phig +2 -0
- phig-0.1.0/tests/testdata/quoted_strings.json +5 -0
- phig-0.1.0/tests/testdata/quoted_strings.phig +3 -0
- phig-0.1.0/tests/testdata/raw_strings.json +4 -0
- phig-0.1.0/tests/testdata/raw_strings.phig +2 -0
- phig-0.1.0/tests/testdata/single_pair.json +3 -0
- phig-0.1.0/tests/testdata/single_pair.phig +1 -0
- phig-0.1.0/tests/testdata/tab_hspace.json +4 -0
- phig-0.1.0/tests/testdata/tab_hspace.phig +2 -0
- phig-0.1.0/tests/testdata/toplevel_list_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/trailing_semicolon.json +4 -0
- phig-0.1.0/tests/testdata/trailing_semicolon.phig +1 -0
- phig-0.1.0/tests/testdata/unclosed_list_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/unclosed_map_FAIL.phig +2 -0
- phig-0.1.0/tests/testdata/unclosed_quote_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/unclosed_raw_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/unicode_bare.json +5 -0
- phig-0.1.0/tests/testdata/unicode_bare.phig +3 -0
- phig-0.1.0/tests/testdata/unicode_bare_keys.json +4 -0
- phig-0.1.0/tests/testdata/unicode_bare_keys.phig +2 -0
- phig-0.1.0/tests/testdata/unicode_escape.json +6 -0
- phig-0.1.0/tests/testdata/unicode_escape.phig +4 -0
- phig-0.1.0/tests/testdata/unterminated_unicode_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/vertical_tab_ws_FAIL.phig +1 -0
- phig-0.1.0/tests/testdata/whitespace_only.json +1 -0
- phig-0.1.0/tests/testdata/whitespace_only.phig +2 -0
- phig-0.1.0/uv.lock +155 -0
phig-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*.egg-info/
|
|
4
|
+
dist/
|
|
5
|
+
build/
|
|
6
|
+
.venv/
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
*.so
|
|
9
|
+
*.dll
|
|
10
|
+
|
|
11
|
+
# Generated by Cargo
|
|
12
|
+
# will have compiled files and executables
|
|
13
|
+
debug
|
|
14
|
+
target
|
|
15
|
+
|
|
16
|
+
# These are backup files generated by rustfmt
|
|
17
|
+
**/*.rs.bk
|
|
18
|
+
|
|
19
|
+
# MSVC Windows builds of rustc generate these, which store debugging information
|
|
20
|
+
*.pdb
|
|
21
|
+
|
|
22
|
+
# Generated by cargo mutants
|
|
23
|
+
# Contains mutation testing data
|
|
24
|
+
**/mutants.out*/
|
|
25
|
+
|
|
26
|
+
# RustRover
|
|
27
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
28
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
29
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
30
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
31
|
+
#.idea/
|
phig-0.1.0/.gitmodules
ADDED
phig-0.1.0/Cargo.lock
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "autocfg"
|
|
7
|
+
version = "1.5.0"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "cfg-if"
|
|
13
|
+
version = "1.0.4"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "heck"
|
|
19
|
+
version = "0.5.0"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "indoc"
|
|
25
|
+
version = "2.0.7"
|
|
26
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
+
checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
|
|
28
|
+
dependencies = [
|
|
29
|
+
"rustversion",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[[package]]
|
|
33
|
+
name = "libc"
|
|
34
|
+
version = "0.2.185"
|
|
35
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
36
|
+
checksum = "52ff2c0fe9bc6cb6b14a0592c2ff4fa9ceb83eea9db979b0487cd054946a2b8f"
|
|
37
|
+
|
|
38
|
+
[[package]]
|
|
39
|
+
name = "memoffset"
|
|
40
|
+
version = "0.9.1"
|
|
41
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
42
|
+
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
|
|
43
|
+
dependencies = [
|
|
44
|
+
"autocfg",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[[package]]
|
|
48
|
+
name = "once_cell"
|
|
49
|
+
version = "1.21.4"
|
|
50
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
51
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
52
|
+
|
|
53
|
+
[[package]]
|
|
54
|
+
name = "phig"
|
|
55
|
+
version = "0.1.0"
|
|
56
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
57
|
+
checksum = "538d1db0b60541fcfa5af46006faa82799aac404b41469fd67b014f9c9706936"
|
|
58
|
+
dependencies = [
|
|
59
|
+
"serde",
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
[[package]]
|
|
63
|
+
name = "phig-py"
|
|
64
|
+
version = "0.1.0"
|
|
65
|
+
dependencies = [
|
|
66
|
+
"phig",
|
|
67
|
+
"pyo3",
|
|
68
|
+
]
|
|
69
|
+
|
|
70
|
+
[[package]]
|
|
71
|
+
name = "portable-atomic"
|
|
72
|
+
version = "1.13.1"
|
|
73
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
74
|
+
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
|
75
|
+
|
|
76
|
+
[[package]]
|
|
77
|
+
name = "proc-macro2"
|
|
78
|
+
version = "1.0.106"
|
|
79
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
80
|
+
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
|
81
|
+
dependencies = [
|
|
82
|
+
"unicode-ident",
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
[[package]]
|
|
86
|
+
name = "pyo3"
|
|
87
|
+
version = "0.23.5"
|
|
88
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
89
|
+
checksum = "7778bffd85cf38175ac1f545509665d0b9b92a198ca7941f131f85f7a4f9a872"
|
|
90
|
+
dependencies = [
|
|
91
|
+
"cfg-if",
|
|
92
|
+
"indoc",
|
|
93
|
+
"libc",
|
|
94
|
+
"memoffset",
|
|
95
|
+
"once_cell",
|
|
96
|
+
"portable-atomic",
|
|
97
|
+
"pyo3-build-config",
|
|
98
|
+
"pyo3-ffi",
|
|
99
|
+
"pyo3-macros",
|
|
100
|
+
"unindent",
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
[[package]]
|
|
104
|
+
name = "pyo3-build-config"
|
|
105
|
+
version = "0.23.5"
|
|
106
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
107
|
+
checksum = "94f6cbe86ef3bf18998d9df6e0f3fc1050a8c5efa409bf712e661a4366e010fb"
|
|
108
|
+
dependencies = [
|
|
109
|
+
"once_cell",
|
|
110
|
+
"target-lexicon",
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
[[package]]
|
|
114
|
+
name = "pyo3-ffi"
|
|
115
|
+
version = "0.23.5"
|
|
116
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
117
|
+
checksum = "e9f1b4c431c0bb1c8fb0a338709859eed0d030ff6daa34368d3b152a63dfdd8d"
|
|
118
|
+
dependencies = [
|
|
119
|
+
"libc",
|
|
120
|
+
"pyo3-build-config",
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
[[package]]
|
|
124
|
+
name = "pyo3-macros"
|
|
125
|
+
version = "0.23.5"
|
|
126
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
127
|
+
checksum = "fbc2201328f63c4710f68abdf653c89d8dbc2858b88c5d88b0ff38a75288a9da"
|
|
128
|
+
dependencies = [
|
|
129
|
+
"proc-macro2",
|
|
130
|
+
"pyo3-macros-backend",
|
|
131
|
+
"quote",
|
|
132
|
+
"syn",
|
|
133
|
+
]
|
|
134
|
+
|
|
135
|
+
[[package]]
|
|
136
|
+
name = "pyo3-macros-backend"
|
|
137
|
+
version = "0.23.5"
|
|
138
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
139
|
+
checksum = "fca6726ad0f3da9c9de093d6f116a93c1a38e417ed73bf138472cf4064f72028"
|
|
140
|
+
dependencies = [
|
|
141
|
+
"heck",
|
|
142
|
+
"proc-macro2",
|
|
143
|
+
"pyo3-build-config",
|
|
144
|
+
"quote",
|
|
145
|
+
"syn",
|
|
146
|
+
]
|
|
147
|
+
|
|
148
|
+
[[package]]
|
|
149
|
+
name = "quote"
|
|
150
|
+
version = "1.0.45"
|
|
151
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
152
|
+
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
|
153
|
+
dependencies = [
|
|
154
|
+
"proc-macro2",
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
[[package]]
|
|
158
|
+
name = "rustversion"
|
|
159
|
+
version = "1.0.22"
|
|
160
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
161
|
+
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
|
162
|
+
|
|
163
|
+
[[package]]
|
|
164
|
+
name = "serde"
|
|
165
|
+
version = "1.0.228"
|
|
166
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
167
|
+
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
|
168
|
+
dependencies = [
|
|
169
|
+
"serde_core",
|
|
170
|
+
]
|
|
171
|
+
|
|
172
|
+
[[package]]
|
|
173
|
+
name = "serde_core"
|
|
174
|
+
version = "1.0.228"
|
|
175
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
176
|
+
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
|
177
|
+
dependencies = [
|
|
178
|
+
"serde_derive",
|
|
179
|
+
]
|
|
180
|
+
|
|
181
|
+
[[package]]
|
|
182
|
+
name = "serde_derive"
|
|
183
|
+
version = "1.0.228"
|
|
184
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
185
|
+
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
|
186
|
+
dependencies = [
|
|
187
|
+
"proc-macro2",
|
|
188
|
+
"quote",
|
|
189
|
+
"syn",
|
|
190
|
+
]
|
|
191
|
+
|
|
192
|
+
[[package]]
|
|
193
|
+
name = "syn"
|
|
194
|
+
version = "2.0.117"
|
|
195
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
196
|
+
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
|
197
|
+
dependencies = [
|
|
198
|
+
"proc-macro2",
|
|
199
|
+
"quote",
|
|
200
|
+
"unicode-ident",
|
|
201
|
+
]
|
|
202
|
+
|
|
203
|
+
[[package]]
|
|
204
|
+
name = "target-lexicon"
|
|
205
|
+
version = "0.12.16"
|
|
206
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
207
|
+
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
|
|
208
|
+
|
|
209
|
+
[[package]]
|
|
210
|
+
name = "unicode-ident"
|
|
211
|
+
version = "1.0.24"
|
|
212
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
213
|
+
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
|
214
|
+
|
|
215
|
+
[[package]]
|
|
216
|
+
name = "unindent"
|
|
217
|
+
version = "0.2.4"
|
|
218
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
219
|
+
checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
|
phig-0.1.0/Cargo.toml
ADDED
phig-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2026 the phig authors
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
phig-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""phig configuration language"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import io
|
|
6
|
+
from typing import IO, Any
|
|
7
|
+
|
|
8
|
+
from ._phig import (
|
|
9
|
+
PhigError,
|
|
10
|
+
dump as _dump,
|
|
11
|
+
dumps as _dumps,
|
|
12
|
+
load as _load,
|
|
13
|
+
loads as _loads,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = ["loads", "dumps", "load", "dump", "PhigError"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def load(fp: IO[str]) -> dict[str, Any]:
|
|
20
|
+
"""Read and parse phig from a file object."""
|
|
21
|
+
return _load(fp)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def loads(s: str) -> dict[str, Any]:
|
|
25
|
+
"""Parse a phig string into a dict.
|
|
26
|
+
|
|
27
|
+
>>> loads('name foo\\nport 8080')
|
|
28
|
+
{'name': 'foo', 'port': '8080'}
|
|
29
|
+
"""
|
|
30
|
+
return _loads(s)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def dump(data: Any, fp: IO[str]) -> None:
|
|
34
|
+
"""Serialize and write phig to a file object."""
|
|
35
|
+
_dump(_to_dict(data), fp)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def dumps(data: Any) -> str:
|
|
39
|
+
"""Serialize a dict to a phig string.
|
|
40
|
+
|
|
41
|
+
>>> dumps({'name': 'foo', 'port': '8080'})
|
|
42
|
+
'name foo\\nport 8080\\n'
|
|
43
|
+
"""
|
|
44
|
+
return _dumps(_to_dict(data))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _to_dict(obj: Any) -> Any:
|
|
48
|
+
if hasattr(obj, "__dataclass_fields__"):
|
|
49
|
+
import dataclasses
|
|
50
|
+
|
|
51
|
+
return dataclasses.asdict(obj)
|
|
52
|
+
if isinstance(obj, dict):
|
|
53
|
+
return {k: _to_dict(v) for k, v in obj.items()}
|
|
54
|
+
if isinstance(obj, list):
|
|
55
|
+
return [_to_dict(v) for v in obj]
|
|
56
|
+
if isinstance(obj, bool):
|
|
57
|
+
return str(obj).lower()
|
|
58
|
+
if isinstance(obj, (int, float)):
|
|
59
|
+
return str(obj)
|
|
60
|
+
return obj
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["maturin>=1.0,<2.0"]
|
|
3
|
+
build-backend = "maturin"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "phig"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Parser and serializer for phig"
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
|
|
11
|
+
[project.optional-dependencies]
|
|
12
|
+
dev = ["pytest>=7"]
|
|
13
|
+
|
|
14
|
+
[tool.maturin]
|
|
15
|
+
module-name = "phig._phig"
|
|
16
|
+
features = ["pyo3/extension-module"]
|
|
17
|
+
|
|
18
|
+
[tool.pytest.ini_options]
|
|
19
|
+
testpaths = ["tests"]
|
phig-0.1.0/src/lib.rs
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
use std::io::{self, BufReader, BufWriter, Read, Write};
|
|
2
|
+
|
|
3
|
+
use pyo3::prelude::*;
|
|
4
|
+
use pyo3::types::{PyDict, PyList, PyString};
|
|
5
|
+
|
|
6
|
+
pyo3::create_exception!(_phig, PhigError, pyo3::exceptions::PyException);
|
|
7
|
+
|
|
8
|
+
fn value_to_py(py: Python<'_>, val: &phig::Value) -> PyResult<PyObject> {
|
|
9
|
+
Ok(match val {
|
|
10
|
+
phig::Value::String(s) => PyString::new(py, s).into_any().unbind(),
|
|
11
|
+
phig::Value::List(items) => {
|
|
12
|
+
let py_items: Vec<PyObject> = items
|
|
13
|
+
.iter()
|
|
14
|
+
.map(|v| value_to_py(py, v))
|
|
15
|
+
.collect::<PyResult<_>>()?;
|
|
16
|
+
PyList::new(py, py_items)?.into_any().unbind()
|
|
17
|
+
}
|
|
18
|
+
phig::Value::Map(pairs) => {
|
|
19
|
+
let dict = PyDict::new(py);
|
|
20
|
+
for (k, v) in pairs {
|
|
21
|
+
dict.set_item(k, value_to_py(py, v)?)?;
|
|
22
|
+
}
|
|
23
|
+
dict.into_any().unbind()
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fn py_to_value(obj: &Bound<'_, PyAny>) -> PyResult<phig::Value> {
|
|
29
|
+
Ok(if let Ok(dict) = obj.downcast::<PyDict>() {
|
|
30
|
+
let mut pairs = Vec::new();
|
|
31
|
+
for (k, v) in dict.iter() {
|
|
32
|
+
let key: String = k.extract()?;
|
|
33
|
+
pairs.push((key, py_to_value(&v)?));
|
|
34
|
+
}
|
|
35
|
+
phig::Value::Map(pairs)
|
|
36
|
+
} else if let Ok(list) = obj.downcast::<PyList>() {
|
|
37
|
+
let items = list
|
|
38
|
+
.iter()
|
|
39
|
+
.map(|item| py_to_value(&item))
|
|
40
|
+
.collect::<PyResult<Vec<_>>>()?;
|
|
41
|
+
phig::Value::List(items)
|
|
42
|
+
} else if let Ok(s) = obj.extract::<String>() {
|
|
43
|
+
phig::Value::String(s)
|
|
44
|
+
} else {
|
|
45
|
+
return Err(PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!(
|
|
46
|
+
"unsupported type: {}",
|
|
47
|
+
obj.get_type().qualname()?
|
|
48
|
+
)));
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// Adapts a Python text file object (with a `.read(size)` method) into `std::io::Read`.
|
|
53
|
+
struct PyReader<'py> {
|
|
54
|
+
fp: Bound<'py, PyAny>,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
impl<'py> Read for PyReader<'py> {
|
|
58
|
+
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
|
59
|
+
let chunk: String = self
|
|
60
|
+
.fp
|
|
61
|
+
.call_method1("read", (buf.len(),))
|
|
62
|
+
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?
|
|
63
|
+
.extract()
|
|
64
|
+
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?;
|
|
65
|
+
let bytes = chunk.as_bytes();
|
|
66
|
+
buf[..bytes.len()].copy_from_slice(bytes);
|
|
67
|
+
Ok(bytes.len())
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/// Adapts a Python text file object (with a `.write(s)` method) into `std::io::Write`.
|
|
72
|
+
struct PyWriter<'py> {
|
|
73
|
+
fp: Bound<'py, PyAny>,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
impl<'py> Write for PyWriter<'py> {
|
|
77
|
+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
|
78
|
+
let s =
|
|
79
|
+
std::str::from_utf8(buf).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
|
|
80
|
+
self.fp
|
|
81
|
+
.call_method1("write", (s,))
|
|
82
|
+
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?;
|
|
83
|
+
Ok(buf.len())
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
fn flush(&mut self) -> io::Result<()> {
|
|
87
|
+
let _ = self.fp.call_method0("flush");
|
|
88
|
+
Ok(())
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
fn to_py_err(e: phig::Error) -> PyErr {
|
|
93
|
+
PyErr::new::<PhigError, _>(e.to_string())
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#[pyfunction]
|
|
97
|
+
fn load(py: Python<'_>, fp: Bound<'_, PyAny>) -> PyResult<PyObject> {
|
|
98
|
+
let reader = BufReader::new(PyReader { fp });
|
|
99
|
+
let value: phig::Value = phig::from_reader(reader).map_err(to_py_err)?;
|
|
100
|
+
value_to_py(py, &value)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#[pyfunction]
|
|
104
|
+
fn loads(py: Python<'_>, s: &str) -> PyResult<PyObject> {
|
|
105
|
+
let value: phig::Value = phig::from_str(s).map_err(to_py_err)?;
|
|
106
|
+
value_to_py(py, &value)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
#[pyfunction]
|
|
110
|
+
fn dump(obj: &Bound<'_, PyAny>, fp: Bound<'_, PyAny>) -> PyResult<()> {
|
|
111
|
+
let value = py_to_value(obj)?;
|
|
112
|
+
let mut writer = BufWriter::new(PyWriter { fp });
|
|
113
|
+
phig::to_writer(&value, &mut writer).map_err(to_py_err)?;
|
|
114
|
+
writer
|
|
115
|
+
.flush()
|
|
116
|
+
.map_err(|e| PyErr::new::<PhigError, _>(e.to_string()))
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#[pyfunction]
|
|
120
|
+
fn dumps(obj: &Bound<'_, PyAny>) -> PyResult<String> {
|
|
121
|
+
let value = py_to_value(obj)?;
|
|
122
|
+
phig::to_string(&value).map_err(to_py_err)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
#[pymodule]
|
|
126
|
+
fn _phig(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
127
|
+
m.add_function(wrap_pyfunction!(load, m)?)?;
|
|
128
|
+
m.add_function(wrap_pyfunction!(loads, m)?)?;
|
|
129
|
+
m.add_function(wrap_pyfunction!(dump, m)?)?;
|
|
130
|
+
m.add_function(wrap_pyfunction!(dumps, m)?)?;
|
|
131
|
+
m.add("PhigError", m.py().get_type::<PhigError>())?;
|
|
132
|
+
Ok(())
|
|
133
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Tests for the public loads/dumps/load/dump API."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import io
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
import phig
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TestLoads:
|
|
13
|
+
def test_simple(self) -> None:
|
|
14
|
+
assert phig.loads("name foo\nport 8080") == {
|
|
15
|
+
"name": "foo",
|
|
16
|
+
"port": "8080",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
def test_nested(self) -> None:
|
|
20
|
+
assert phig.loads("server { host localhost; port 3000 }") == {
|
|
21
|
+
"server": {"host": "localhost", "port": "3000"},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
def test_list(self) -> None:
|
|
25
|
+
assert phig.loads("tags [a b c]") == {"tags": ["a", "b", "c"]}
|
|
26
|
+
|
|
27
|
+
def test_empty(self) -> None:
|
|
28
|
+
assert phig.loads("") == {}
|
|
29
|
+
|
|
30
|
+
def test_comments(self) -> None:
|
|
31
|
+
assert phig.loads("# header\na 1 # inline") == {"a": "1"}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class TestDumps:
|
|
35
|
+
def test_simple(self) -> None:
|
|
36
|
+
assert phig.dumps({"name": "foo", "port": "8080"}) == "name foo\nport 8080\n"
|
|
37
|
+
|
|
38
|
+
def test_nested(self) -> None:
|
|
39
|
+
result = phig.dumps({"server": {"host": "localhost", "port": "3000"}})
|
|
40
|
+
assert result == "server {\n host localhost\n port 3000\n}\n"
|
|
41
|
+
|
|
42
|
+
def test_list(self) -> None:
|
|
43
|
+
assert phig.dumps({"tags": ["a", "b"]}) == "tags [a b]\n"
|
|
44
|
+
|
|
45
|
+
def test_empty(self) -> None:
|
|
46
|
+
assert phig.dumps({}) == ""
|
|
47
|
+
|
|
48
|
+
def test_quoted(self) -> None:
|
|
49
|
+
assert phig.dumps({"msg": "hello world"}) == 'msg "hello world"\n'
|
|
50
|
+
|
|
51
|
+
def test_escapes(self) -> None:
|
|
52
|
+
assert phig.dumps({"msg": "a\nb"}) == 'msg "a\\nb"\n'
|
|
53
|
+
|
|
54
|
+
def test_coerces_non_string_scalars(self) -> None:
|
|
55
|
+
assert phig.dumps({"port": 8080, "debug": True}) == "port 8080\ndebug true\n"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class TestRoundtrip:
|
|
59
|
+
def test_value_roundtrip(self) -> None:
|
|
60
|
+
src = "name foo\ntags [a b c]\nnested { x 1; y 2 }"
|
|
61
|
+
data = phig.loads(src)
|
|
62
|
+
text = phig.dumps(data)
|
|
63
|
+
assert phig.loads(text) == data
|
|
64
|
+
|
|
65
|
+
def test_file_io(self) -> None:
|
|
66
|
+
data = {"name": "app", "port": "3000"}
|
|
67
|
+
buf = io.StringIO()
|
|
68
|
+
phig.dump(data, buf)
|
|
69
|
+
buf.seek(0)
|
|
70
|
+
assert phig.load(buf) == data
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class TestErrors:
|
|
74
|
+
def test_unclosed_brace(self) -> None:
|
|
75
|
+
with pytest.raises(phig.PhigError):
|
|
76
|
+
phig.loads("x {")
|
|
77
|
+
|
|
78
|
+
def test_unclosed_bracket(self) -> None:
|
|
79
|
+
with pytest.raises(phig.PhigError):
|
|
80
|
+
phig.loads("x [")
|
|
81
|
+
|
|
82
|
+
def test_duplicate_key(self) -> None:
|
|
83
|
+
with pytest.raises(phig.PhigError, match="duplicate key"):
|
|
84
|
+
phig.loads("a 1\na 2")
|
|
85
|
+
|
|
86
|
+
def test_unterminated_string(self) -> None:
|
|
87
|
+
with pytest.raises(phig.PhigError):
|
|
88
|
+
phig.loads('x "hello')
|
|
89
|
+
|
|
90
|
+
def test_invalid_escape(self) -> None:
|
|
91
|
+
with pytest.raises(phig.PhigError):
|
|
92
|
+
phig.loads('x "\\q"')
|
|
93
|
+
|
|
94
|
+
def test_dumps_non_dict(self) -> None:
|
|
95
|
+
with pytest.raises(phig.PhigError):
|
|
96
|
+
phig.dumps("hello") # type: ignore[arg-type]
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class TestUnicodeWhitespace:
|
|
100
|
+
def test_nbsp_not_separator(self) -> None:
|
|
101
|
+
with pytest.raises(phig.PhigError):
|
|
102
|
+
phig.loads("name\u00a0foo")
|
|
103
|
+
|
|
104
|
+
def test_nbsp_in_bare_value(self) -> None:
|
|
105
|
+
with pytest.raises(phig.PhigError):
|
|
106
|
+
phig.loads("name foo\u00a0bar")
|
|
107
|
+
|
|
108
|
+
def test_em_space_in_bare_value(self) -> None:
|
|
109
|
+
with pytest.raises(phig.PhigError):
|
|
110
|
+
phig.loads("name foo\u2003bar")
|
|
111
|
+
|
|
112
|
+
def test_nbsp_in_quoted_ok(self) -> None:
|
|
113
|
+
assert phig.loads('name "foo\u00a0bar"') == {"name": "foo\u00a0bar"}
|
|
114
|
+
|
|
115
|
+
def test_nbsp_in_raw_ok(self) -> None:
|
|
116
|
+
assert phig.loads("name 'foo\u00a0bar'") == {"name": "foo\u00a0bar"}
|
|
117
|
+
|
|
118
|
+
def test_dumps_quotes_nbsp(self) -> None:
|
|
119
|
+
text = phig.dumps({"name": "foo\u00a0bar"})
|
|
120
|
+
assert phig.loads(text) == {"name": "foo\u00a0bar"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Run conformance tests against the shared testdata/ fixtures."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
import phig
|
|
11
|
+
|
|
12
|
+
TESTDATA = Path(__file__).resolve().parent / "testdata"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _collect_pass() -> list[str]:
|
|
16
|
+
return sorted(
|
|
17
|
+
p.stem for p in TESTDATA.glob("*.phig") if not p.stem.endswith("_FAIL")
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _collect_fail() -> list[str]:
|
|
22
|
+
return sorted(p.stem for p in TESTDATA.glob("*_FAIL.phig"))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest.mark.parametrize("name", _collect_pass())
|
|
26
|
+
def test_pass(name: str) -> None:
|
|
27
|
+
phig_text = (TESTDATA / f"{name}.phig").read_text()
|
|
28
|
+
expected = json.loads((TESTDATA / f"{name}.json").read_text())
|
|
29
|
+
result = phig.loads(phig_text)
|
|
30
|
+
assert result == expected, f"{name}: {result!r} != {expected!r}"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.parametrize("name", _collect_fail())
|
|
34
|
+
def test_fail(name: str) -> None:
|
|
35
|
+
phig_text = (TESTDATA / f"{name}.phig").read_text()
|
|
36
|
+
with pytest.raises(phig.PhigError):
|
|
37
|
+
phig.loads(phig_text)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2026 the phig authors
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
;
|