omlish 0.0.0.dev252__py3-none-any.whl → 0.0.0.dev254__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.
@@ -0,0 +1,291 @@
1
+ # type: ignore
2
+ # ruff: noqa
3
+ # flake8: noqa
4
+ # Generated from Minisql.g4 by ANTLR 4.13.2
5
+ from omlish.antlr._runtime._all import *
6
+ if "." in __name__:
7
+ from .MinisqlParser import MinisqlParser
8
+ else:
9
+ from MinisqlParser import MinisqlParser
10
+
11
+ # This class defines a complete generic visitor for a parse tree produced by MinisqlParser.
12
+
13
+ class MinisqlVisitor(ParseTreeVisitor):
14
+
15
+ # Visit a parse tree produced by MinisqlParser#singleStmt.
16
+ def visitSingleStmt(self, ctx:MinisqlParser.SingleStmtContext):
17
+ return self.visitChildren(ctx)
18
+
19
+
20
+ # Visit a parse tree produced by MinisqlParser#select.
21
+ def visitSelect(self, ctx:MinisqlParser.SelectContext):
22
+ return self.visitChildren(ctx)
23
+
24
+
25
+ # Visit a parse tree produced by MinisqlParser#cteSelect.
26
+ def visitCteSelect(self, ctx:MinisqlParser.CteSelectContext):
27
+ return self.visitChildren(ctx)
28
+
29
+
30
+ # Visit a parse tree produced by MinisqlParser#cte.
31
+ def visitCte(self, ctx:MinisqlParser.CteContext):
32
+ return self.visitChildren(ctx)
33
+
34
+
35
+ # Visit a parse tree produced by MinisqlParser#unionSelect.
36
+ def visitUnionSelect(self, ctx:MinisqlParser.UnionSelectContext):
37
+ return self.visitChildren(ctx)
38
+
39
+
40
+ # Visit a parse tree produced by MinisqlParser#unionItem.
41
+ def visitUnionItem(self, ctx:MinisqlParser.UnionItemContext):
42
+ return self.visitChildren(ctx)
43
+
44
+
45
+ # Visit a parse tree produced by MinisqlParser#primarySelect.
46
+ def visitPrimarySelect(self, ctx:MinisqlParser.PrimarySelectContext):
47
+ return self.visitChildren(ctx)
48
+
49
+
50
+ # Visit a parse tree produced by MinisqlParser#allSelectItem.
51
+ def visitAllSelectItem(self, ctx:MinisqlParser.AllSelectItemContext):
52
+ return self.visitChildren(ctx)
53
+
54
+
55
+ # Visit a parse tree produced by MinisqlParser#exprSelectItem.
56
+ def visitExprSelectItem(self, ctx:MinisqlParser.ExprSelectItemContext):
57
+ return self.visitChildren(ctx)
58
+
59
+
60
+ # Visit a parse tree produced by MinisqlParser#expr.
61
+ def visitExpr(self, ctx:MinisqlParser.ExprContext):
62
+ return self.visitChildren(ctx)
63
+
64
+
65
+ # Visit a parse tree produced by MinisqlParser#unaryBooleanExpr.
66
+ def visitUnaryBooleanExpr(self, ctx:MinisqlParser.UnaryBooleanExprContext):
67
+ return self.visitChildren(ctx)
68
+
69
+
70
+ # Visit a parse tree produced by MinisqlParser#predicatedBooleanExpr.
71
+ def visitPredicatedBooleanExpr(self, ctx:MinisqlParser.PredicatedBooleanExprContext):
72
+ return self.visitChildren(ctx)
73
+
74
+
75
+ # Visit a parse tree produced by MinisqlParser#binaryBooleanExpr.
76
+ def visitBinaryBooleanExpr(self, ctx:MinisqlParser.BinaryBooleanExprContext):
77
+ return self.visitChildren(ctx)
78
+
79
+
80
+ # Visit a parse tree produced by MinisqlParser#castBooleanExpr.
81
+ def visitCastBooleanExpr(self, ctx:MinisqlParser.CastBooleanExprContext):
82
+ return self.visitChildren(ctx)
83
+
84
+
85
+ # Visit a parse tree produced by MinisqlParser#cmpPredicate.
86
+ def visitCmpPredicate(self, ctx:MinisqlParser.CmpPredicateContext):
87
+ return self.visitChildren(ctx)
88
+
89
+
90
+ # Visit a parse tree produced by MinisqlParser#isNullPredicate.
91
+ def visitIsNullPredicate(self, ctx:MinisqlParser.IsNullPredicateContext):
92
+ return self.visitChildren(ctx)
93
+
94
+
95
+ # Visit a parse tree produced by MinisqlParser#inListPredicate.
96
+ def visitInListPredicate(self, ctx:MinisqlParser.InListPredicateContext):
97
+ return self.visitChildren(ctx)
98
+
99
+
100
+ # Visit a parse tree produced by MinisqlParser#inSelectPredicate.
101
+ def visitInSelectPredicate(self, ctx:MinisqlParser.InSelectPredicateContext):
102
+ return self.visitChildren(ctx)
103
+
104
+
105
+ # Visit a parse tree produced by MinisqlParser#likePredicate.
106
+ def visitLikePredicate(self, ctx:MinisqlParser.LikePredicateContext):
107
+ return self.visitChildren(ctx)
108
+
109
+
110
+ # Visit a parse tree produced by MinisqlParser#arithValueExpr.
111
+ def visitArithValueExpr(self, ctx:MinisqlParser.ArithValueExprContext):
112
+ return self.visitChildren(ctx)
113
+
114
+
115
+ # Visit a parse tree produced by MinisqlParser#unaryValueExpr.
116
+ def visitUnaryValueExpr(self, ctx:MinisqlParser.UnaryValueExprContext):
117
+ return self.visitChildren(ctx)
118
+
119
+
120
+ # Visit a parse tree produced by MinisqlParser#primaryValueExpr.
121
+ def visitPrimaryValueExpr(self, ctx:MinisqlParser.PrimaryValueExprContext):
122
+ return self.visitChildren(ctx)
123
+
124
+
125
+ # Visit a parse tree produced by MinisqlParser#functionCallExpr.
126
+ def visitFunctionCallExpr(self, ctx:MinisqlParser.FunctionCallExprContext):
127
+ return self.visitChildren(ctx)
128
+
129
+
130
+ # Visit a parse tree produced by MinisqlParser#starFunctionCallExpr.
131
+ def visitStarFunctionCallExpr(self, ctx:MinisqlParser.StarFunctionCallExprContext):
132
+ return self.visitChildren(ctx)
133
+
134
+
135
+ # Visit a parse tree produced by MinisqlParser#caseExpr.
136
+ def visitCaseExpr(self, ctx:MinisqlParser.CaseExprContext):
137
+ return self.visitChildren(ctx)
138
+
139
+
140
+ # Visit a parse tree produced by MinisqlParser#selectExpr.
141
+ def visitSelectExpr(self, ctx:MinisqlParser.SelectExprContext):
142
+ return self.visitChildren(ctx)
143
+
144
+
145
+ # Visit a parse tree produced by MinisqlParser#parenExpr.
146
+ def visitParenExpr(self, ctx:MinisqlParser.ParenExprContext):
147
+ return self.visitChildren(ctx)
148
+
149
+
150
+ # Visit a parse tree produced by MinisqlParser#simplePrimaryExpr.
151
+ def visitSimplePrimaryExpr(self, ctx:MinisqlParser.SimplePrimaryExprContext):
152
+ return self.visitChildren(ctx)
153
+
154
+
155
+ # Visit a parse tree produced by MinisqlParser#simpleExpr.
156
+ def visitSimpleExpr(self, ctx:MinisqlParser.SimpleExprContext):
157
+ return self.visitChildren(ctx)
158
+
159
+
160
+ # Visit a parse tree produced by MinisqlParser#caseItem.
161
+ def visitCaseItem(self, ctx:MinisqlParser.CaseItemContext):
162
+ return self.visitChildren(ctx)
163
+
164
+
165
+ # Visit a parse tree produced by MinisqlParser#over.
166
+ def visitOver(self, ctx:MinisqlParser.OverContext):
167
+ return self.visitChildren(ctx)
168
+
169
+
170
+ # Visit a parse tree produced by MinisqlParser#sortItem.
171
+ def visitSortItem(self, ctx:MinisqlParser.SortItemContext):
172
+ return self.visitChildren(ctx)
173
+
174
+
175
+ # Visit a parse tree produced by MinisqlParser#aliasedRelation.
176
+ def visitAliasedRelation(self, ctx:MinisqlParser.AliasedRelationContext):
177
+ return self.visitChildren(ctx)
178
+
179
+
180
+ # Visit a parse tree produced by MinisqlParser#joinRelation.
181
+ def visitJoinRelation(self, ctx:MinisqlParser.JoinRelationContext):
182
+ return self.visitChildren(ctx)
183
+
184
+
185
+ # Visit a parse tree produced by MinisqlParser#selectRelation.
186
+ def visitSelectRelation(self, ctx:MinisqlParser.SelectRelationContext):
187
+ return self.visitChildren(ctx)
188
+
189
+
190
+ # Visit a parse tree produced by MinisqlParser#tableRelation.
191
+ def visitTableRelation(self, ctx:MinisqlParser.TableRelationContext):
192
+ return self.visitChildren(ctx)
193
+
194
+
195
+ # Visit a parse tree produced by MinisqlParser#parenRelation.
196
+ def visitParenRelation(self, ctx:MinisqlParser.ParenRelationContext):
197
+ return self.visitChildren(ctx)
198
+
199
+
200
+ # Visit a parse tree produced by MinisqlParser#groupBy.
201
+ def visitGroupBy(self, ctx:MinisqlParser.GroupByContext):
202
+ return self.visitChildren(ctx)
203
+
204
+
205
+ # Visit a parse tree produced by MinisqlParser#qualifiedName.
206
+ def visitQualifiedName(self, ctx:MinisqlParser.QualifiedNameContext):
207
+ return self.visitChildren(ctx)
208
+
209
+
210
+ # Visit a parse tree produced by MinisqlParser#identList.
211
+ def visitIdentList(self, ctx:MinisqlParser.IdentListContext):
212
+ return self.visitChildren(ctx)
213
+
214
+
215
+ # Visit a parse tree produced by MinisqlParser#ident.
216
+ def visitIdent(self, ctx:MinisqlParser.IdentContext):
217
+ return self.visitChildren(ctx)
218
+
219
+
220
+ # Visit a parse tree produced by MinisqlParser#quotedIdent.
221
+ def visitQuotedIdent(self, ctx:MinisqlParser.QuotedIdentContext):
222
+ return self.visitChildren(ctx)
223
+
224
+
225
+ # Visit a parse tree produced by MinisqlParser#integerNumber.
226
+ def visitIntegerNumber(self, ctx:MinisqlParser.IntegerNumberContext):
227
+ return self.visitChildren(ctx)
228
+
229
+
230
+ # Visit a parse tree produced by MinisqlParser#decimalNumber.
231
+ def visitDecimalNumber(self, ctx:MinisqlParser.DecimalNumberContext):
232
+ return self.visitChildren(ctx)
233
+
234
+
235
+ # Visit a parse tree produced by MinisqlParser#floatNumber.
236
+ def visitFloatNumber(self, ctx:MinisqlParser.FloatNumberContext):
237
+ return self.visitChildren(ctx)
238
+
239
+
240
+ # Visit a parse tree produced by MinisqlParser#string.
241
+ def visitString(self, ctx:MinisqlParser.StringContext):
242
+ return self.visitChildren(ctx)
243
+
244
+
245
+ # Visit a parse tree produced by MinisqlParser#null.
246
+ def visitNull(self, ctx:MinisqlParser.NullContext):
247
+ return self.visitChildren(ctx)
248
+
249
+
250
+ # Visit a parse tree produced by MinisqlParser#true.
251
+ def visitTrue(self, ctx:MinisqlParser.TrueContext):
252
+ return self.visitChildren(ctx)
253
+
254
+
255
+ # Visit a parse tree produced by MinisqlParser#false.
256
+ def visitFalse(self, ctx:MinisqlParser.FalseContext):
257
+ return self.visitChildren(ctx)
258
+
259
+
260
+ # Visit a parse tree produced by MinisqlParser#setQuantifier.
261
+ def visitSetQuantifier(self, ctx:MinisqlParser.SetQuantifierContext):
262
+ return self.visitChildren(ctx)
263
+
264
+
265
+ # Visit a parse tree produced by MinisqlParser#joinType.
266
+ def visitJoinType(self, ctx:MinisqlParser.JoinTypeContext):
267
+ return self.visitChildren(ctx)
268
+
269
+
270
+ # Visit a parse tree produced by MinisqlParser#cmpOp.
271
+ def visitCmpOp(self, ctx:MinisqlParser.CmpOpContext):
272
+ return self.visitChildren(ctx)
273
+
274
+
275
+ # Visit a parse tree produced by MinisqlParser#arithOp.
276
+ def visitArithOp(self, ctx:MinisqlParser.ArithOpContext):
277
+ return self.visitChildren(ctx)
278
+
279
+
280
+ # Visit a parse tree produced by MinisqlParser#unaryOp.
281
+ def visitUnaryOp(self, ctx:MinisqlParser.UnaryOpContext):
282
+ return self.visitChildren(ctx)
283
+
284
+
285
+ # Visit a parse tree produced by MinisqlParser#unquotedIdent.
286
+ def visitUnquotedIdent(self, ctx:MinisqlParser.UnquotedIdentContext):
287
+ return self.visitChildren(ctx)
288
+
289
+
290
+
291
+ del MinisqlParser
File without changes
@@ -0,0 +1,119 @@
1
+ # ruff: noqa: N802 N803
2
+ import typing as ta
3
+
4
+ from ... import check
5
+ from ...antlr import runtime as antlr4
6
+ from ...antlr.delimit import DelimitingLexer
7
+ from ...antlr.errors import SilentRaisingErrorListener
8
+ from .. import queries as no
9
+ from ._antlr.MinisqlLexer import MinisqlLexer # type: ignore
10
+ from ._antlr.MinisqlParser import MinisqlParser # type: ignore
11
+ from ._antlr.MinisqlVisitor import MinisqlVisitor # type: ignore
12
+
13
+
14
+ ##
15
+
16
+
17
+ class _ParseVisitor(MinisqlVisitor):
18
+ def visit(self, ctx: antlr4.ParserRuleContext):
19
+ check.isinstance(ctx, antlr4.ParserRuleContext)
20
+ node = ctx.accept(self)
21
+ return node
22
+
23
+ def aggregateResult(self, aggregate, nextResult):
24
+ if aggregate is not None:
25
+ check.none(nextResult)
26
+ return aggregate
27
+ else:
28
+ check.none(aggregate)
29
+ return nextResult
30
+
31
+ #
32
+
33
+ def visitExprSelectItem(self, ctx: MinisqlParser.ExprSelectItemContext):
34
+ value = self.visit(ctx.expr())
35
+ label = self.visit(ctx.ident()) if ctx.ident() is not None else None
36
+ return no.SelectItem(value, label)
37
+
38
+ def visitIntegerNumber(self, ctx: MinisqlParser.IntegerNumberContext):
39
+ return no.Literal(int(ctx.INTEGER_VALUE().getText()))
40
+
41
+ def visitPrimarySelect(self, ctx: MinisqlParser.PrimarySelectContext):
42
+ items = [self.visit(i) for i in ctx.selectItem()]
43
+ relations = [self.visit(r) for r in ctx.relation()]
44
+ where = self.visit(ctx.where) if ctx.where is not None else None
45
+ return no.Select(
46
+ items=items,
47
+ from_=check.single(relations) if relations else None,
48
+ where=where,
49
+ )
50
+
51
+ def visitQuotedIdent(self, ctx: MinisqlParser.QuotedIdentContext):
52
+ name = unquote(ctx.QUOTED_IDENT().getText(), '"')
53
+ return no.Ident(name)
54
+
55
+ def visitUnquotedIdent(self, ctx: MinisqlParser.UnquotedIdentContext):
56
+ return no.Ident(ctx.getText())
57
+
58
+
59
+ ##
60
+
61
+
62
+ def create_parser(buf: str) -> MinisqlParser:
63
+ lexer = MinisqlLexer(antlr4.InputStream(buf))
64
+ lexer.removeErrorListeners()
65
+ lexer.addErrorListener(SilentRaisingErrorListener())
66
+
67
+ stream = antlr4.CommonTokenStream(lexer)
68
+ stream.fill()
69
+
70
+ parser = MinisqlParser(stream)
71
+ parser.removeErrorListeners()
72
+ parser.addErrorListener(SilentRaisingErrorListener())
73
+
74
+ return parser
75
+
76
+
77
+ ##
78
+
79
+
80
+ def parse_stmt(buf: str, **kwargs) -> no.Stmt:
81
+ parser = create_parser(buf, **kwargs)
82
+ node = _ParseVisitor().visit(parser.singleStmt())
83
+ return check.isinstance(node, no.Stmt)
84
+
85
+
86
+ class _DelimitingLexer(DelimitingLexer, MinisqlLexer):
87
+ pass
88
+
89
+
90
+ def split_stmts(buf: str) -> ta.Sequence[str]:
91
+ lexer = _DelimitingLexer(
92
+ antlr4.InputStream(buf),
93
+ delimiter_token=MinisqlParser.DELIMITER,
94
+ delimiters=[';'],
95
+ )
96
+ lexer.removeErrorListeners()
97
+ lexer.addErrorListener(SilentRaisingErrorListener())
98
+
99
+ lst, part = lexer.split()
100
+ if part.strip():
101
+ raise ValueError(part)
102
+
103
+ return [s for s, _ in lst]
104
+
105
+
106
+ def parse_stmts(buf: str, **kwargs) -> ta.Sequence[no.Stmt]:
107
+ return [parse_stmt(sb, **kwargs) for sb in split_stmts(buf)]
108
+
109
+
110
+ ##
111
+
112
+
113
+ def quote(val: str, q: str) -> str:
114
+ return q + val.replace(q, q * 2) + q
115
+
116
+
117
+ def unquote(val: str, q: str) -> str:
118
+ check.arg(val.startswith(q) and val.endswith(q))
119
+ return val[1:-1].replace(q * 2, q)
@@ -1,5 +1,10 @@
1
1
  # ruff: noqa: UP006 UP007
2
2
  # @omlish-lite
3
+ """
4
+ This bypasses debuggers attaching to spawned subprocess children that look like python processes. See:
5
+
6
+ https://github.com/JetBrains/intellij-community/blob/e9d8f126c286acf9df3ff272f440b305bf2ff585/python/helpers/pydev/_pydev_bundle/pydev_monkey.py
7
+ """
3
8
  import shlex
4
9
  import typing as ta
5
10
 
@@ -0,0 +1,73 @@
1
+ """
2
+ TODO:
3
+ - cext
4
+ """
5
+ import array
6
+ import codecs
7
+ import typing as ta
8
+
9
+
10
+ ##
11
+
12
+
13
+ def decode_to_list(
14
+ raw: bytes,
15
+ encoding: str = 'utf-8',
16
+ *,
17
+ errors: str = 'strict',
18
+ ) -> list[str]:
19
+ dec = codecs.getincrementaldecoder(encoding)(errors)
20
+ end = len(raw) - 1
21
+ return [dec.decode(bytes([b]), final=i == end) for i, b in enumerate(raw)]
22
+
23
+
24
+ #
25
+
26
+
27
+ class DecodedStringIndex(ta.NamedTuple):
28
+ byte_offsets: ta.Sequence[int]
29
+
30
+
31
+ def decode_indexed(
32
+ raw: bytes,
33
+ encoding: str = 'utf-8',
34
+ *,
35
+ errors: str = 'strict',
36
+ ) -> tuple[str, DecodedStringIndex]:
37
+ dec_lst = decode_to_list(
38
+ raw,
39
+ encoding,
40
+ errors=errors,
41
+ )
42
+
43
+ dec_s = ''.join(dec_lst)
44
+
45
+ bo_arr_len = len(dec_s) + 1
46
+ if bo_arr_len < 2**8:
47
+ fmt = 'B'
48
+ elif bo_arr_len < 2**16:
49
+ fmt = 'H'
50
+ elif bo_arr_len < 2**32:
51
+ fmt = 'L'
52
+ else:
53
+ fmt = 'Q'
54
+
55
+ bo_arr = array.array(fmt, [0]) * bo_arr_len
56
+ so = 0
57
+ lbo = 0
58
+ for bo, s in enumerate(dec_lst):
59
+ if s:
60
+ bo_arr[so] = lbo
61
+ so += 1
62
+ lbo = bo + 1
63
+
64
+ if so != len(dec_s):
65
+ raise RuntimeError
66
+
67
+ bo_arr[len(dec_s)] = len(raw)
68
+
69
+ dsi = DecodedStringIndex(
70
+ bo_arr,
71
+ )
72
+
73
+ return (dec_s, dsi)