Try fix compatibility with old antlr

This commit is contained in:
mcDandy
2026-05-14 14:18:41 +02:00
parent d4cbefc986
commit 11be4840ce
21 changed files with 21051 additions and 8 deletions
+5 -2
View File
@@ -1,12 +1,15 @@
import time
from token import OP
import sys
import torch
import math
import inspect
import torch.nn.functional as F
from . import optical_flow_utils as ofu
from antlr4 import TerminalNode
from .MathExprVisitor import MathExprVisitor
from .antlr_router import get_antlr_modules
_, _, MathExprVisitor = get_antlr_modules()
from ..helper_functions import generate_dim_variables
from ..noise_utils import NoiseUtils
import struct
View File
+26
View File
@@ -0,0 +1,26 @@
import sys
import antlr4
def get_antlr_modules():
runtime_version = "0.0.0"
try:
if sys.version_info >= (3, 8):
import importlib.metadata
runtime_version = importlib.metadata.version("antlr4-python3-runtime")
else:
import pkg_resources
runtime_version = pkg_resources.get_distribution("antlr4-python3-runtime").version
except Exception:
runtime_version = getattr(antlr4, "__version__", "4.13.2")
if runtime_version.startswith("4.9"):
from .legacy.MathExprLexer import MathExprLexer
from .legacy.MathExprParser import MathExprParser
from .legacy.MathExprVisitor import MathExprVisitor
else:
from .grammer.MathExprLexer import MathExprLexer
from .grammer.MathExprParser import MathExprParser
from .grammer.MathExprVisitor import MathExprVisitor
return MathExprLexer, MathExprParser, MathExprVisitor
+3
View File
@@ -0,0 +1,3 @@
antlr4 -v 4.9.3 -Dlanguage=Python3 -visitor -o ./legacy MathExpr.g4
antlr4 -v 4.13.2 -Dlanguage=Python3 -visitor -o ./grammer MathExpr.g4
@@ -1,4 +1,4 @@
# Generated from ./MathExpr.g4 by ANTLR 4.13.2
# Generated from MathExpr.g4 by ANTLR 4.13.2
from antlr4 import *
from io import StringIO
import sys
@@ -1,4 +1,4 @@
# Generated from ./MathExpr.g4 by ANTLR 4.13.2
# Generated from MathExpr.g4 by ANTLR 4.13.2
from antlr4 import *
if "." in __name__:
from .MathExprParser import MathExprParser
@@ -1,4 +1,4 @@
# Generated from ./MathExpr.g4 by ANTLR 4.13.2
# Generated from MathExpr.g4 by ANTLR 4.13.2
# encoding: utf-8
from antlr4 import *
from io import StringIO
@@ -1,4 +1,4 @@
# Generated from ./MathExpr.g4 by ANTLR 4.13.2
# Generated from MathExpr.g4 by ANTLR 4.13.2
from antlr4 import *
if "." in __name__:
from .MathExprParser import MathExprParser
File diff suppressed because one or more lines are too long
+385
View File
@@ -0,0 +1,385 @@
SIN=1
COS=2
TAN=3
ASIN=4
ACOS=5
ATAN=6
ATAN2=7
SINH=8
COSH=9
TANH=10
ASINH=11
ACOSH=12
ATANH=13
ABS=14
SQRT=15
LN=16
LOG=17
EXP=18
SMIN=19
SMAX=20
TMIN=21
TMAX=22
TNORM=23
SNORM=24
FLOOR=25
CEIL=26
ROUND=27
GAMMA=28
POWE=29
SIGM=30
CLAMP=31
SFFT=32
SIFFT=33
ANGL=34
PRNT=35
PRINT_SHAPE=36
NVL=37
LERP=38
STEP=39
SMOOTHSTEP=40
FRACT=41
RELU=42
SOFTPLUS=43
GELU=44
SIGN=45
MAP=46
EZCONV=47
CONV=48
SWAP=49
PERM=50
RESHAPE=51
RANGE=52
LINSPACE=53
LOGSPACE=54
TOPK=55
BOTK=56
PINV=57
SUM=58
MEAN=59
STD=60
VAR=61
QUARTILE=62
PERCENTILE=63
QUANTILE=64
DOT=65
MOMENT=66
ERF=67
ERFINV=68
ANY=69
ALL=70
EDGE=71
GAUSSIAN=72
MEDIAN=73
MODE=74
CUMSUM=75
CUMPROD=76
TOPK_IND=77
BOTK_IND=78
CUBIC_EASE=79
ELASTIC_EASE=80
SINE_EASE=81
SMOOTHERSTEP=82
DIST=83
REMAP=84
COSSIM=85
COUNT=86
FLATTEN=87
APPEND=88
GET_VALUE=89
FLOW_APPLY=90
BATCH_SHUFFLE=91
MOTION_MASK=92
FLOW_TO_IMAGE=93
FLOW_MAG=94
FLOW_ANG=95
WHERE=96
HISTOGRAM=97
OVERLAY=98
PAD=99
CROSS=100
MATMUL=101
RIFE=102
BNOT=103
BITCOUNT=104
SHAPE=105
BAND=106
XOR=107
BOR=108
TENSOR=109
PUSH=110
POP=111
CLEAR=112
HAS=113
GET=114
CONCAT=115
INT=116
FLOAT=117
UPPER=118
LOWER=119
TRIM=120
SPLIT=121
JOIN=122
SUBSTRING=123
SUBSTR=124
FIND=125
REPLACE=126
DILATE=127
ERODE=128
MORPH_OPEN=129
MORPH_CLOSE=130
RGB_TO_OKLAB=131
RGB_TO_CIELAB=132
OKLAB_TO_RGB=133
CIELAB_TO_RGB=134
RGB_TO_HSV=135
HSV_TO_RGB=136
INT_TO_RGB=137
RGB_TO_INT=138
INTERPOLATE_LINEAR=139
INTERPOLATE_AREA=140
INTERPOLATE_NEAREST=141
IF=142
ELSE=143
WHILE=144
FOR=145
IN=146
BREAK=147
CONTINUE=148
RETURN=149
TIMESTAMP=150
SORT=151
ARGSORT=152
ARGMIN=153
ARGMAX=154
SOFTMAX=155
SOFTMIN=156
UNIQUE=157
FLIP=158
ROLL=159
COV=160
CORR=161
ENTROPY=162
CROP=163
NONE=164
NOISE=165
RAND=166
CAUCHY=167
EXPONENTIAL=168
LOGNORMAL=169
BERNOULLI=170
POISSON=171
GAMMADIST=172
BETADIST=173
LAPLACEDIST=174
GUMBELDIST=175
WEIBULLDIST=176
CHI2DIST=177
STUDENTTDIST=178
PERLIN=179
CELLULAR=180
PLASMA=181
PLUS=182
MINUS=183
MULT=184
DIV=185
MOD=186
POW=187
LSHIFT=188
RSHIFT=189
GE=190
GT=191
LE=192
LT=193
EQ=194
EQUEALS=195
PLUS_EQ=196
MINUS_EQ=197
MULT_EQ=198
DIV_EQ=199
MOD_EQ=200
NE=201
PIPE=202
LPAREN=203
RPAREN=204
COMMA=205
SEMICOLON=206
ARROW=207
LBRACKET=208
RBRACKET=209
QUESTION=210
COLON=211
LBRACE=212
RBRACE=213
NUMBER=214
CONSTANT=215
STRING=216
VARIABLE=217
SL_COMMENT=218
ML_COMMENT=219
WS=220
'sin'=1
'cos'=2
'tan'=3
'asin'=4
'acos'=5
'atan'=6
'atan2'=7
'sinh'=8
'cosh'=9
'tanh'=10
'asinh'=11
'acosh'=12
'atanh'=13
'abs'=14
'sqrt'=15
'ln'=16
'log'=17
'exp'=18
'smin'=19
'smax'=20
'tmin'=21
'tmax'=22
'tnorm'=23
'snorm'=24
'floor'=25
'ceil'=26
'round'=27
'gamma'=28
'pow'=29
'sigm'=30
'clamp'=31
'fft'=32
'ifft'=33
'angle'=34
'print'=35
'lerp'=38
'step'=39
'smoothstep'=40
'fract'=41
'relu'=42
'softplus'=43
'gelu'=44
'sign'=45
'map'=46
'swap'=49
'range'=52
'linspace'=53
'logspace'=54
'topk'=55
'botk'=56
'pinv'=57
'sum'=58
'mean'=59
'std'=60
'var'=61
'quantile'=64
'dot'=65
'moment'=66
'erf'=67
'erfinv'=68
'any'=69
'all'=70
'edge'=71
'median'=73
'mode'=74
'cumsum'=75
'cumprod'=76
'smootherstep'=82
'remap'=84
'flatten'=87
'append'=88
'get_value'=89
'flow_apply'=90
'motion_mask'=92
'flow_to_image'=93
'where'=96
'overlay'=98
'pad'=99
'cross'=100
'matmul'=101
'rife'=102
'shape'=105
'tensor'=109
'stack_push'=110
'stack_pop'=111
'stack_clear'=112
'stack_has'=113
'stack_get'=114
'int'=116
'float'=117
'upper'=118
'lower'=119
'trim'=120
'split'=121
'join'=122
'substring'=123
'substr'=124
'find'=125
'replace'=126
'dilate'=127
'erode'=128
'morph_open'=129
'morph_close'=130
'rgb_to_oklab'=131
'rgb_to_cielab'=132
'oklab_to_rgb'=133
'cielab_to_rgb'=134
'rgb_to_hsv'=135
'hsv_to_rgb'=136
'int_to_rgb'=137
'rgb_to_int'=138
'interpolate_linear'=139
'interpolate_area'=140
'if'=142
'else'=143
'while'=144
'for'=145
'in'=146
'break'=147
'continue'=148
'return'=149
'sort'=151
'argsort'=152
'argmin'=153
'argmax'=154
'softmax'=155
'softmin'=156
'unique'=157
'flip'=158
'roll'=159
'cov'=160
'entropy'=162
'crop'=163
'+'=182
'-'=183
'*'=184
'/'=185
'%'=186
'^'=187
'<<'=188
'>>'=189
'>='=190
'>'=191
'<='=192
'<'=193
'=='=194
'='=195
'+='=196
'-='=197
'*='=198
'/='=199
'%='=200
'!='=201
'|'=202
'('=203
')'=204
','=205
';'=206
'->'=207
'['=208
']'=209
'?'=210
':'=211
'{'=212
'}'=213
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,385 @@
SIN=1
COS=2
TAN=3
ASIN=4
ACOS=5
ATAN=6
ATAN2=7
SINH=8
COSH=9
TANH=10
ASINH=11
ACOSH=12
ATANH=13
ABS=14
SQRT=15
LN=16
LOG=17
EXP=18
SMIN=19
SMAX=20
TMIN=21
TMAX=22
TNORM=23
SNORM=24
FLOOR=25
CEIL=26
ROUND=27
GAMMA=28
POWE=29
SIGM=30
CLAMP=31
SFFT=32
SIFFT=33
ANGL=34
PRNT=35
PRINT_SHAPE=36
NVL=37
LERP=38
STEP=39
SMOOTHSTEP=40
FRACT=41
RELU=42
SOFTPLUS=43
GELU=44
SIGN=45
MAP=46
EZCONV=47
CONV=48
SWAP=49
PERM=50
RESHAPE=51
RANGE=52
LINSPACE=53
LOGSPACE=54
TOPK=55
BOTK=56
PINV=57
SUM=58
MEAN=59
STD=60
VAR=61
QUARTILE=62
PERCENTILE=63
QUANTILE=64
DOT=65
MOMENT=66
ERF=67
ERFINV=68
ANY=69
ALL=70
EDGE=71
GAUSSIAN=72
MEDIAN=73
MODE=74
CUMSUM=75
CUMPROD=76
TOPK_IND=77
BOTK_IND=78
CUBIC_EASE=79
ELASTIC_EASE=80
SINE_EASE=81
SMOOTHERSTEP=82
DIST=83
REMAP=84
COSSIM=85
COUNT=86
FLATTEN=87
APPEND=88
GET_VALUE=89
FLOW_APPLY=90
BATCH_SHUFFLE=91
MOTION_MASK=92
FLOW_TO_IMAGE=93
FLOW_MAG=94
FLOW_ANG=95
WHERE=96
HISTOGRAM=97
OVERLAY=98
PAD=99
CROSS=100
MATMUL=101
RIFE=102
BNOT=103
BITCOUNT=104
SHAPE=105
BAND=106
XOR=107
BOR=108
TENSOR=109
PUSH=110
POP=111
CLEAR=112
HAS=113
GET=114
CONCAT=115
INT=116
FLOAT=117
UPPER=118
LOWER=119
TRIM=120
SPLIT=121
JOIN=122
SUBSTRING=123
SUBSTR=124
FIND=125
REPLACE=126
DILATE=127
ERODE=128
MORPH_OPEN=129
MORPH_CLOSE=130
RGB_TO_OKLAB=131
RGB_TO_CIELAB=132
OKLAB_TO_RGB=133
CIELAB_TO_RGB=134
RGB_TO_HSV=135
HSV_TO_RGB=136
INT_TO_RGB=137
RGB_TO_INT=138
INTERPOLATE_LINEAR=139
INTERPOLATE_AREA=140
INTERPOLATE_NEAREST=141
IF=142
ELSE=143
WHILE=144
FOR=145
IN=146
BREAK=147
CONTINUE=148
RETURN=149
TIMESTAMP=150
SORT=151
ARGSORT=152
ARGMIN=153
ARGMAX=154
SOFTMAX=155
SOFTMIN=156
UNIQUE=157
FLIP=158
ROLL=159
COV=160
CORR=161
ENTROPY=162
CROP=163
NONE=164
NOISE=165
RAND=166
CAUCHY=167
EXPONENTIAL=168
LOGNORMAL=169
BERNOULLI=170
POISSON=171
GAMMADIST=172
BETADIST=173
LAPLACEDIST=174
GUMBELDIST=175
WEIBULLDIST=176
CHI2DIST=177
STUDENTTDIST=178
PERLIN=179
CELLULAR=180
PLASMA=181
PLUS=182
MINUS=183
MULT=184
DIV=185
MOD=186
POW=187
LSHIFT=188
RSHIFT=189
GE=190
GT=191
LE=192
LT=193
EQ=194
EQUEALS=195
PLUS_EQ=196
MINUS_EQ=197
MULT_EQ=198
DIV_EQ=199
MOD_EQ=200
NE=201
PIPE=202
LPAREN=203
RPAREN=204
COMMA=205
SEMICOLON=206
ARROW=207
LBRACKET=208
RBRACKET=209
QUESTION=210
COLON=211
LBRACE=212
RBRACE=213
NUMBER=214
CONSTANT=215
STRING=216
VARIABLE=217
SL_COMMENT=218
ML_COMMENT=219
WS=220
'sin'=1
'cos'=2
'tan'=3
'asin'=4
'acos'=5
'atan'=6
'atan2'=7
'sinh'=8
'cosh'=9
'tanh'=10
'asinh'=11
'acosh'=12
'atanh'=13
'abs'=14
'sqrt'=15
'ln'=16
'log'=17
'exp'=18
'smin'=19
'smax'=20
'tmin'=21
'tmax'=22
'tnorm'=23
'snorm'=24
'floor'=25
'ceil'=26
'round'=27
'gamma'=28
'pow'=29
'sigm'=30
'clamp'=31
'fft'=32
'ifft'=33
'angle'=34
'print'=35
'lerp'=38
'step'=39
'smoothstep'=40
'fract'=41
'relu'=42
'softplus'=43
'gelu'=44
'sign'=45
'map'=46
'swap'=49
'range'=52
'linspace'=53
'logspace'=54
'topk'=55
'botk'=56
'pinv'=57
'sum'=58
'mean'=59
'std'=60
'var'=61
'quantile'=64
'dot'=65
'moment'=66
'erf'=67
'erfinv'=68
'any'=69
'all'=70
'edge'=71
'median'=73
'mode'=74
'cumsum'=75
'cumprod'=76
'smootherstep'=82
'remap'=84
'flatten'=87
'append'=88
'get_value'=89
'flow_apply'=90
'motion_mask'=92
'flow_to_image'=93
'where'=96
'overlay'=98
'pad'=99
'cross'=100
'matmul'=101
'rife'=102
'shape'=105
'tensor'=109
'stack_push'=110
'stack_pop'=111
'stack_clear'=112
'stack_has'=113
'stack_get'=114
'int'=116
'float'=117
'upper'=118
'lower'=119
'trim'=120
'split'=121
'join'=122
'substring'=123
'substr'=124
'find'=125
'replace'=126
'dilate'=127
'erode'=128
'morph_open'=129
'morph_close'=130
'rgb_to_oklab'=131
'rgb_to_cielab'=132
'oklab_to_rgb'=133
'cielab_to_rgb'=134
'rgb_to_hsv'=135
'hsv_to_rgb'=136
'int_to_rgb'=137
'rgb_to_int'=138
'interpolate_linear'=139
'interpolate_area'=140
'if'=142
'else'=143
'while'=144
'for'=145
'in'=146
'break'=147
'continue'=148
'return'=149
'sort'=151
'argsort'=152
'argmin'=153
'argmax'=154
'softmax'=155
'softmin'=156
'unique'=157
'flip'=158
'roll'=159
'cov'=160
'entropy'=162
'crop'=163
'+'=182
'-'=183
'*'=184
'/'=185
'%'=186
'^'=187
'<<'=188
'>>'=189
'>='=190
'>'=191
'<='=192
'<'=193
'=='=194
'='=195
'+='=196
'-='=197
'*='=198
'/='=199
'%='=200
'!='=201
'|'=202
'('=203
')'=204
','=205
';'=206
'->'=207
'['=208
']'=209
'?'=210
':'=211
'{'=212
'}'=213
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -3,8 +3,8 @@ from antlr4 import InputStream, CommonTokenStream
import torch
from .Parser.MathExprLexer import MathExprLexer
from .Parser.MathExprParser import MathExprParser
from .Parser.antlr_router import get_antlr_modules
MathExprLexer, MathExprParser, _ = get_antlr_modules()
import re