tactus 0.31.2__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.
- tactus/__init__.py +49 -0
- tactus/adapters/__init__.py +9 -0
- tactus/adapters/broker_log.py +76 -0
- tactus/adapters/cli_hitl.py +189 -0
- tactus/adapters/cli_log.py +223 -0
- tactus/adapters/cost_collector_log.py +56 -0
- tactus/adapters/file_storage.py +367 -0
- tactus/adapters/http_callback_log.py +109 -0
- tactus/adapters/ide_log.py +71 -0
- tactus/adapters/lua_tools.py +336 -0
- tactus/adapters/mcp.py +289 -0
- tactus/adapters/mcp_manager.py +196 -0
- tactus/adapters/memory.py +53 -0
- tactus/adapters/plugins.py +419 -0
- tactus/backends/http_backend.py +58 -0
- tactus/backends/model_backend.py +35 -0
- tactus/backends/pytorch_backend.py +110 -0
- tactus/broker/__init__.py +12 -0
- tactus/broker/client.py +247 -0
- tactus/broker/protocol.py +183 -0
- tactus/broker/server.py +1123 -0
- tactus/broker/stdio.py +12 -0
- tactus/cli/__init__.py +7 -0
- tactus/cli/app.py +2245 -0
- tactus/cli/commands/__init__.py +0 -0
- tactus/core/__init__.py +32 -0
- tactus/core/config_manager.py +790 -0
- tactus/core/dependencies/__init__.py +14 -0
- tactus/core/dependencies/registry.py +180 -0
- tactus/core/dsl_stubs.py +2117 -0
- tactus/core/exceptions.py +66 -0
- tactus/core/execution_context.py +480 -0
- tactus/core/lua_sandbox.py +508 -0
- tactus/core/message_history_manager.py +236 -0
- tactus/core/mocking.py +286 -0
- tactus/core/output_validator.py +291 -0
- tactus/core/registry.py +499 -0
- tactus/core/runtime.py +2907 -0
- tactus/core/template_resolver.py +142 -0
- tactus/core/yaml_parser.py +301 -0
- tactus/docker/Dockerfile +61 -0
- tactus/docker/entrypoint.sh +69 -0
- tactus/dspy/__init__.py +39 -0
- tactus/dspy/agent.py +1144 -0
- tactus/dspy/broker_lm.py +181 -0
- tactus/dspy/config.py +212 -0
- tactus/dspy/history.py +196 -0
- tactus/dspy/module.py +405 -0
- tactus/dspy/prediction.py +318 -0
- tactus/dspy/signature.py +185 -0
- tactus/formatting/__init__.py +7 -0
- tactus/formatting/formatter.py +437 -0
- tactus/ide/__init__.py +9 -0
- tactus/ide/coding_assistant.py +343 -0
- tactus/ide/server.py +2223 -0
- tactus/primitives/__init__.py +49 -0
- tactus/primitives/control.py +168 -0
- tactus/primitives/file.py +229 -0
- tactus/primitives/handles.py +378 -0
- tactus/primitives/host.py +94 -0
- tactus/primitives/human.py +342 -0
- tactus/primitives/json.py +189 -0
- tactus/primitives/log.py +187 -0
- tactus/primitives/message_history.py +157 -0
- tactus/primitives/model.py +163 -0
- tactus/primitives/procedure.py +564 -0
- tactus/primitives/procedure_callable.py +318 -0
- tactus/primitives/retry.py +155 -0
- tactus/primitives/session.py +152 -0
- tactus/primitives/state.py +182 -0
- tactus/primitives/step.py +209 -0
- tactus/primitives/system.py +93 -0
- tactus/primitives/tool.py +375 -0
- tactus/primitives/tool_handle.py +279 -0
- tactus/primitives/toolset.py +229 -0
- tactus/protocols/__init__.py +38 -0
- tactus/protocols/chat_recorder.py +81 -0
- tactus/protocols/config.py +97 -0
- tactus/protocols/cost.py +31 -0
- tactus/protocols/hitl.py +71 -0
- tactus/protocols/log_handler.py +27 -0
- tactus/protocols/models.py +355 -0
- tactus/protocols/result.py +33 -0
- tactus/protocols/storage.py +90 -0
- tactus/providers/__init__.py +13 -0
- tactus/providers/base.py +92 -0
- tactus/providers/bedrock.py +117 -0
- tactus/providers/google.py +105 -0
- tactus/providers/openai.py +98 -0
- tactus/sandbox/__init__.py +63 -0
- tactus/sandbox/config.py +171 -0
- tactus/sandbox/container_runner.py +1099 -0
- tactus/sandbox/docker_manager.py +433 -0
- tactus/sandbox/entrypoint.py +227 -0
- tactus/sandbox/protocol.py +213 -0
- tactus/stdlib/__init__.py +10 -0
- tactus/stdlib/io/__init__.py +13 -0
- tactus/stdlib/io/csv.py +88 -0
- tactus/stdlib/io/excel.py +136 -0
- tactus/stdlib/io/file.py +90 -0
- tactus/stdlib/io/fs.py +154 -0
- tactus/stdlib/io/hdf5.py +121 -0
- tactus/stdlib/io/json.py +109 -0
- tactus/stdlib/io/parquet.py +83 -0
- tactus/stdlib/io/tsv.py +88 -0
- tactus/stdlib/loader.py +274 -0
- tactus/stdlib/tac/tactus/tools/done.tac +33 -0
- tactus/stdlib/tac/tactus/tools/log.tac +50 -0
- tactus/testing/README.md +273 -0
- tactus/testing/__init__.py +61 -0
- tactus/testing/behave_integration.py +380 -0
- tactus/testing/context.py +486 -0
- tactus/testing/eval_models.py +114 -0
- tactus/testing/evaluation_runner.py +222 -0
- tactus/testing/evaluators.py +634 -0
- tactus/testing/events.py +94 -0
- tactus/testing/gherkin_parser.py +134 -0
- tactus/testing/mock_agent.py +315 -0
- tactus/testing/mock_dependencies.py +234 -0
- tactus/testing/mock_hitl.py +171 -0
- tactus/testing/mock_registry.py +168 -0
- tactus/testing/mock_tools.py +133 -0
- tactus/testing/models.py +115 -0
- tactus/testing/pydantic_eval_runner.py +508 -0
- tactus/testing/steps/__init__.py +13 -0
- tactus/testing/steps/builtin.py +902 -0
- tactus/testing/steps/custom.py +69 -0
- tactus/testing/steps/registry.py +68 -0
- tactus/testing/test_runner.py +489 -0
- tactus/tracing/__init__.py +5 -0
- tactus/tracing/trace_manager.py +417 -0
- tactus/utils/__init__.py +1 -0
- tactus/utils/cost_calculator.py +72 -0
- tactus/utils/model_pricing.py +132 -0
- tactus/utils/safe_file_library.py +502 -0
- tactus/utils/safe_libraries.py +234 -0
- tactus/validation/LuaLexerBase.py +66 -0
- tactus/validation/LuaParserBase.py +23 -0
- tactus/validation/README.md +224 -0
- tactus/validation/__init__.py +7 -0
- tactus/validation/error_listener.py +21 -0
- tactus/validation/generated/LuaLexer.interp +231 -0
- tactus/validation/generated/LuaLexer.py +5548 -0
- tactus/validation/generated/LuaLexer.tokens +124 -0
- tactus/validation/generated/LuaLexerBase.py +66 -0
- tactus/validation/generated/LuaParser.interp +173 -0
- tactus/validation/generated/LuaParser.py +6439 -0
- tactus/validation/generated/LuaParser.tokens +124 -0
- tactus/validation/generated/LuaParserBase.py +23 -0
- tactus/validation/generated/LuaParserVisitor.py +118 -0
- tactus/validation/generated/__init__.py +7 -0
- tactus/validation/grammar/LuaLexer.g4 +123 -0
- tactus/validation/grammar/LuaParser.g4 +178 -0
- tactus/validation/semantic_visitor.py +817 -0
- tactus/validation/validator.py +157 -0
- tactus-0.31.2.dist-info/METADATA +1809 -0
- tactus-0.31.2.dist-info/RECORD +160 -0
- tactus-0.31.2.dist-info/WHEEL +4 -0
- tactus-0.31.2.dist-info/entry_points.txt +2 -0
- tactus-0.31.2.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
SEMI=1
|
|
2
|
+
EQ=2
|
|
3
|
+
BREAK=3
|
|
4
|
+
GOTO=4
|
|
5
|
+
DO=5
|
|
6
|
+
END=6
|
|
7
|
+
WHILE=7
|
|
8
|
+
REPEAT=8
|
|
9
|
+
UNTIL=9
|
|
10
|
+
IF=10
|
|
11
|
+
THEN=11
|
|
12
|
+
ELSEIF=12
|
|
13
|
+
ELSE=13
|
|
14
|
+
FOR=14
|
|
15
|
+
COMMA=15
|
|
16
|
+
IN=16
|
|
17
|
+
FUNCTION=17
|
|
18
|
+
LOCAL=18
|
|
19
|
+
LT=19
|
|
20
|
+
GT=20
|
|
21
|
+
RETURN=21
|
|
22
|
+
CONTINUE=22
|
|
23
|
+
CC=23
|
|
24
|
+
NIL=24
|
|
25
|
+
FALSE=25
|
|
26
|
+
TRUE=26
|
|
27
|
+
DOT=27
|
|
28
|
+
SQUIG=28
|
|
29
|
+
MINUS=29
|
|
30
|
+
POUND=30
|
|
31
|
+
OP=31
|
|
32
|
+
CP=32
|
|
33
|
+
NOT=33
|
|
34
|
+
LL=34
|
|
35
|
+
GG=35
|
|
36
|
+
AMP=36
|
|
37
|
+
SS=37
|
|
38
|
+
PER=38
|
|
39
|
+
COL=39
|
|
40
|
+
LE=40
|
|
41
|
+
GE=41
|
|
42
|
+
AND=42
|
|
43
|
+
OR=43
|
|
44
|
+
PLUS=44
|
|
45
|
+
STAR=45
|
|
46
|
+
OCU=46
|
|
47
|
+
CCU=47
|
|
48
|
+
OB=48
|
|
49
|
+
CB=49
|
|
50
|
+
EE=50
|
|
51
|
+
DD=51
|
|
52
|
+
PIPE=52
|
|
53
|
+
CARET=53
|
|
54
|
+
SLASH=54
|
|
55
|
+
DDD=55
|
|
56
|
+
SQEQ=56
|
|
57
|
+
NAME=57
|
|
58
|
+
NORMALSTRING=58
|
|
59
|
+
CHARSTRING=59
|
|
60
|
+
LONGSTRING=60
|
|
61
|
+
INT=61
|
|
62
|
+
HEX=62
|
|
63
|
+
FLOAT=63
|
|
64
|
+
HEX_FLOAT=64
|
|
65
|
+
COMMENT=65
|
|
66
|
+
WS=66
|
|
67
|
+
NL=67
|
|
68
|
+
SHEBANG=68
|
|
69
|
+
';'=1
|
|
70
|
+
'='=2
|
|
71
|
+
'break'=3
|
|
72
|
+
'goto'=4
|
|
73
|
+
'do'=5
|
|
74
|
+
'end'=6
|
|
75
|
+
'while'=7
|
|
76
|
+
'repeat'=8
|
|
77
|
+
'until'=9
|
|
78
|
+
'if'=10
|
|
79
|
+
'then'=11
|
|
80
|
+
'elseif'=12
|
|
81
|
+
'else'=13
|
|
82
|
+
'for'=14
|
|
83
|
+
','=15
|
|
84
|
+
'in'=16
|
|
85
|
+
'function'=17
|
|
86
|
+
'local'=18
|
|
87
|
+
'<'=19
|
|
88
|
+
'>'=20
|
|
89
|
+
'return'=21
|
|
90
|
+
'continue'=22
|
|
91
|
+
'::'=23
|
|
92
|
+
'nil'=24
|
|
93
|
+
'false'=25
|
|
94
|
+
'true'=26
|
|
95
|
+
'.'=27
|
|
96
|
+
'~'=28
|
|
97
|
+
'-'=29
|
|
98
|
+
'#'=30
|
|
99
|
+
'('=31
|
|
100
|
+
')'=32
|
|
101
|
+
'not'=33
|
|
102
|
+
'<<'=34
|
|
103
|
+
'>>'=35
|
|
104
|
+
'&'=36
|
|
105
|
+
'//'=37
|
|
106
|
+
'%'=38
|
|
107
|
+
':'=39
|
|
108
|
+
'<='=40
|
|
109
|
+
'>='=41
|
|
110
|
+
'and'=42
|
|
111
|
+
'or'=43
|
|
112
|
+
'+'=44
|
|
113
|
+
'*'=45
|
|
114
|
+
'{'=46
|
|
115
|
+
'}'=47
|
|
116
|
+
'['=48
|
|
117
|
+
']'=49
|
|
118
|
+
'=='=50
|
|
119
|
+
'..'=51
|
|
120
|
+
'|'=52
|
|
121
|
+
'^'=53
|
|
122
|
+
'/'=54
|
|
123
|
+
'...'=55
|
|
124
|
+
'~='=56
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from antlr4 import *
|
|
3
|
+
|
|
4
|
+
if sys.version_info[1] > 5:
|
|
5
|
+
from typing import TextIO
|
|
6
|
+
else:
|
|
7
|
+
from typing.io import TextIO
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class LuaParserBase(Parser):
|
|
11
|
+
debug = False
|
|
12
|
+
|
|
13
|
+
def __init__(self, input: TokenStream, output: TextIO = sys.stdout):
|
|
14
|
+
super().__init__(input, output)
|
|
15
|
+
|
|
16
|
+
def IsFunctionCall(self) -> bool:
|
|
17
|
+
la = self._input.LT(1)
|
|
18
|
+
if la.type != self.NAME:
|
|
19
|
+
return False
|
|
20
|
+
la = self._input.LT(2)
|
|
21
|
+
if la.type == self.OP:
|
|
22
|
+
return False
|
|
23
|
+
return True
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Generated from /work/tactus/validation/grammar/LuaParser.g4 by ANTLR 4.13.1
|
|
2
|
+
from antlr4 import *
|
|
3
|
+
|
|
4
|
+
if "." in __name__:
|
|
5
|
+
from .LuaParser import LuaParser
|
|
6
|
+
else:
|
|
7
|
+
from LuaParser import LuaParser
|
|
8
|
+
|
|
9
|
+
# This class defines a complete generic visitor for a parse tree produced by LuaParser.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class LuaParserVisitor(ParseTreeVisitor):
|
|
13
|
+
# Visit a parse tree produced by LuaParser#start_.
|
|
14
|
+
def visitStart_(self, ctx: LuaParser.Start_Context):
|
|
15
|
+
return self.visitChildren(ctx)
|
|
16
|
+
|
|
17
|
+
# Visit a parse tree produced by LuaParser#chunk.
|
|
18
|
+
def visitChunk(self, ctx: LuaParser.ChunkContext):
|
|
19
|
+
return self.visitChildren(ctx)
|
|
20
|
+
|
|
21
|
+
# Visit a parse tree produced by LuaParser#block.
|
|
22
|
+
def visitBlock(self, ctx: LuaParser.BlockContext):
|
|
23
|
+
return self.visitChildren(ctx)
|
|
24
|
+
|
|
25
|
+
# Visit a parse tree produced by LuaParser#stat.
|
|
26
|
+
def visitStat(self, ctx: LuaParser.StatContext):
|
|
27
|
+
return self.visitChildren(ctx)
|
|
28
|
+
|
|
29
|
+
# Visit a parse tree produced by LuaParser#attnamelist.
|
|
30
|
+
def visitAttnamelist(self, ctx: LuaParser.AttnamelistContext):
|
|
31
|
+
return self.visitChildren(ctx)
|
|
32
|
+
|
|
33
|
+
# Visit a parse tree produced by LuaParser#attrib.
|
|
34
|
+
def visitAttrib(self, ctx: LuaParser.AttribContext):
|
|
35
|
+
return self.visitChildren(ctx)
|
|
36
|
+
|
|
37
|
+
# Visit a parse tree produced by LuaParser#retstat.
|
|
38
|
+
def visitRetstat(self, ctx: LuaParser.RetstatContext):
|
|
39
|
+
return self.visitChildren(ctx)
|
|
40
|
+
|
|
41
|
+
# Visit a parse tree produced by LuaParser#label.
|
|
42
|
+
def visitLabel(self, ctx: LuaParser.LabelContext):
|
|
43
|
+
return self.visitChildren(ctx)
|
|
44
|
+
|
|
45
|
+
# Visit a parse tree produced by LuaParser#funcname.
|
|
46
|
+
def visitFuncname(self, ctx: LuaParser.FuncnameContext):
|
|
47
|
+
return self.visitChildren(ctx)
|
|
48
|
+
|
|
49
|
+
# Visit a parse tree produced by LuaParser#varlist.
|
|
50
|
+
def visitVarlist(self, ctx: LuaParser.VarlistContext):
|
|
51
|
+
return self.visitChildren(ctx)
|
|
52
|
+
|
|
53
|
+
# Visit a parse tree produced by LuaParser#namelist.
|
|
54
|
+
def visitNamelist(self, ctx: LuaParser.NamelistContext):
|
|
55
|
+
return self.visitChildren(ctx)
|
|
56
|
+
|
|
57
|
+
# Visit a parse tree produced by LuaParser#explist.
|
|
58
|
+
def visitExplist(self, ctx: LuaParser.ExplistContext):
|
|
59
|
+
return self.visitChildren(ctx)
|
|
60
|
+
|
|
61
|
+
# Visit a parse tree produced by LuaParser#exp.
|
|
62
|
+
def visitExp(self, ctx: LuaParser.ExpContext):
|
|
63
|
+
return self.visitChildren(ctx)
|
|
64
|
+
|
|
65
|
+
# Visit a parse tree produced by LuaParser#var.
|
|
66
|
+
def visitVar(self, ctx: LuaParser.VarContext):
|
|
67
|
+
return self.visitChildren(ctx)
|
|
68
|
+
|
|
69
|
+
# Visit a parse tree produced by LuaParser#prefixexp.
|
|
70
|
+
def visitPrefixexp(self, ctx: LuaParser.PrefixexpContext):
|
|
71
|
+
return self.visitChildren(ctx)
|
|
72
|
+
|
|
73
|
+
# Visit a parse tree produced by LuaParser#functioncall.
|
|
74
|
+
def visitFunctioncall(self, ctx: LuaParser.FunctioncallContext):
|
|
75
|
+
return self.visitChildren(ctx)
|
|
76
|
+
|
|
77
|
+
# Visit a parse tree produced by LuaParser#args.
|
|
78
|
+
def visitArgs(self, ctx: LuaParser.ArgsContext):
|
|
79
|
+
return self.visitChildren(ctx)
|
|
80
|
+
|
|
81
|
+
# Visit a parse tree produced by LuaParser#functiondef.
|
|
82
|
+
def visitFunctiondef(self, ctx: LuaParser.FunctiondefContext):
|
|
83
|
+
return self.visitChildren(ctx)
|
|
84
|
+
|
|
85
|
+
# Visit a parse tree produced by LuaParser#funcbody.
|
|
86
|
+
def visitFuncbody(self, ctx: LuaParser.FuncbodyContext):
|
|
87
|
+
return self.visitChildren(ctx)
|
|
88
|
+
|
|
89
|
+
# Visit a parse tree produced by LuaParser#parlist.
|
|
90
|
+
def visitParlist(self, ctx: LuaParser.ParlistContext):
|
|
91
|
+
return self.visitChildren(ctx)
|
|
92
|
+
|
|
93
|
+
# Visit a parse tree produced by LuaParser#tableconstructor.
|
|
94
|
+
def visitTableconstructor(self, ctx: LuaParser.TableconstructorContext):
|
|
95
|
+
return self.visitChildren(ctx)
|
|
96
|
+
|
|
97
|
+
# Visit a parse tree produced by LuaParser#fieldlist.
|
|
98
|
+
def visitFieldlist(self, ctx: LuaParser.FieldlistContext):
|
|
99
|
+
return self.visitChildren(ctx)
|
|
100
|
+
|
|
101
|
+
# Visit a parse tree produced by LuaParser#field.
|
|
102
|
+
def visitField(self, ctx: LuaParser.FieldContext):
|
|
103
|
+
return self.visitChildren(ctx)
|
|
104
|
+
|
|
105
|
+
# Visit a parse tree produced by LuaParser#fieldsep.
|
|
106
|
+
def visitFieldsep(self, ctx: LuaParser.FieldsepContext):
|
|
107
|
+
return self.visitChildren(ctx)
|
|
108
|
+
|
|
109
|
+
# Visit a parse tree produced by LuaParser#number.
|
|
110
|
+
def visitNumber(self, ctx: LuaParser.NumberContext):
|
|
111
|
+
return self.visitChildren(ctx)
|
|
112
|
+
|
|
113
|
+
# Visit a parse tree produced by LuaParser#string.
|
|
114
|
+
def visitString(self, ctx: LuaParser.StringContext):
|
|
115
|
+
return self.visitChildren(ctx)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
del LuaParser
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// $antlr-format alignTrailingComments true, columnLimit 150, maxEmptyLinesToKeep 1, reflowComments false, useTab false
|
|
2
|
+
// $antlr-format allowShortRulesOnASingleLine true, allowShortBlocksOnASingleLine true, minEmptyLines 0, alignSemicolons ownLine
|
|
3
|
+
// $antlr-format alignColons trailing, singleLineOverrulesHangingColon true, alignLexerCommands true, alignLabels true, alignTrailers true
|
|
4
|
+
|
|
5
|
+
lexer grammar LuaLexer;
|
|
6
|
+
|
|
7
|
+
options {
|
|
8
|
+
superClass = LuaLexerBase;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Insert here @header for lexer.
|
|
12
|
+
|
|
13
|
+
SEMI : ';';
|
|
14
|
+
EQ : '=';
|
|
15
|
+
|
|
16
|
+
BREAK : 'break';
|
|
17
|
+
GOTO : 'goto';
|
|
18
|
+
DO : 'do';
|
|
19
|
+
END : 'end';
|
|
20
|
+
WHILE : 'while';
|
|
21
|
+
REPEAT : 'repeat';
|
|
22
|
+
UNTIL : 'until';
|
|
23
|
+
IF : 'if';
|
|
24
|
+
THEN : 'then';
|
|
25
|
+
ELSEIF : 'elseif';
|
|
26
|
+
ELSE : 'else';
|
|
27
|
+
FOR : 'for';
|
|
28
|
+
COMMA : ',';
|
|
29
|
+
IN : 'in';
|
|
30
|
+
FUNCTION : 'function';
|
|
31
|
+
LOCAL : 'local';
|
|
32
|
+
LT : '<';
|
|
33
|
+
GT : '>';
|
|
34
|
+
RETURN : 'return';
|
|
35
|
+
CONTINUE : 'continue';
|
|
36
|
+
CC : '::';
|
|
37
|
+
NIL : 'nil';
|
|
38
|
+
FALSE : 'false';
|
|
39
|
+
TRUE : 'true';
|
|
40
|
+
DOT : '.';
|
|
41
|
+
SQUIG : '~';
|
|
42
|
+
MINUS : '-';
|
|
43
|
+
POUND : '#';
|
|
44
|
+
OP : '(';
|
|
45
|
+
CP : ')';
|
|
46
|
+
NOT : 'not';
|
|
47
|
+
LL : '<<';
|
|
48
|
+
GG : '>>';
|
|
49
|
+
AMP : '&';
|
|
50
|
+
SS : '//';
|
|
51
|
+
PER : '%';
|
|
52
|
+
COL : ':';
|
|
53
|
+
LE : '<=';
|
|
54
|
+
GE : '>=';
|
|
55
|
+
AND : 'and';
|
|
56
|
+
OR : 'or';
|
|
57
|
+
PLUS : '+';
|
|
58
|
+
STAR : '*';
|
|
59
|
+
OCU : '{';
|
|
60
|
+
CCU : '}';
|
|
61
|
+
OB : '[';
|
|
62
|
+
CB : ']';
|
|
63
|
+
EE : '==';
|
|
64
|
+
DD : '..';
|
|
65
|
+
PIPE : '|';
|
|
66
|
+
CARET : '^';
|
|
67
|
+
SLASH : '/';
|
|
68
|
+
DDD : '...';
|
|
69
|
+
SQEQ : '~=';
|
|
70
|
+
|
|
71
|
+
NAME: [a-zA-Z_][a-zA-Z_0-9]*;
|
|
72
|
+
|
|
73
|
+
NORMALSTRING: '"' ( EscapeSequence | ~('\\' | '"'))* '"';
|
|
74
|
+
|
|
75
|
+
CHARSTRING: '\'' ( EscapeSequence | ~('\'' | '\\'))* '\'';
|
|
76
|
+
|
|
77
|
+
LONGSTRING: '[' NESTED_STR ']';
|
|
78
|
+
|
|
79
|
+
fragment NESTED_STR: '=' NESTED_STR '=' | '[' .*? ']';
|
|
80
|
+
|
|
81
|
+
INT: Digit+;
|
|
82
|
+
|
|
83
|
+
HEX: '0' [xX] HexDigit+;
|
|
84
|
+
|
|
85
|
+
FLOAT: Digit+ '.' Digit* ExponentPart? | '.' Digit+ ExponentPart? | Digit+ ExponentPart;
|
|
86
|
+
|
|
87
|
+
HEX_FLOAT:
|
|
88
|
+
'0' [xX] HexDigit+ '.' HexDigit* HexExponentPart?
|
|
89
|
+
| '0' [xX] '.' HexDigit+ HexExponentPart?
|
|
90
|
+
| '0' [xX] HexDigit+ HexExponentPart
|
|
91
|
+
;
|
|
92
|
+
|
|
93
|
+
fragment ExponentPart: [eE] [+-]? Digit+;
|
|
94
|
+
|
|
95
|
+
fragment HexExponentPart: [pP] [+-]? Digit+;
|
|
96
|
+
|
|
97
|
+
fragment EscapeSequence:
|
|
98
|
+
'\\' [abfnrtvz"'|$#\\] // World of Warcraft Lua additionally escapes |$#
|
|
99
|
+
| '\\' '\r'? '\n'
|
|
100
|
+
| DecimalEscape
|
|
101
|
+
| HexEscape
|
|
102
|
+
| UtfEscape
|
|
103
|
+
;
|
|
104
|
+
|
|
105
|
+
fragment DecimalEscape: '\\' Digit | '\\' Digit Digit | '\\' [0-2] Digit Digit;
|
|
106
|
+
|
|
107
|
+
fragment HexEscape: '\\' 'x' HexDigit HexDigit;
|
|
108
|
+
|
|
109
|
+
fragment UtfEscape: '\\' 'u{' HexDigit+ '}';
|
|
110
|
+
|
|
111
|
+
fragment Digit: [0-9];
|
|
112
|
+
|
|
113
|
+
fragment HexDigit: [0-9a-fA-F];
|
|
114
|
+
|
|
115
|
+
fragment SingleLineInputCharacter: ~[\r\n\u0085\u2028\u2029];
|
|
116
|
+
|
|
117
|
+
COMMENT: '--' { this.HandleComment(); } -> channel(HIDDEN);
|
|
118
|
+
|
|
119
|
+
WS: [ \t\u000C\r]+ -> channel(HIDDEN);
|
|
120
|
+
|
|
121
|
+
NL: [\n] -> channel(2);
|
|
122
|
+
|
|
123
|
+
SHEBANG: '#' { this.IsLine1Col0() }? '!'? SingleLineInputCharacter* -> channel(HIDDEN);
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
MIT license
|
|
4
|
+
|
|
5
|
+
Author: Ken Domino, October 2023
|
|
6
|
+
|
|
7
|
+
Based on previous work of: Kazunori Sakamoto, Alexander Alexeev
|
|
8
|
+
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// $antlr-format alignTrailingComments true, columnLimit 150, minEmptyLines 1, maxEmptyLinesToKeep 1, reflowComments false, useTab false
|
|
12
|
+
// $antlr-format allowShortRulesOnASingleLine false, allowShortBlocksOnASingleLine true, alignSemicolons hanging, alignColons hanging
|
|
13
|
+
|
|
14
|
+
parser grammar LuaParser;
|
|
15
|
+
|
|
16
|
+
options {
|
|
17
|
+
tokenVocab = LuaLexer;
|
|
18
|
+
superClass = LuaParserBase;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Insert here @header for parser.
|
|
22
|
+
|
|
23
|
+
start_
|
|
24
|
+
: chunk EOF
|
|
25
|
+
;
|
|
26
|
+
|
|
27
|
+
chunk
|
|
28
|
+
: block
|
|
29
|
+
;
|
|
30
|
+
|
|
31
|
+
block
|
|
32
|
+
: stat* retstat?
|
|
33
|
+
;
|
|
34
|
+
|
|
35
|
+
stat
|
|
36
|
+
: ';'
|
|
37
|
+
| varlist '=' explist
|
|
38
|
+
| functioncall
|
|
39
|
+
| label
|
|
40
|
+
| 'break'
|
|
41
|
+
| 'goto' NAME
|
|
42
|
+
| 'do' block 'end'
|
|
43
|
+
| 'while' exp 'do' block 'end'
|
|
44
|
+
| 'repeat' block 'until' exp
|
|
45
|
+
| 'if' exp 'then' block ('elseif' exp 'then' block)* ('else' block)? 'end'
|
|
46
|
+
| 'for' NAME '=' exp ',' exp (',' exp)? 'do' block 'end'
|
|
47
|
+
| 'for' namelist 'in' explist 'do' block 'end'
|
|
48
|
+
| 'function' funcname funcbody
|
|
49
|
+
| 'local' 'function' NAME funcbody
|
|
50
|
+
| 'local' attnamelist ('=' explist)?
|
|
51
|
+
;
|
|
52
|
+
|
|
53
|
+
attnamelist
|
|
54
|
+
: NAME attrib (',' NAME attrib)*
|
|
55
|
+
;
|
|
56
|
+
|
|
57
|
+
attrib
|
|
58
|
+
: ('<' NAME '>')?
|
|
59
|
+
;
|
|
60
|
+
|
|
61
|
+
retstat
|
|
62
|
+
: 'return' explist? ';'?
|
|
63
|
+
;
|
|
64
|
+
|
|
65
|
+
label
|
|
66
|
+
: '::' NAME '::'
|
|
67
|
+
;
|
|
68
|
+
|
|
69
|
+
funcname
|
|
70
|
+
: NAME ('.' NAME)* (':' NAME)?
|
|
71
|
+
;
|
|
72
|
+
|
|
73
|
+
varlist
|
|
74
|
+
: var (',' var)*
|
|
75
|
+
;
|
|
76
|
+
|
|
77
|
+
namelist
|
|
78
|
+
: NAME (',' NAME)*
|
|
79
|
+
;
|
|
80
|
+
|
|
81
|
+
explist
|
|
82
|
+
: exp (',' exp)*
|
|
83
|
+
;
|
|
84
|
+
|
|
85
|
+
exp
|
|
86
|
+
: 'nil'
|
|
87
|
+
| 'false'
|
|
88
|
+
| 'true'
|
|
89
|
+
| number
|
|
90
|
+
| string
|
|
91
|
+
| '...'
|
|
92
|
+
| functiondef
|
|
93
|
+
| prefixexp
|
|
94
|
+
| tableconstructor
|
|
95
|
+
| <assoc = right> exp ('^') exp
|
|
96
|
+
| ('not' | '#' | '-' | '~') exp
|
|
97
|
+
| exp ('*' | '/' | '%' | '//') exp
|
|
98
|
+
| exp ('+' | '-') exp
|
|
99
|
+
| <assoc = right> exp ('..') exp
|
|
100
|
+
| exp ('<' | '>' | '<=' | '>=' | '~=' | '==') exp
|
|
101
|
+
| exp ('and') exp
|
|
102
|
+
| exp ('or') exp
|
|
103
|
+
| exp ('&' | '|' | '~' | '<<' | '>>') exp
|
|
104
|
+
;
|
|
105
|
+
|
|
106
|
+
// var ::= Name | prefixexp '[' exp ']' | prefixexp '.' Name
|
|
107
|
+
var
|
|
108
|
+
: NAME
|
|
109
|
+
| prefixexp ('[' exp ']' | '.' NAME)
|
|
110
|
+
;
|
|
111
|
+
|
|
112
|
+
// prefixexp ::= var | functioncall | '(' exp ')'
|
|
113
|
+
prefixexp
|
|
114
|
+
: { this.IsFunctionCall() }? NAME ( '[' exp ']' | '.' NAME )*
|
|
115
|
+
| functioncall ( '[' exp ']' | '.' NAME )*
|
|
116
|
+
| '(' exp ')' ( '[' exp ']' | '.' NAME )*
|
|
117
|
+
;
|
|
118
|
+
|
|
119
|
+
// functioncall ::= prefixexp args | prefixexp ':' Name args;
|
|
120
|
+
functioncall
|
|
121
|
+
: ( ( NAME | '(' exp ')' ) ( '[' exp ']' | '.' NAME )* ( args | ':' NAME args ) ) ( ( '[' exp ']' | '.' NAME )* ( args | ':' NAME args ) )*
|
|
122
|
+
;
|
|
123
|
+
|
|
124
|
+
args
|
|
125
|
+
: '(' explist? ')'
|
|
126
|
+
| tableconstructor
|
|
127
|
+
| string
|
|
128
|
+
;
|
|
129
|
+
|
|
130
|
+
functiondef
|
|
131
|
+
: 'function' funcbody
|
|
132
|
+
;
|
|
133
|
+
|
|
134
|
+
funcbody
|
|
135
|
+
: '(' parlist ')' block 'end'
|
|
136
|
+
;
|
|
137
|
+
|
|
138
|
+
/* lparser.c says "is 'parlist' not empty?"
|
|
139
|
+
* That code does so by checking la(1) == ')'.
|
|
140
|
+
* This means that parlist can derive empty.
|
|
141
|
+
*/
|
|
142
|
+
parlist
|
|
143
|
+
: namelist (',' '...')?
|
|
144
|
+
| '...'
|
|
145
|
+
|
|
|
146
|
+
;
|
|
147
|
+
|
|
148
|
+
tableconstructor
|
|
149
|
+
: '{' fieldlist? '}'
|
|
150
|
+
;
|
|
151
|
+
|
|
152
|
+
fieldlist
|
|
153
|
+
: field (fieldsep field)* fieldsep?
|
|
154
|
+
;
|
|
155
|
+
|
|
156
|
+
field
|
|
157
|
+
: '[' exp ']' '=' exp
|
|
158
|
+
| NAME '=' exp
|
|
159
|
+
| exp
|
|
160
|
+
;
|
|
161
|
+
|
|
162
|
+
fieldsep
|
|
163
|
+
: ','
|
|
164
|
+
| ';'
|
|
165
|
+
;
|
|
166
|
+
|
|
167
|
+
number
|
|
168
|
+
: INT
|
|
169
|
+
| HEX
|
|
170
|
+
| FLOAT
|
|
171
|
+
| HEX_FLOAT
|
|
172
|
+
;
|
|
173
|
+
|
|
174
|
+
string
|
|
175
|
+
: NORMALSTRING
|
|
176
|
+
| CHARSTRING
|
|
177
|
+
| LONGSTRING
|
|
178
|
+
;
|