evalis 0.2.0__tar.gz → 0.3.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.
Files changed (26) hide show
  1. {evalis-0.2.0/src/evalis.egg-info → evalis-0.3.0}/PKG-INFO +5 -1
  2. {evalis-0.2.0 → evalis-0.3.0}/README.md +4 -0
  3. evalis-0.3.0/src/evalis/__gen__/EvalisLexer.py +145 -0
  4. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/__gen__/EvalisListener.py +36 -0
  5. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/__gen__/EvalisParser.py +401 -135
  6. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/__gen__/EvalisVisitor.py +20 -0
  7. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/ast.py +26 -2
  8. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/constants.py +2 -2
  9. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/eval.py +74 -5
  10. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/types.py +19 -1
  11. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/utils.py +12 -0
  12. {evalis-0.2.0 → evalis-0.3.0/src/evalis.egg-info}/PKG-INFO +5 -1
  13. evalis-0.2.0/src/evalis/__gen__/EvalisLexer.py +0 -140
  14. {evalis-0.2.0 → evalis-0.3.0}/LICENSE +0 -0
  15. {evalis-0.2.0 → evalis-0.3.0}/MANIFEST.in +0 -0
  16. {evalis-0.2.0 → evalis-0.3.0}/pyproject.toml +0 -0
  17. {evalis-0.2.0 → evalis-0.3.0}/setup.cfg +0 -0
  18. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/__gen__/grammar.py +0 -0
  19. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/__init__.py +0 -0
  20. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/antlr4_adapter.py +0 -0
  21. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/error.py +0 -0
  22. {evalis-0.2.0 → evalis-0.3.0}/src/evalis/evalis.py +0 -0
  23. {evalis-0.2.0 → evalis-0.3.0}/src/evalis.egg-info/SOURCES.txt +0 -0
  24. {evalis-0.2.0 → evalis-0.3.0}/src/evalis.egg-info/dependency_links.txt +0 -0
  25. {evalis-0.2.0 → evalis-0.3.0}/src/evalis.egg-info/requires.txt +0 -0
  26. {evalis-0.2.0 → evalis-0.3.0}/src/evalis.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: evalis
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: A polyglot, safe, user-friendly expression evaluator.
5
5
  Author-email: Paul Slaughter <paul@souldzin.com>
6
6
  License-Expression: MIT
@@ -67,10 +67,14 @@ print(value) # 7
67
67
  - **Logical**: `and`, `or`, `not`
68
68
  - **Property access**: `obj.property`, `obj['key']`
69
69
  - **Array access**: `arr[0]`
70
+ - **Array slicing**: `arr[:10]`, `arr[2:5]`, `arr[8:]` (step syntax and negative indexes are not supported)
71
+ - **List literals**: `[1, 2, 3]`, `[]`
70
72
  - **List comprehensions**: `[x * 2 for x in numbers]`
71
73
  - **Membership**: `x in collection`
72
74
  - **String literals**: Both `'single'` and `"double"` quotes supported
73
75
 
76
+ Array slicing currently applies to identifier/property/index chains, such as `items[:10]` or `user.items[2:5]`. Slicing arbitrary expression results, such as `[x for x in items][:10]`, is not yet supported.
77
+
74
78
  **Note on `+` operator:**
75
79
  - Numbers: `5 + 3` → `8`
76
80
  - Strings: `"hello" + "world"` → `"helloworld"` (coerces primitives to string)
@@ -34,10 +34,14 @@ print(value) # 7
34
34
  - **Logical**: `and`, `or`, `not`
35
35
  - **Property access**: `obj.property`, `obj['key']`
36
36
  - **Array access**: `arr[0]`
37
+ - **Array slicing**: `arr[:10]`, `arr[2:5]`, `arr[8:]` (step syntax and negative indexes are not supported)
38
+ - **List literals**: `[1, 2, 3]`, `[]`
37
39
  - **List comprehensions**: `[x * 2 for x in numbers]`
38
40
  - **Membership**: `x in collection`
39
41
  - **String literals**: Both `'single'` and `"double"` quotes supported
40
42
 
43
+ Array slicing currently applies to identifier/property/index chains, such as `items[:10]` or `user.items[2:5]`. Slicing arbitrary expression results, such as `[x for x in items][:10]`, is not yet supported.
44
+
41
45
  **Note on `+` operator:**
42
46
  - Numbers: `5 + 3` → `8`
43
47
  - Strings: `"hello" + "world"` → `"helloworld"` (coerces primitives to string)
@@ -0,0 +1,145 @@
1
+ # Generated from /home/runner/work/evalis/evalis/grammar/Evalis.g4 by ANTLR 4.13.2
2
+ from antlr4 import *
3
+ from io import StringIO
4
+ import sys
5
+ if sys.version_info[1] > 5:
6
+ from typing import TextIO
7
+ else:
8
+ from typing.io import TextIO
9
+
10
+
11
+ def serializedATN():
12
+ return [
13
+ 4,0,30,185,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
14
+ 2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,
15
+ 13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,
16
+ 19,2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,
17
+ 26,7,26,2,27,7,27,2,28,7,28,2,29,7,29,1,0,1,0,1,0,1,0,1,1,1,1,1,
18
+ 2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,1,6,1,6,1,7,1,7,1,8,1,8,1,8,1,
19
+ 9,1,9,1,9,1,10,1,10,1,10,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,13,
20
+ 1,13,1,13,1,14,1,14,1,15,1,15,1,16,1,16,1,17,1,17,1,17,1,17,1,18,
21
+ 1,18,1,19,1,19,1,20,1,20,1,21,1,21,1,22,1,22,1,22,1,22,1,22,1,23,
22
+ 1,23,1,23,1,23,1,23,1,24,1,24,1,24,1,24,1,24,1,24,1,25,1,25,5,25,
23
+ 136,8,25,10,25,12,25,139,9,25,1,26,4,26,142,8,26,11,26,12,26,143,
24
+ 1,27,4,27,147,8,27,11,27,12,27,148,1,27,1,27,4,27,153,8,27,11,27,
25
+ 12,27,154,1,28,1,28,1,28,1,28,5,28,161,8,28,10,28,12,28,164,9,28,
26
+ 1,28,1,28,1,28,1,28,1,28,5,28,171,8,28,10,28,12,28,174,9,28,1,28,
27
+ 3,28,177,8,28,1,29,4,29,180,8,29,11,29,12,29,181,1,29,1,29,0,0,30,
28
+ 1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,
29
+ 27,14,29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,47,24,
30
+ 49,25,51,26,53,27,55,28,57,29,59,30,1,0,6,3,0,65,90,95,95,97,122,
31
+ 4,0,48,57,65,90,95,95,97,122,1,0,48,57,2,0,34,34,92,92,2,0,39,39,
32
+ 92,92,3,0,9,10,13,13,32,32,194,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,
33
+ 0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,
34
+ 0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,
35
+ 0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,
36
+ 0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,
37
+ 0,47,1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,
38
+ 0,57,1,0,0,0,0,59,1,0,0,0,1,61,1,0,0,0,3,65,1,0,0,0,5,67,1,0,0,0,
39
+ 7,69,1,0,0,0,9,71,1,0,0,0,11,73,1,0,0,0,13,75,1,0,0,0,15,78,1,0,
40
+ 0,0,17,80,1,0,0,0,19,83,1,0,0,0,21,86,1,0,0,0,23,89,1,0,0,0,25,92,
41
+ 1,0,0,0,27,96,1,0,0,0,29,99,1,0,0,0,31,101,1,0,0,0,33,103,1,0,0,
42
+ 0,35,105,1,0,0,0,37,109,1,0,0,0,39,111,1,0,0,0,41,113,1,0,0,0,43,
43
+ 115,1,0,0,0,45,117,1,0,0,0,47,122,1,0,0,0,49,127,1,0,0,0,51,133,
44
+ 1,0,0,0,53,141,1,0,0,0,55,146,1,0,0,0,57,176,1,0,0,0,59,179,1,0,
45
+ 0,0,61,62,5,110,0,0,62,63,5,111,0,0,63,64,5,116,0,0,64,2,1,0,0,0,
46
+ 65,66,5,42,0,0,66,4,1,0,0,0,67,68,5,47,0,0,68,6,1,0,0,0,69,70,5,
47
+ 43,0,0,70,8,1,0,0,0,71,72,5,45,0,0,72,10,1,0,0,0,73,74,5,60,0,0,
48
+ 74,12,1,0,0,0,75,76,5,60,0,0,76,77,5,61,0,0,77,14,1,0,0,0,78,79,
49
+ 5,62,0,0,79,16,1,0,0,0,80,81,5,62,0,0,81,82,5,61,0,0,82,18,1,0,0,
50
+ 0,83,84,5,61,0,0,84,85,5,61,0,0,85,20,1,0,0,0,86,87,5,33,0,0,87,
51
+ 88,5,61,0,0,88,22,1,0,0,0,89,90,5,105,0,0,90,91,5,110,0,0,91,24,
52
+ 1,0,0,0,92,93,5,97,0,0,93,94,5,110,0,0,94,95,5,100,0,0,95,26,1,0,
53
+ 0,0,96,97,5,111,0,0,97,98,5,114,0,0,98,28,1,0,0,0,99,100,5,40,0,
54
+ 0,100,30,1,0,0,0,101,102,5,41,0,0,102,32,1,0,0,0,103,104,5,91,0,
55
+ 0,104,34,1,0,0,0,105,106,5,102,0,0,106,107,5,111,0,0,107,108,5,114,
56
+ 0,0,108,36,1,0,0,0,109,110,5,93,0,0,110,38,1,0,0,0,111,112,5,44,
57
+ 0,0,112,40,1,0,0,0,113,114,5,46,0,0,114,42,1,0,0,0,115,116,5,58,
58
+ 0,0,116,44,1,0,0,0,117,118,5,110,0,0,118,119,5,117,0,0,119,120,5,
59
+ 108,0,0,120,121,5,108,0,0,121,46,1,0,0,0,122,123,5,116,0,0,123,124,
60
+ 5,114,0,0,124,125,5,117,0,0,125,126,5,101,0,0,126,48,1,0,0,0,127,
61
+ 128,5,102,0,0,128,129,5,97,0,0,129,130,5,108,0,0,130,131,5,115,0,
62
+ 0,131,132,5,101,0,0,132,50,1,0,0,0,133,137,7,0,0,0,134,136,7,1,0,
63
+ 0,135,134,1,0,0,0,136,139,1,0,0,0,137,135,1,0,0,0,137,138,1,0,0,
64
+ 0,138,52,1,0,0,0,139,137,1,0,0,0,140,142,7,2,0,0,141,140,1,0,0,0,
65
+ 142,143,1,0,0,0,143,141,1,0,0,0,143,144,1,0,0,0,144,54,1,0,0,0,145,
66
+ 147,7,2,0,0,146,145,1,0,0,0,147,148,1,0,0,0,148,146,1,0,0,0,148,
67
+ 149,1,0,0,0,149,150,1,0,0,0,150,152,5,46,0,0,151,153,7,2,0,0,152,
68
+ 151,1,0,0,0,153,154,1,0,0,0,154,152,1,0,0,0,154,155,1,0,0,0,155,
69
+ 56,1,0,0,0,156,162,5,34,0,0,157,161,8,3,0,0,158,159,5,92,0,0,159,
70
+ 161,9,0,0,0,160,157,1,0,0,0,160,158,1,0,0,0,161,164,1,0,0,0,162,
71
+ 160,1,0,0,0,162,163,1,0,0,0,163,165,1,0,0,0,164,162,1,0,0,0,165,
72
+ 177,5,34,0,0,166,172,5,39,0,0,167,171,8,4,0,0,168,169,5,92,0,0,169,
73
+ 171,9,0,0,0,170,167,1,0,0,0,170,168,1,0,0,0,171,174,1,0,0,0,172,
74
+ 170,1,0,0,0,172,173,1,0,0,0,173,175,1,0,0,0,174,172,1,0,0,0,175,
75
+ 177,5,39,0,0,176,156,1,0,0,0,176,166,1,0,0,0,177,58,1,0,0,0,178,
76
+ 180,7,5,0,0,179,178,1,0,0,0,180,181,1,0,0,0,181,179,1,0,0,0,181,
77
+ 182,1,0,0,0,182,183,1,0,0,0,183,184,6,29,0,0,184,60,1,0,0,0,11,0,
78
+ 137,143,148,154,160,162,170,172,176,181,1,6,0,0
79
+ ]
80
+
81
+ class EvalisLexer(Lexer):
82
+
83
+ atn = ATNDeserializer().deserialize(serializedATN())
84
+
85
+ decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ]
86
+
87
+ T__0 = 1
88
+ T__1 = 2
89
+ T__2 = 3
90
+ T__3 = 4
91
+ T__4 = 5
92
+ T__5 = 6
93
+ T__6 = 7
94
+ T__7 = 8
95
+ T__8 = 9
96
+ T__9 = 10
97
+ T__10 = 11
98
+ T__11 = 12
99
+ T__12 = 13
100
+ T__13 = 14
101
+ T__14 = 15
102
+ T__15 = 16
103
+ T__16 = 17
104
+ T__17 = 18
105
+ T__18 = 19
106
+ T__19 = 20
107
+ T__20 = 21
108
+ T__21 = 22
109
+ T__22 = 23
110
+ T__23 = 24
111
+ T__24 = 25
112
+ IDENTIFIER = 26
113
+ INT = 27
114
+ FLOAT = 28
115
+ STRING = 29
116
+ WS = 30
117
+
118
+ channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
119
+
120
+ modeNames = [ "DEFAULT_MODE" ]
121
+
122
+ literalNames = [ "<INVALID>",
123
+ "'not'", "'*'", "'/'", "'+'", "'-'", "'<'", "'<='", "'>'", "'>='",
124
+ "'=='", "'!='", "'in'", "'and'", "'or'", "'('", "')'", "'['",
125
+ "'for'", "']'", "','", "'.'", "':'", "'null'", "'true'", "'false'" ]
126
+
127
+ symbolicNames = [ "<INVALID>",
128
+ "IDENTIFIER", "INT", "FLOAT", "STRING", "WS" ]
129
+
130
+ ruleNames = [ "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6",
131
+ "T__7", "T__8", "T__9", "T__10", "T__11", "T__12", "T__13",
132
+ "T__14", "T__15", "T__16", "T__17", "T__18", "T__19",
133
+ "T__20", "T__21", "T__22", "T__23", "T__24", "IDENTIFIER",
134
+ "INT", "FLOAT", "STRING", "WS" ]
135
+
136
+ grammarFileName = "Evalis.g4"
137
+
138
+ def __init__(self, input=None, output:TextIO = sys.stdout):
139
+ super().__init__(input, output)
140
+ self.checkVersion("4.13.2")
141
+ self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache())
142
+ self._actions = None
143
+ self._predicates = None
144
+
145
+
@@ -107,6 +107,15 @@ class EvalisListener(ParseTreeListener):
107
107
  pass
108
108
 
109
109
 
110
+ # Enter a parse tree produced by EvalisParser#SliceAtom.
111
+ def enterSliceAtom(self, ctx:EvalisParser.SliceAtomContext):
112
+ pass
113
+
114
+ # Exit a parse tree produced by EvalisParser#SliceAtom.
115
+ def exitSliceAtom(self, ctx:EvalisParser.SliceAtomContext):
116
+ pass
117
+
118
+
110
119
  # Enter a parse tree produced by EvalisParser#IdentifierAtom.
111
120
  def enterIdentifierAtom(self, ctx:EvalisParser.IdentifierAtomContext):
112
121
  pass
@@ -134,6 +143,24 @@ class EvalisListener(ParseTreeListener):
134
143
  pass
135
144
 
136
145
 
146
+ # Enter a parse tree produced by EvalisParser#ListLiteral.
147
+ def enterListLiteral(self, ctx:EvalisParser.ListLiteralContext):
148
+ pass
149
+
150
+ # Exit a parse tree produced by EvalisParser#ListLiteral.
151
+ def exitListLiteral(self, ctx:EvalisParser.ListLiteralContext):
152
+ pass
153
+
154
+
155
+ # Enter a parse tree produced by EvalisParser#exprList.
156
+ def enterExprList(self, ctx:EvalisParser.ExprListContext):
157
+ pass
158
+
159
+ # Exit a parse tree produced by EvalisParser#exprList.
160
+ def exitExprList(self, ctx:EvalisParser.ExprListContext):
161
+ pass
162
+
163
+
137
164
  # Enter a parse tree produced by EvalisParser#accessSuffix.
138
165
  def enterAccessSuffix(self, ctx:EvalisParser.AccessSuffixContext):
139
166
  pass
@@ -143,6 +170,15 @@ class EvalisListener(ParseTreeListener):
143
170
  pass
144
171
 
145
172
 
173
+ # Enter a parse tree produced by EvalisParser#sliceSuffix.
174
+ def enterSliceSuffix(self, ctx:EvalisParser.SliceSuffixContext):
175
+ pass
176
+
177
+ # Exit a parse tree produced by EvalisParser#sliceSuffix.
178
+ def exitSliceSuffix(self, ctx:EvalisParser.SliceSuffixContext):
179
+ pass
180
+
181
+
146
182
  # Enter a parse tree produced by EvalisParser#literal.
147
183
  def enterLiteral(self, ctx:EvalisParser.LiteralContext):
148
184
  pass