linked-data-python 0.0.3__py3-none-any.whl → 0.2.0__py3-none-any.whl

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.
Files changed (41) hide show
  1. ldpy/__init__.py +35 -11
  2. ldpy/__main__.py +75 -250
  3. ldpy/build.py +91 -0
  4. ldpy/console.py +116 -0
  5. ldpy/debug.py +235 -0
  6. ldpy/formatter.py +329 -0
  7. ldpy/importer.py +110 -0
  8. ldpy/lsp/__init__.py +11 -0
  9. ldpy/lsp/__main__.py +4 -0
  10. ldpy/lsp/backend.py +118 -0
  11. ldpy/lsp/rpc.py +104 -0
  12. ldpy/lsp/server.py +353 -0
  13. ldpy/lsp/translate.py +140 -0
  14. ldpy/pygments_lexer.py +613 -0
  15. ldpy/runtime.py +931 -0
  16. ldpy/sparql.py +551 -0
  17. ldpy/transpiler/__init__.py +14 -0
  18. ldpy/transpiler/core.py +2558 -0
  19. ldpy/transpiler/errors.py +38 -0
  20. ldpy/transpiler/linemap.py +292 -0
  21. linked_data_python-0.2.0.dist-info/METADATA +158 -0
  22. linked_data_python-0.2.0.dist-info/RECORD +26 -0
  23. {linked_data_python-0.0.3.dist-info → linked_data_python-0.2.0.dist-info}/WHEEL +1 -1
  24. linked_data_python-0.2.0.dist-info/entry_points.txt +9 -0
  25. {linked_data_python-0.0.3.dist-info → linked_data_python-0.2.0.dist-info/licenses}/LICENSE.md +0 -0
  26. {linked_data_python-0.0.3.dist-info → linked_data_python-0.2.0.dist-info}/top_level.txt +0 -0
  27. ldpy/grun/lib.py +0 -63
  28. ldpy/grun/util.py +0 -11
  29. ldpy/ldpy.py +0 -183
  30. ldpy/rewriter/IndentedStringWriter.py +0 -54
  31. ldpy/rewriter/LDPythonRewriter.py +0 -677
  32. ldpy/rewriter/MultiChannelTokenStream.py +0 -127
  33. ldpy/rewriter/Result.py +0 -49
  34. ldpy/rewriter/__init__.py +0 -7
  35. ldpy/rewriter/antlr/LDPythonLexer.py +0 -870
  36. ldpy/rewriter/antlr/LDPythonParser.py +0 -9336
  37. ldpy/rewriter/antlr/LDPythonVisitor.py +0 -573
  38. ldpy/sparql/builtin.py +0 -326
  39. linked_data_python-0.0.3.dist-info/METADATA +0 -139
  40. linked_data_python-0.0.3.dist-info/RECORD +0 -20
  41. linked_data_python-0.0.3.dist-info/entry_points.txt +0 -3
ldpy/sparql/builtin.py DELETED
@@ -1,326 +0,0 @@
1
- """
2
- This contains those op.Builtin functions from SPARQL that may be of interest to ldpy developers.
3
-
4
- ```
5
- # They can be all imported for use in expression nodes as follows:
6
-
7
- from ldpy.sparql.op.Builtin import *
8
- e{ STRSTARTS( ?var , "test" ) }
9
-
10
-
11
- # or individually, for example:
12
- from ldpy.sparql.op.Builtin import STRSTARTS
13
- e{ STRSTARTS( ?var , "test" ) }
14
- ```
15
- """
16
-
17
- from rdflib.plugins.sparql import operators as op
18
-
19
- def IRI(expr, ctx):
20
- expr.arg = expr.expr[0]
21
- del expr["expr"]
22
- return op.Builtin_IRI(expr, ctx)
23
-
24
- def isBLANK(expr, ctx):
25
- expr.arg = expr.expr[0]
26
- del expr["expr"]
27
- return op.Builtin_isBLANK(expr,ctx)
28
-
29
-
30
- def isLITERAL(expr, ctx):
31
- expr.arg = expr.expr[0]
32
- del expr["expr"]
33
- return op.Builtin_isLITERAL(expr, ctx)
34
-
35
-
36
- def isIRI(expr, ctx):
37
- expr.arg = expr.expr[0]
38
- del expr["expr"]
39
- return op.Builtin_isIRI(expr, ctx)
40
-
41
-
42
- def isNUMERIC(expr, ctx):
43
- expr.arg = expr.expr[0]
44
- del expr["expr"]
45
- return op.Builtin_isNUMERIC(expr, ctx)
46
-
47
-
48
- def BNODE(expr, ctx):
49
- if len(expr.expr) > 0:
50
- expr.arg = expr.expr[0]
51
- del expr["expr"]
52
- return op.Builtin_BNODE(expr, ctx)
53
-
54
-
55
- def ABS(expr, ctx):
56
- expr.arg = expr.expr[0]
57
- del expr["expr"]
58
- return op.Builtin_ABS(expr, ctx)
59
-
60
-
61
- def IF(expr, ctx):
62
- expr.arg1 = expr.expr[0]
63
- expr.arg2 = expr.expr[1]
64
- expr.arg3 = expr.expr[2]
65
- del expr["expr"]
66
- return op.Builtin_IF(expr, ctx)
67
-
68
-
69
- def RAND(expr, ctx):
70
- return op.Builtin_RAND(expr, ctx)
71
-
72
-
73
- def UUID(expr, ctx):
74
- return op.Builtin_UUID(expr, ctx)
75
-
76
-
77
- def STRUUID(expr, ctx):
78
- return op.Builtin_STRUUID(expr, ctx)
79
-
80
- def MD5(expr, ctx):
81
- expr.arg = expr.expr[0]
82
- del expr["expr"]
83
- return op.Builtin_MD5(expr, ctx)
84
-
85
- def SHA1(expr, ctx):
86
- expr.arg = expr.expr[0]
87
- del expr["expr"]
88
- return op.Builtin_SHA1(expr, ctx)
89
-
90
- def SHA256(expr, ctx):
91
- expr.arg = expr.expr[0]
92
- del expr["expr"]
93
- return op.Builtin_SHA256(expr, ctx)
94
-
95
-
96
- def SHA384(expr, ctx):
97
- expr.arg = expr.expr[0]
98
- del expr["expr"]
99
- return op.Builtin_SHA384(expr, ctx)
100
-
101
-
102
- def SHA512(expr, ctx):
103
- expr.arg = expr.expr[0]
104
- del expr["expr"]
105
- return op.Builtin_SHA512(expr, ctx)
106
-
107
-
108
- def COALESCE(expr, ctx):
109
- expr.arg = expr.expr
110
- del expr["expr"]
111
- return op.Builtin_COALESCE(expr, ctx)
112
-
113
-
114
- def CEIL(expr, ctx):
115
- expr.arg = expr.expr[0]
116
- del expr["expr"]
117
- return op.Builtin_CEIL(expr, ctx)
118
-
119
-
120
- def FLOOR(expr, ctx):
121
- expr.arg = expr.expr[0]
122
- del expr["expr"]
123
- return op.Builtin_FLOOR(expr, ctx)
124
-
125
-
126
- def ROUND(expr, ctx):
127
- expr.arg = expr.expr[0]
128
- del expr["expr"]
129
- return op.Builtin_ROUND(expr, ctx)
130
-
131
-
132
- def REGEX(expr, ctx):
133
- expr.text = expr.expr[0]
134
- expr.pattern = expr.expr[1]
135
- if len(expr.expr) > 2:
136
- expr.flags = expr.expr[2]
137
- del expr["expr"]
138
- return op.Builtin_REGEX(expr, ctx)
139
-
140
-
141
- def REPLACE(expr, ctx):
142
- expr.arg = expr.expr[0]
143
- expr.pattern = expr.expr[1]
144
- expr.replacement = expr.expr[2]
145
- expr.flags = expr.expr[3]
146
- del expr["expr"]
147
- return op.Builtin_REPLACE(expr, ctx)
148
-
149
-
150
- def STRDT(expr, ctx):
151
- expr.arg1 = expr.expr[0]
152
- expr.arg2 = expr.expr[1]
153
- del expr["expr"]
154
- return op.Builtin_STRDT(expr, ctx)
155
-
156
-
157
- def STRLANG(expr, ctx):
158
- expr.arg1 = expr.expr[0]
159
- expr.arg2 = expr.expr[1]
160
- del expr["expr"]
161
- return op.Builtin_STRLANG(expr, ctx)
162
-
163
-
164
- def CONCAT(expr, ctx):
165
- expr.arg = expr.expr
166
- del expr["expr"]
167
- return op.Builtin_CONCAT(expr, ctx)
168
-
169
-
170
- def STRSTARTS(expr, ctx):
171
- expr.arg1 = expr.expr[0]
172
- expr.arg2 = expr.expr[1]
173
- del expr["expr"]
174
- return op.Builtin_STRSTARTS(expr, ctx)
175
-
176
-
177
- def STRENDS(expr, ctx):
178
- expr.arg1 = expr.expr[0]
179
- expr.arg2 = expr.expr[1]
180
- del expr["expr"]
181
- return op.Builtin_STRENDS(expr, ctx)
182
-
183
-
184
- def STRBEFORE(expr, ctx):
185
- expr.arg1 = expr.expr[0]
186
- expr.arg2 = expr.expr[1]
187
- del expr["expr"]
188
- return op.Builtin_STRBEFORE(expr, ctx)
189
-
190
-
191
- def STRAFTER(expr, ctx):
192
- expr.arg1 = expr.expr[0]
193
- expr.arg2 = expr.expr[1]
194
- del expr["expr"]
195
- return op.Builtin_STRAFTER(expr, ctx)
196
-
197
-
198
- def CONTAINS(expr, ctx):
199
- expr.arg1 = expr.expr[0]
200
- expr.arg2 = expr.expr[1]
201
- del expr["expr"]
202
- return op.Builtin_CONTAINS(expr, ctx)
203
-
204
-
205
- def ENCODE_FOR_URI(expr, ctx):
206
- expr.arg = expr.expr[0]
207
- del expr["expr"]
208
- return op.Builtin_ENCODE_FOR_URI(expr, ctx)
209
-
210
-
211
- def SUBSTR(expr, ctx):
212
- expr.arg = expr.expr[0]
213
- expr.start = expr.expr[1]
214
- if len(expr.expr) > 2:
215
- expr.length = expr.expr[2]
216
- del expr["expr"]
217
- return op.Builtin_SUBSTR(expr, ctx)
218
-
219
-
220
- def STRLEN(expr, ctx):
221
- expr.arg = expr.expr[0]
222
- del expr["expr"]
223
- return op.Builtin_STRLEN(expr, ctx)
224
-
225
-
226
- def STR(expr, ctx):
227
- expr.arg = expr.expr[0]
228
- del expr["expr"]
229
- return op.Builtin_STR(expr, ctx)
230
-
231
-
232
- def LCASE(expr, ctx):
233
- expr.arg = expr.expr[0]
234
- del expr["expr"]
235
- return op.Builtin_LCASE(expr, ctx)
236
-
237
-
238
- def LANGMATCHES(expr, ctx):
239
- expr.arg1 = expr.expr[0]
240
- expr.arg2 = expr.expr[0]
241
- del expr["expr"]
242
- return op.Builtin_LANGMATCHES(expr, ctx)
243
-
244
-
245
- def NOW(expr, ctx):
246
- return op.Builtin_NOW(expr, ctx)
247
-
248
-
249
- def YEAR(expr, ctx):
250
- expr.arg = expr.expr[0]
251
- del expr["expr"]
252
- return op.Builtin_YEAR(expr, ctx)
253
-
254
-
255
- def MONTH(expr, ctx):
256
- expr.arg = expr.expr[0]
257
- del expr["expr"]
258
- return op.Builtin_MONTH(expr, ctx)
259
-
260
-
261
- def DAY(expr, ctx):
262
- expr.arg = expr.expr[0]
263
- del expr["expr"]
264
- return op.Builtin_DAY(expr, ctx)
265
-
266
-
267
- def HOURS(expr, ctx):
268
- expr.arg = expr.expr[0]
269
- del expr["expr"]
270
- return op.Builtin_HOURS(expr, ctx)
271
-
272
-
273
- def MINUTES(expr, ctx):
274
- expr.arg = expr.expr[0]
275
- del expr["expr"]
276
- return op.Builtin_MINUTES(expr, ctx)
277
-
278
-
279
- def SECONDS(expr, ctx):
280
- expr.arg = expr.expr[0]
281
- del expr["expr"]
282
- return op.Builtin_SECONDS(expr, ctx)
283
-
284
-
285
- def TIMEZONE(expr, ctx):
286
- expr.arg = expr.expr[0]
287
- del expr["expr"]
288
- return op.Builtin_TIMEZONE(expr, ctx)
289
-
290
-
291
- def TZ(expr, ctx):
292
- expr.arg = expr.expr[0]
293
- del expr["expr"]
294
- return op.Builtin_TZ(expr, ctx)
295
-
296
-
297
- def UCASE(expr, ctx):
298
- expr.arg = expr.expr[0]
299
- del expr["expr"]
300
- return op.Builtin_UCASE(expr, ctx)
301
-
302
-
303
- def LANG(expr, ctx):
304
- expr.arg = expr.expr[0]
305
- del expr["expr"]
306
- return op.Builtin_LANG(expr, ctx)
307
-
308
-
309
- def DATATYPE(expr, ctx):
310
- expr.arg = expr.expr[0]
311
- del expr["expr"]
312
- return op.Builtin_DATATYPE(expr, ctx)
313
-
314
-
315
- def sameTerm(expr, ctx):
316
- expr.arg1 = expr.expr[0]
317
- expr.arg2 = expr.expr[0]
318
- del expr["expr"]
319
- return op.Builtin_sameTerm(expr, ctx)
320
-
321
-
322
- def BOUND(expr, ctx):
323
- expr.arg = expr.expr[0]
324
- del expr["expr"]
325
- return op.Builtin_BOUND(expr, ctx)
326
-
@@ -1,139 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: linked-data-python
3
- Version: 0.0.3
4
- Summary: The python package "linked-data-python" can execute .ldpy files and run an interactive ldpy console.
5
- Home-page: https://gitlab.com/coswot/ldpy
6
- Author: Maxime Lefrançois
7
- Author-email: maxime.lefrancois@emse.fr
8
- License: MIT
9
- Platform: any
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Programming Language :: Python :: 3
12
- Classifier: Programming Language :: Python :: 3.7
13
- Classifier: Programming Language :: Python :: 3.8
14
- Classifier: Programming Language :: Python :: 3.9
15
- Classifier: Programming Language :: Python :: 3.10
16
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
- Classifier: Operating System :: OS Independent
18
- Classifier: Natural Language :: English
19
- Requires-Python: >=3.7
20
- Description-Content-Type: text/markdown
21
- Requires-Dist: antlr4
22
- Requires-Dist: ideas
23
- Requires-Dist: rdflib
24
-
25
- # Linked-Data Python
26
-
27
- The Linked-Data Python package allow to run .ldpy scripts, run a ldpy interactive console, and import .ldpy library modules.
28
-
29
- ![](https://gitlab.com/coswot/ldpy/-/raw/master/ldpyIcon.png)
30
-
31
- ## Installation
32
-
33
- You can install the Linked-Data Python
34
- ```
35
- pip install linked-data-python
36
- ```
37
-
38
- ## The Linked-Data Python syntax
39
-
40
- The extension ["linked-data-python" for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=MaximeLefrancois.linked-data-python) enables the syntax highlighting for Linked-Data Python source files (extensions .ldpy).
41
-
42
- The Linked-Data Python grammar only uses grammar rules supported by MicroPython 1.18, and adds support for Linked Data languages primitives and constructs:
43
-
44
- - prefix declaration statements: `@prefix ex: <http://example.org/> .`
45
- - base declaration statements: `@base <http://example.org/> .`
46
- - IRIs: `<http://example.org/>
47
- - Prefixed names: `ex:Person`
48
- - RDF literals: `"hello"^^xsd:string`, `f"hello {world}"@en`
49
- - RDF graphs: `g{ ex:Person a owl:Class ; rdfs:label "Person"@en }`
50
-
51
- Furthermore, it allows:
52
-
53
- - formatted IRIs: `f<http://example/org/{ id }/>`
54
- - formatted nodes in RDF graphs: `f{ ex:Person ex:age ?{ age } }`
55
-
56
- Example programs are available in the `examples` folder of the source code repository.
57
-
58
-
59
- # How to use
60
-
61
- ## In the command line
62
-
63
- The Linked-Data Python package is a command line application, name `ldpy`. It can also be run as `python -m ldpy`.
64
-
65
- ```
66
- $ python -m ldpy -h
67
- usage: __main__.py [-h] [-v] [-l] [-p] [-s] [-i] [-m MODULE | source]
68
-
69
- ldpy extends the Python syntax with primitives from the Semantic Web such as namespaces, RDF terms, and RDF graphs.
70
-
71
- If no source is given, ldpy will start an interactive console.
72
-
73
- positional arguments:
74
- source Program read from script file. The file extension may be .ldpy or .py.
75
-
76
- optional arguments:
77
- -h, --help show this help message and exit
78
- -v, --version only displays the current version.
79
- -l, --debug-lexer print the lexer output
80
- -p, --debug-parser print the parser output
81
- -s, --show_changes shows the transformed code before it is executed.
82
- -i starts the interactive console after executing a source
83
- -m MODULE, --module MODULE
84
- Run library module as a script. The module may be a .ldpy or a .py file.
85
- ```
86
-
87
- ## As a module
88
-
89
- ```
90
- import ldpy
91
-
92
- ldpy.config.debug_ldpy = True # print transformed source
93
- ldpy.config.debug_lexer = False # print tokens
94
- ldpy.config.debug_parser = False # print syntax tree
95
-
96
- ldpy.transform_source(source) # transform a Linked-Data Python source into a Python source
97
- ```
98
-
99
- ## Run from the source code
100
-
101
- ### 1. Dependencies
102
-
103
- ```
104
- # cd ldpy
105
- pip install -r requirements.txt
106
- ```
107
-
108
- ### 2. Generate the parser
109
-
110
- Generate the `SWPythonLexer`, `SWPythonParser`, and `SWPythonVisitor` using ANTLR4:
111
-
112
- ```
113
- # cd ldpy
114
- antlr4 -o ldpy/rewriter/antlr -package ldpy.rewriter.antlr -Xexact-output-dir -Dlanguage=Python3 -visitor -no-listener grammars/LDPython.g4
115
- ```
116
-
117
-
118
- ## Release Notes
119
-
120
- All notable changes to the "linked-data-python" are documented below.
121
-
122
- ## [0.0.3] - 2023-02-24
123
-
124
- - use `ideas` import hooks to enable using `.ldpy` files from import statements
125
- - added interactive ldpy console
126
- - added line mapping to point to the right line in the `.ldpy` file on error
127
- - corrected small bugs in the parser
128
-
129
- ## [0.0.2] - 2022-04-30
130
-
131
- - corrected many small bugs
132
- - added many examples
133
- - add `-d` functionality
134
-
135
- ## [0.0.1] - 2022-04-29
136
-
137
- - Initial release
138
-
139
-
@@ -1,20 +0,0 @@
1
- ldpy/__init__.py,sha256=F53ItPqeb2mOXIvAy4AML1lJ3oHR25n0ryQMJZHWtMQ,542
2
- ldpy/__main__.py,sha256=ieAIidZdU1wRehD0XGltni9rFhgE_qEBMFh8I8gJ2ZI,9585
3
- ldpy/ldpy.py,sha256=B88YtcOHDefXilRCVBVPMn1nVfjq5gtyNB4LyJ42nXA,6942
4
- ldpy/grun/lib.py,sha256=6A5bcemRN0JW9Utuo9MKfWgX2BhP_x-2uG8JPfK5w-o,2108
5
- ldpy/grun/util.py,sha256=MRXY2HLUY1mYwSP7a-93eU5Jhwy_wETvUWNWHi1B-AQ,346
6
- ldpy/rewriter/IndentedStringWriter.py,sha256=KJwQh-jDdnzLn7AGd-mwWgqPYlYfso36VUrUqKJfiQ0,1963
7
- ldpy/rewriter/LDPythonRewriter.py,sha256=tSisXufAta08VWh9tpA9G-qPExLhG6K0LYQ8XslLOkc,27711
8
- ldpy/rewriter/MultiChannelTokenStream.py,sha256=CW_INzEHCnUS7v1tYUkrMa1OXhQZSXnMial5aIIg0XU,4511
9
- ldpy/rewriter/Result.py,sha256=DJo2DesPMK0dbNqP8aycvAgizMKDQo3f95sWSJtMp_Y,1927
10
- ldpy/rewriter/__init__.py,sha256=zLgRTCVkruDD1QSKOPS0QimufOVyXGtHLrGJEAlI4TQ,448
11
- ldpy/rewriter/antlr/LDPythonLexer.py,sha256=O8uCIzkK_tcKZzhMDE_Ro08bXBlIWYgR1ulc4BTiH4A,46210
12
- ldpy/rewriter/antlr/LDPythonParser.py,sha256=Ulilk8_88hmiLEhxuxFXd9ymbYtWvpcc00OIJYwEzZs,319648
13
- ldpy/rewriter/antlr/LDPythonVisitor.py,sha256=0wb3U9qSFk1EQWIkRthmY1VZaQNcAV38pJxsor71BRU,19779
14
- ldpy/sparql/builtin.py,sha256=T_RRRgQgcfXPVBogHeb-P2lL92Kh_eeoIqpm7_oB-tc,6545
15
- linked_data_python-0.0.3.dist-info/LICENSE.md,sha256=R6KjQ098eAFd2k5mKaSRJqMH1LhY4o7xkHrKT5vjRfs,1074
16
- linked_data_python-0.0.3.dist-info/METADATA,sha256=0FZ1dp47OkGQqb8Kym2ocXZeEL-yx60kdQ9zCno8arg,4406
17
- linked_data_python-0.0.3.dist-info/WHEEL,sha256=g4nMs7d-Xl9-xC9XovUrsDHGXt-FT0E17Yqo92DEfvY,92
18
- linked_data_python-0.0.3.dist-info/entry_points.txt,sha256=y8_PGm7EFwUaNbLM07Hyc3ruD0W67UB6Y0_2fLKjJUk,45
19
- linked_data_python-0.0.3.dist-info/top_level.txt,sha256=dkG_F4jYkh6CS6gdpQeV_gKW3yaJBvl1ukUu0zo2KA8,5
20
- linked_data_python-0.0.3.dist-info/RECORD,,
@@ -1,3 +0,0 @@
1
- [console_scripts]
2
- ldpy = ldpy.__main__:main
3
-