├── .github └── workflows │ └── build.yml ├── .gitignore ├── LICENSE ├── README.md ├── examples ├── bools.tale ├── fibonacci.tale ├── helloworld.tale ├── python_interop.tale ├── rock_paper_scissors.tale └── test.tale ├── images ├── logo.png └── syntax.png └── src ├── cli.py ├── requirements.txt ├── tale ├── __init__.py ├── common.py ├── core.py ├── runtime │ ├── __init__.py │ ├── evaluation.py │ └── objects.py └── syntax │ ├── __init__.py │ ├── grammar │ ├── Tale.g4 │ ├── Tale.interp │ ├── Tale.tokens │ ├── TaleLexer.interp │ ├── TaleLexer.py │ ├── TaleLexer.tokens │ ├── TaleListener.py │ └── TaleParser.py │ ├── nodes.py │ └── parsers │ ├── __init__.py │ ├── antlr4.py │ └── parser.py └── tests ├── __init__.py └── integration ├── __init__.py ├── forms ├── __init__.py ├── binary_forms_test.py ├── keyword_forms_test.py ├── prefix_operators_test.py ├── unary_forms_test.py └── unary_operator_forms_test.py ├── interop_test.py ├── syntax ├── __init__.py ├── assignments_test.py ├── comments_test.py ├── implicit_return_test.py ├── indentation_test.py ├── pattern_matching_test.py └── tuple_arguments_test.py └── types ├── __init__.py ├── int_test.py └── string_test.py /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: develop 6 | pull_request: 7 | branches: develop 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v1 16 | - name: Set up Python 3.8 17 | uses: actions/setup-python@v1 18 | with: 19 | python-version: 3.8 20 | - name: Install dependencies 21 | run: | 22 | cd src 23 | python -m pip install --upgrade pip 24 | pip install -r requirements.txt 25 | - name: Test with pytest 26 | run: | 27 | cd src 28 | pytest -s 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Emacs. 2 | *~ 3 | \#*\# 4 | .\#* 5 | 6 | # Mac. 7 | .DS_Store 8 | 9 | # Python. 10 | venv/ 11 | __pycache__/ 12 | 13 | # Tags. 14 | tags 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Tale Programming Language 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | Tale Logo 3 |
4 | 5 |

Tale

6 | 7 |

8 | An example of Haskell + Smalltalk + Python as a programming language. 9 |

10 | 11 |
12 | Tale Syntax 13 |
14 | 15 | ## Status 16 | 17 | Currently, the project is frozen for an undefined time. 18 | -------------------------------------------------------------------------------- /examples/bools.tale: -------------------------------------------------------------------------------- 1 | not: True = False 2 | not: False = True 3 | 4 | !(x) = not: x 5 | 6 | True and: True = True 7 | (x) and: (y) = False 8 | 9 | True and: True 10 | -------------------------------------------------------------------------------- /examples/fibonacci.tale: -------------------------------------------------------------------------------- 1 | fibonacci: 1 = 0 2 | fibonacci: 2 = 1 3 | fibonacci: (n) = 4 | a = fibonacci: n - 1 5 | b = fibonacci: n - 2 6 | a + b 7 | 8 | -- Put any number here. 9 | x = fibonacci: 10 10 | x 11 | -------------------------------------------------------------------------------- /examples/helloworld.tale: -------------------------------------------------------------------------------- 1 | print: "Hello, world!" 2 | -------------------------------------------------------------------------------- /examples/python_interop.tale: -------------------------------------------------------------------------------- 1 | random: (x) to: (y) = py: "import random; result = random.randint", x, y 2 | 3 | random: 1 to: 10 4 | -------------------------------------------------------------------------------- /examples/rock_paper_scissors.tale: -------------------------------------------------------------------------------- 1 | -- A random integer in range [x, y]. 2 | random: (x) to: (y) = py: "import random; result = random.randint", x, y 3 | 4 | -- Read from stdin. 5 | read: (x) = py: "result = input", x 6 | 7 | Rock vs: Rock = Draw 8 | Rock vs: Scissors = Win 9 | Rock vs: Paper = Lose 10 | 11 | Paper vs: Paper = Draw 12 | Paper vs: Scissors = Lose 13 | Paper vs: Rock = Win 14 | 15 | Scissors vs: Scissors = Draw 16 | Scissors vs: Paper = Win 17 | Scissors vs: Rock = Lose 18 | 19 | weapon: 1 = Rock 20 | weapon: 2 = Paper 21 | weapon: 3 = Scissors 22 | 23 | round = 24 | player = read: "Choose a weapon (rock=1, paper=2, scissors=3): " 25 | playerWeapon = weapon: player 26 | 27 | ai = random: 1 to: 3 28 | aiWeapon = weapon: ai 29 | 30 | playerWeapon vs: aiWeapon 31 | 32 | play = 33 | result = round 34 | print: result 35 | play 36 | play 37 | -------------------------------------------------------------------------------- /examples/test.tale: -------------------------------------------------------------------------------- 1 | #(x: Int) = 1123 2 | 3 | ##123 4 | -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tale-lang/tale/1779f94aa13545e58a1d5a8819b85ad02ada4144/images/logo.png -------------------------------------------------------------------------------- /images/syntax.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tale-lang/tale/1779f94aa13545e58a1d5a8819b85ad02ada4144/images/syntax.png -------------------------------------------------------------------------------- /src/cli.py: -------------------------------------------------------------------------------- 1 | """Command line interface module for the Tale Python interpreter.""" 2 | 3 | import os 4 | import subprocess 5 | 6 | from mints import Arg, Flag, cli 7 | 8 | 9 | class File: 10 | def __init__(self, path: str): 11 | self.path = path 12 | 13 | def read(self) -> str: 14 | with open(self.path, 'r') as f: 15 | return f.read() 16 | 17 | 18 | def rebuild_grammar(): 19 | def build(grammar: str): 20 | antlr4_path = '/usr/local/lib/antlr-4.8-complete.jar:$CLASSPATH' 21 | subprocess.call(f'java -Xmx500M -cp "{antlr4_path}" ' + 22 | f'org.antlr.v4.Tool {grammar} -Dlanguage=Python3', 23 | shell=True) 24 | 25 | grammar = 'tale/syntax/grammar/Tale.g4' 26 | change_time = os.stat(grammar) 27 | build(grammar) 28 | 29 | 30 | @cli 31 | def interpret(program: Arg[File], rebuild: Flag): 32 | """Interprets a program file as a Tale program.""" 33 | 34 | if rebuild: 35 | rebuild_grammar() 36 | 37 | from tale.core import execute 38 | 39 | code = program.read() 40 | execute(code) 41 | 42 | 43 | cli.add_parser(File) 44 | 45 | 46 | if __name__ == '__main__': 47 | cli() 48 | -------------------------------------------------------------------------------- /src/requirements.txt: -------------------------------------------------------------------------------- 1 | click==7.0 2 | tree-format==0.1.2 3 | antlr4-python3-runtime==4.8 4 | antlr-denter==1.3.1 5 | mints==0.0.1 6 | 7 | pytest==5.3.2 8 | mock==3.0.5 9 | -------------------------------------------------------------------------------- /src/tale/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tale-lang/tale/1779f94aa13545e58a1d5a8819b85ad02ada4144/src/tale/__init__.py -------------------------------------------------------------------------------- /src/tale/common.py: -------------------------------------------------------------------------------- 1 | from functools import reduce 2 | from itertools import zip_longest 3 | from typing import Any, Callable, Iterable, List 4 | 5 | 6 | def group(iterable: Iterable[Any], by: int) -> Iterable[Iterable[Any]]: 7 | """Groups an iterable into chunks of the specified size. 8 | 9 | Args: 10 | iterable: An iterable that will be grouped. 11 | by: A size of each chunk. 12 | 13 | Returns: 14 | A sequence of tuples of the constant size. 15 | 16 | Examples: 17 | >>> list(group([1, 2, 3, 4], by=1)) 18 | [(1,), (2,), (3,), (4,)] 19 | >>> list(group([1, 2, 3, 4], by=2)) 20 | [(1, 2), (3, 4)] 21 | >>> list(group([1, 2, 3, 4], by=3)) 22 | [(1, 2, 3), (4, None, None)] 23 | """ 24 | 25 | args = [iter(iterable)] * by 26 | return zip_longest(*args) 27 | 28 | 29 | def pipe(*funcs: List[Callable]) -> Any: 30 | """Composes a sequence of functions into single pipe. 31 | 32 | For example, a following code: 33 | 34 | pipe(f, g)(x) 35 | 36 | Is similar to: 37 | 38 | g(f(x)) 39 | 40 | Args: 41 | funcs: A sequence of functions. 42 | 43 | Returns: 44 | A function that pipes an input value into the first function of the sequence, 45 | whose result is piped into the second function, etc. 46 | """ 47 | 48 | def pipe_(f: Callable, g: Callable): 49 | return lambda x: g(f(x)) 50 | 51 | return reduce(pipe_, funcs, lambda x: x) 52 | -------------------------------------------------------------------------------- /src/tale/core.py: -------------------------------------------------------------------------------- 1 | from typing import Any 2 | 3 | from tale.runtime.evaluation import evaluate 4 | from tale.syntax.parsers.antlr4 import Antlr4Parser 5 | 6 | 7 | def execute(code: str) -> Any: 8 | """Executes a code string. 9 | 10 | Args: 11 | code: Code as a string. 12 | 13 | Returns: 14 | A result of the code execution. 15 | 16 | Examples: 17 | >>> execute('2 + 2') 18 | 4 19 | >>> execute('x = 1') 20 | None 21 | """ 22 | 23 | print('--------------------------------------------------------------') 24 | print('ANTLR4 Output:') 25 | tree: Node = Antlr4Parser().ast(code) 26 | print('--------------------------------------------------------------') 27 | print('Syntax tree:') 28 | print(str(tree).rstrip()) 29 | print('--------------------------------------------------------------') 30 | output: TaleObject = evaluate(tree) 31 | print('Output:') 32 | print(output.py_instance if output.py_instance is not None else '') 33 | print('--------------------------------------------------------------') 34 | 35 | return output.py_instance 36 | -------------------------------------------------------------------------------- /src/tale/runtime/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tale-lang/tale/1779f94aa13545e58a1d5a8819b85ad02ada4144/src/tale/runtime/__init__.py -------------------------------------------------------------------------------- /src/tale/runtime/evaluation.py: -------------------------------------------------------------------------------- 1 | import os 2 | from abc import ABCMeta, abstractmethod 3 | from typing import Any, Iterable, Optional, Tuple 4 | 5 | from tale.runtime.objects import (TaleInt, TaleNone, TaleObject, TaleString, 6 | TaleTuple, TaleType) 7 | from tale.syntax.nodes import (Assignment, BinaryExpression, BinaryForm, 8 | Expression, Form, IntLiteral, KeywordArgument, 9 | KeywordExpression, KeywordForm, Node, Parameter, 10 | PatternMatchingParameter, 11 | PrefixOperatorExpression, PrefixOperatorForm, 12 | PrimitiveExpression, PrimitiveExpressionItem, 13 | PrimitiveForm, SimpleParameter, Statement, 14 | StringLiteral, TupleParameter, UnaryExpression, 15 | UnaryForm) 16 | 17 | 18 | class Value(metaclass=ABCMeta): 19 | """A value that is already instantiated. 20 | 21 | For example, in the following code: 22 | x = 1 23 | print: x 24 | print: x 25 | The value of `x` is an instance of `PrimitiveValue`, which is itself an 26 | instance of `TaleObject` with type `TaleInt`. 27 | """ 28 | 29 | @staticmethod 30 | def of(expression: Expression, scope: 'Scope') -> 'Value': 31 | if isinstance(expression, UnaryExpression): 32 | return UnaryValue(expression, scope) 33 | if isinstance(expression, PrefixOperatorExpression): 34 | return PrefixOperatorValue(expression, scope) 35 | if isinstance(expression, BinaryExpression): 36 | return BinaryValue(expression, scope) 37 | if isinstance(expression, KeywordExpression): 38 | return KeywordValue(expression, scope) 39 | if isinstance(expression, PrimitiveExpression) or \ 40 | isinstance(expression, PrimitiveExpressionItem): 41 | return PrimitiveValue(expression, scope) 42 | 43 | raise ValueError(f"Couldn't recognize node:{os.linesep}" 44 | f"{expression}") 45 | 46 | 47 | class UnaryValue(Value): 48 | def __init__(self, expression: UnaryExpression, scope: 'Scope'): 49 | self.identifier = expression.identifier 50 | self.argument = scope.resolve(expression.argument) 51 | 52 | 53 | class PrefixOperatorValue(Value): 54 | def __init__(self, expression: PrefixOperatorExpression, scope: 'Scope'): 55 | self.operator = expression.operator 56 | self.argument = scope.resolve(expression.argument) 57 | 58 | 59 | class BinaryValue(Value): 60 | def __init__(self, expression: BinaryExpression, scope: 'Scope'): 61 | self.operator = expression.operator.content 62 | self.first_argument = scope.resolve(expression.first_argument) 63 | self.second_argument = scope.resolve(expression.second_argument) 64 | 65 | 66 | class KeywordValue(Value): 67 | def __init__(self, expression: KeywordExpression, scope: 'Scope'): 68 | def resolved(x): 69 | name, value = x 70 | return name, scope.resolve(value) 71 | 72 | self.prefix = scope.resolve(expression.prefix) if expression.prefix is not None else None 73 | self.parts = list(map(resolved, expression.parts)) 74 | 75 | 76 | class PrimitiveValue(Value): 77 | """A primitive value.""" 78 | 79 | def __init__(self, expression: Expression, scope: 'Scope'): 80 | self.identifier = expression.content 81 | 82 | 83 | class Captured(metaclass=ABCMeta): 84 | """An expression that was captured by a form.""" 85 | 86 | @abstractmethod 87 | def resolve(self, scope: 'Scope') -> TaleObject: 88 | """Resolves captured expression into value. 89 | 90 | Args: 91 | scope: A parent scope that needs to resolve the expression. 92 | 93 | Returns: 94 | Resolved expression. 95 | """ 96 | 97 | 98 | class CapturedNode(Captured): 99 | """An expression that was captured by a form. 100 | 101 | Represents captured node and arguments. 102 | 103 | For example, the following expression: 104 | 1 squared 105 | Could be captured by the following form: 106 | (x) squared 107 | 108 | Attributes: 109 | form: A node that represents a form that captured the expression. 110 | node: A node that rerepsents a value of the form captured the expression. 111 | For example, `1 squared` could be captured by `(x) squared = x * x` 112 | form, and the `node` would represent `x * x`. 113 | arguments: A sequence of arguments that were captured with the 114 | expression. 115 | For example, when the `1 squared` expression is captured by 116 | the `(x) squared = x * x` one, arguments list would contain 117 | an instance of `CapturedArgument` with `name` equal to `x`, and 118 | `value` equal to node that represents `1`. 119 | """ 120 | 121 | def __init__(self, node: Node, arguments: Iterable['CapturedArgument'] = None): 122 | self.node = node 123 | self.arguments = arguments or [] 124 | 125 | def resolve(self, scope: 'Scope') -> TaleObject: 126 | """Resolves current expression in the new scope. 127 | 128 | Args: 129 | scope: A parent scope that needs to resolve the expression. 130 | 131 | Returns: 132 | Resolved expression. 133 | """ 134 | 135 | scope = Scope(parent=scope) 136 | 137 | for arg in self.arguments: 138 | arg.bind(scope) 139 | 140 | return scope.resolve(self.node) 141 | 142 | 143 | class CapturedConst(Captured): 144 | """A captured expression that represents an already resolved value. 145 | 146 | Unlike default `CapturedNode`, implements `resolve` that returns 147 | a predefined value. 148 | 149 | Attributes: 150 | value: A constant value. 151 | """ 152 | 153 | def __init__(self, instance): 154 | self._instance = instance 155 | 156 | def resolve(self, scope: 'Scope') -> TaleObject: 157 | return self._instance 158 | 159 | 160 | class CapturedArgument(metaclass=ABCMeta): 161 | """An argument that were captured within an expression. 162 | 163 | Attributes: 164 | name: A name of the parameter that captured the argument. 165 | value: A TaleObject that represents a value of the argument. 166 | """ 167 | 168 | @abstractmethod 169 | def bind(self, scope: 'Scope'): 170 | """Binds a captured argument into the scope.""" 171 | 172 | 173 | class CapturedSingle(CapturedArgument): 174 | """A captured single argument.""" 175 | 176 | def __init__(self, name: str, value: TaleObject): 177 | self.name = name 178 | self.value = value 179 | 180 | def bind(self, scope: 'Scope'): 181 | form = PrimitiveForm(self.name) 182 | value = self.value 183 | 184 | scope.bindings.append(ConstBinding(form, value)) 185 | 186 | 187 | class CapturedTuple(CapturedArgument): 188 | """A captured argument that represents a tuple.""" 189 | 190 | def __init__(self, args: CapturedArgument): 191 | self.args = args 192 | 193 | def bind(self, scope: 'Scope'): 194 | for arg in self.args: 195 | arg.bind(scope) 196 | 197 | 198 | class BoundParameter(metaclass=ABCMeta): 199 | """A parameter that is part of a binding. 200 | 201 | For example, in the following form: 202 | (x) squared = x * x 203 | `(x)` is a bound parameter of type `SimpleBoundParameter`. 204 | 205 | On the other hand, one could write: 206 | 1 squared = x * x 207 | Here the `1` is a bound parameter of type `PatternMatchingBoundParameter`. 208 | """ 209 | 210 | @staticmethod 211 | def of(parameter: Parameter) -> 'BoundParameter': 212 | """Creates an instance of `BoundParameter` from syntax `Parameter`. 213 | 214 | Args: 215 | parameter: A `Parameter` syntax node. 216 | 217 | Returns: 218 | An instance of `Parameter`: either `BoundSimpleParameter`, 219 | `BoundPatternMatchingParameter` or `BoundTupleParameter`. 220 | 221 | Raises: 222 | ValueError: If the `parameter` does not represent a simple, 223 | pattern matching or tuple. 224 | """ 225 | 226 | if isinstance(parameter, SimpleParameter): 227 | return BoundSimpleParameter(parameter) 228 | if isinstance(parameter, PatternMatchingParameter): 229 | return BoundPatternMatchingParameter(parameter) 230 | if isinstance(parameter, TupleParameter): 231 | return BoundTupleParameter(parameter) 232 | 233 | raise ValueError(f"Couldn't create a value from {parameter}") 234 | 235 | @abstractmethod 236 | def capture(self, argument: TaleObject) -> CapturedArgument: 237 | """Captures an instance of `TaleObject` as argument. 238 | 239 | Consider following examples of bound parameters: 240 | - `(x)`: could match any object. 241 | - `(x: Int)`: could match only instances of 242 | `TaleInt`. 243 | - `1`: could match only instance of `TaleInt` 244 | with value `1`. 245 | """ 246 | 247 | 248 | class BoundSimpleParameter(BoundParameter): 249 | """A simple parameter that is part of some binding. 250 | 251 | For example, the following binding: 252 | (x) squared = x * x 253 | Contains `(x)` as an instance of `BoundSimpleParameter`. 254 | 255 | Attributes: 256 | node: A `SimpleParameter` syntax node. 257 | """ 258 | 259 | def __init__(self, node: SimpleParameter): 260 | self.node = node 261 | 262 | def capture(self, argument: TaleObject) -> CapturedArgument: 263 | if self.node.type_ is not None: 264 | if argument.type is None: 265 | return None 266 | if self.node.type_.content != argument.type.name.py_instance: 267 | return None 268 | 269 | return CapturedSingle(self.node.name, argument) 270 | 271 | 272 | class BoundPatternMatchingParameter(BoundParameter): 273 | """A pattern matching parameter that is part of some binding. 274 | 275 | For example, the following binding: 276 | 1 squared = 1 277 | Contains `1` as an instance of `BoundPatternMatchingParameter`. 278 | 279 | Attributes: 280 | node: A `PatternMatchingParameter` syntax node. 281 | """ 282 | 283 | def __init__(self, node: PatternMatchingParameter): 284 | self.node = node 285 | 286 | def capture(self, argument: TaleObject) -> CapturedArgument: 287 | if self.node.content != str(argument.py_instance): 288 | return None 289 | 290 | return CapturedSingle(None, argument) 291 | 292 | 293 | class BoundTupleParameter(BoundParameter): 294 | """A tuple parameter that is part of some binding. 295 | 296 | For example, the following binding: 297 | first: (x), (y) = x 298 | Contains `(x), (y)` as an instance of `BoundTupleParameter`. 299 | 300 | Attributes: 301 | node: A `TupleParameter` syntax node. 302 | """ 303 | 304 | def __init__(self, node: TupleParameter): 305 | self.node = node 306 | 307 | def capture(self, argument: TaleObject) -> CapturedArgument: 308 | if argument.type is not TaleTuple: 309 | return None 310 | 311 | parameters = list(self.node.items) 312 | arguments = argument.items 313 | 314 | if len(parameters) != len(arguments): 315 | return None 316 | 317 | args = [] 318 | 319 | for parameter, argument in zip(parameters, arguments): 320 | parameter = BoundParameter.of(parameter) 321 | arg = parameter.capture(argument) 322 | 323 | if arg is None: 324 | return None 325 | else: 326 | args.append(arg) 327 | 328 | return CapturedTuple(args) 329 | 330 | 331 | class Binding(metaclass=ABCMeta): 332 | """A binding between a form and a value.""" 333 | 334 | @staticmethod 335 | def of(form: Form, value: Node) -> 'Binding': 336 | """Creates new binding from instances of form and value. 337 | 338 | Args: 339 | form: A form that represents the binding. 340 | value: A value that is assigned to the form. 341 | 342 | Returns: 343 | An instance of `Binding` that encapsulates the form and the value. 344 | 345 | Raises: 346 | ValueError: If the specific form isn't unary, binary, keyword or 347 | primitive one. 348 | """ 349 | 350 | if isinstance(form, UnaryForm): 351 | return UnaryBinding(form, value) 352 | if isinstance(form, PrefixOperatorForm): 353 | return PrefixOperatorBinding(form, value) 354 | if isinstance(form, BinaryForm): 355 | return BinaryBinding(form, value) 356 | if isinstance(form, KeywordForm): 357 | return KeywordBinding(form, value) 358 | if isinstance(form, PrimitiveForm): 359 | return PrimitiveBinding(form, value) 360 | 361 | raise ValueError(f"Couldn't create a new binding for {type(form)}.") 362 | 363 | @abstractmethod 364 | def capture(self, value: Value) -> Captured: 365 | """Captures the value if it's possible. 366 | 367 | Args: 368 | value: A value that represents an expression. 369 | 370 | Returns: 371 | An instance of `Captured` if the `value` matches the form of the 372 | binding. 373 | """ 374 | 375 | 376 | class UnaryBinding(Binding): 377 | """An unary form binding. 378 | 379 | For example, the following statement: 380 | (x) squared = ... 381 | produces an unary binding of unary form `(x) squared` to `...`. 382 | """ 383 | 384 | def __init__(self, form: UnaryForm, value: Node): 385 | self.form = form 386 | self.value = value 387 | self.parameter = BoundParameter.of(form.parameter) 388 | 389 | def capture(self, value: UnaryValue) -> Captured: 390 | if not isinstance(value, UnaryValue): 391 | return None 392 | if self.form.identifier != value.identifier: 393 | return None 394 | 395 | arg = self.parameter.capture(value.argument) 396 | 397 | if arg is not None: 398 | return CapturedNode(self.value, [arg]) 399 | 400 | 401 | class PrefixOperatorBinding(Binding): 402 | """A prefix operator form binding. 403 | 404 | For example, the following statement: 405 | -(x) = ... 406 | produces a prefix operator binding of prefix operator form `-(x)` to `...`. 407 | """ 408 | 409 | def __init__(self, form: PrefixOperatorForm, value: Node): 410 | self.form = form 411 | self.value = value 412 | self.parameter = BoundParameter.of(form.parameter) 413 | 414 | def capture(self, value: PrefixOperatorValue) -> Captured: 415 | if not isinstance(value, PrefixOperatorValue): 416 | return None 417 | if self.form.operator != value.operator: 418 | return None 419 | 420 | arg = self.parameter.capture(value.argument) 421 | 422 | if arg is not None: 423 | return CapturedNode(self.value, [arg]) 424 | 425 | 426 | class BinaryBinding(Binding): 427 | """A binary form binding. 428 | 429 | For example, the following statement: 430 | (x) + (y) = ... 431 | produces a binary binding of binary form `(x) + (y)` to `...`. 432 | """ 433 | 434 | def __init__(self, form: BinaryForm, value: Node): 435 | self.form = form 436 | self.value = value 437 | self.first_parameter = BoundParameter.of(form.first_parameter) 438 | self.second_parameter = BoundParameter.of(form.second_parameter) 439 | 440 | def capture(self, value: BinaryValue) -> Captured: 441 | if not isinstance(value, BinaryValue): 442 | return None 443 | if self.form.operator.content != value.operator: 444 | return None 445 | 446 | args = [] 447 | 448 | first_argument = self.first_parameter.capture(value.first_argument) 449 | second_argument = self.second_parameter.capture(value.second_argument) 450 | 451 | if first_argument is None or second_argument is None: 452 | return None 453 | 454 | args.append(first_argument) 455 | args.append(second_argument) 456 | 457 | return CapturedNode(self.value, args) 458 | 459 | 460 | class KeywordBinding(Binding): 461 | """A keyword form binding. 462 | 463 | For example, the following statement: 464 | just: (x) = ... 465 | produces a keyword binding of keyword form `just: (x)` to `...`. 466 | """ 467 | 468 | def __init__(self, form: KeywordForm, value: Node): 469 | self.form = form 470 | self.value = value 471 | 472 | def capture(self, value: KeywordValue) -> Captured: 473 | if not isinstance(value, KeywordValue): 474 | return None 475 | 476 | form = self.form 477 | 478 | form_parts = list(form.parts) 479 | node_parts = list(value.parts) 480 | 481 | if len(form_parts) != len(node_parts): 482 | return None 483 | 484 | args = [] 485 | 486 | if form.prefix is not None and value.prefix is not None: 487 | prefix_parameter = BoundParameter.of(form.prefix) 488 | arg = prefix_parameter.capture(value.prefix) 489 | 490 | if arg is None: 491 | return None 492 | else: 493 | args.append(arg) 494 | elif form.prefix is not None or value.prefix is not None: 495 | return None 496 | 497 | parts = zip(form_parts, node_parts) 498 | 499 | for (form_name, form_parameter), (value_name, value) in parts: 500 | if form_name.content != value_name.content: 501 | return None 502 | 503 | form_parameter = BoundParameter.of(form_parameter) 504 | arg = form_parameter.capture(value) 505 | 506 | if arg is None: 507 | return None 508 | else: 509 | args.append(arg) 510 | 511 | return CapturedNode(self.value, args) 512 | 513 | 514 | class PrimitiveBinding(Binding): 515 | """A primitive form binding. 516 | 517 | For example, the following statement: 518 | x = 1 519 | produces a primitive binding of primitive form `x` to `1`. 520 | """ 521 | 522 | def __init__(self, form: PrimitiveForm, value: Node): 523 | self.form = form 524 | self.value = value 525 | 526 | def capture(self, value: PrimitiveValue) -> Captured: 527 | if not isinstance(value, PrimitiveValue): 528 | return None 529 | if self.form.content != value.identifier: 530 | return None 531 | 532 | return CapturedNode(self.value) 533 | 534 | 535 | class ConstBinding: 536 | """A binding with the constant value.""" 537 | 538 | def __init__(self, form: Form, value: TaleObject): 539 | self.binding = Binding.of(form, value) 540 | self.value = value 541 | 542 | def capture(self, node: Node) -> Captured: 543 | captured = self.binding.capture(node) 544 | 545 | if captured: 546 | return CapturedConst(self.value) 547 | 548 | 549 | class PredefinedBinding: 550 | """A binding that is predefined as a part of the Tale's prelude.""" 551 | 552 | def __init__(self, form: Form, func): 553 | self.binding = Binding.of(form, Node('')) 554 | self.func = func 555 | 556 | def capture(self, value: Value) -> Captured: 557 | captured = self.binding.capture(value) 558 | 559 | if captured: 560 | return CapturedConst(self.func(captured)) 561 | 562 | 563 | class PyBinding: 564 | """A binding that is used to capture native Python calls.""" 565 | 566 | def capture(self, value: KeywordValue) -> Captured: 567 | if not isinstance(value, KeywordValue): 568 | return None 569 | 570 | if value.prefix is not None: 571 | return None 572 | 573 | parts = list(value.parts) 574 | 575 | if len(parts) != 1: 576 | return None 577 | 578 | name, arg = parts[0] 579 | 580 | if name.content != 'py': 581 | return None 582 | 583 | if arg.type is not TaleTuple: 584 | return None 585 | 586 | items = arg.items 587 | 588 | if items[0].type is not TaleString: 589 | return None 590 | 591 | code = items[0].py_instance.strip('"') 592 | args = map(lambda x: str(x.py_instance), items[1:]) 593 | args = ', '.join(args) 594 | code = code + '(' + args + ')' 595 | 596 | locals_ = {} 597 | exec(code, {}, locals_) 598 | 599 | result = locals_['result'] 600 | 601 | if isinstance(result, int): 602 | return CapturedConst(TaleObject(TaleInt, result)) 603 | 604 | if isinstance(result, str): 605 | return CapturedConst(TaleObject(TaleString, result)) 606 | 607 | 608 | class Scope: 609 | """A scope of the program execution. 610 | 611 | Attributes: 612 | parent: A parent scope of the current scope. 613 | For example, a function scope is a parent for if statement scope. 614 | """ 615 | 616 | def __init__(self, parent: Optional['Scope'] = None): 617 | self.parent = parent 618 | self.bindings = [] 619 | 620 | def capture(self, value: Value) -> Captured: 621 | """Finds a binding that could capture a value, and captures it. 622 | 623 | Args: 624 | value: A value that represents an expression to capture. 625 | 626 | Returns: 627 | An instance of `Captured` that represents a captured value. 628 | """ 629 | 630 | def parent_capture(): 631 | return self.parent.capture(value) if self.parent is not None else None 632 | 633 | captures = (x.capture(value) for x in self.bindings) 634 | captures = (x for x in captures if x) 635 | 636 | return next(captures, None) or parent_capture() 637 | 638 | def bind(self, form: Node, value: Node): 639 | """Binds the specified value node to the specified form. 640 | 641 | Args: 642 | form: A form that holds the binding. 643 | value: A value that is bound to the form. 644 | """ 645 | 646 | self.bindings.append(Binding.of(form, value)) 647 | 648 | def resolve(self, node: Node) -> TaleObject: 649 | """Processes a syntax node. 650 | 651 | If node is an assignment, then the new binding will be created in the 652 | scope. 653 | If node is an expression, then it will be converted to the value. 654 | 655 | Args: 656 | node: A node to resolve. 657 | 658 | Returns: 659 | An instance of `TaleObject` that represents a resolved node. 660 | """ 661 | 662 | def resolve_primitive(x: PrimitiveExpression) -> TaleObject: 663 | if isinstance(x.children[0], IntLiteral): 664 | return TaleObject(TaleInt, int(x.content)) 665 | 666 | if isinstance(x.children[0], StringLiteral): 667 | return TaleObject(TaleString, x.content) 668 | 669 | def resolve_assignment(x: Assignment): 670 | self.bind(x.form, x.value) 671 | 672 | def resolve_expression(x: Expression): 673 | def resolved(x: Node) -> TaleObject: 674 | if isinstance(x.children[0], IntLiteral): 675 | return TaleObject(TaleInt, int(x.content)) 676 | 677 | if isinstance(x.children[0], StringLiteral): 678 | return TaleObject(TaleString, x.content) 679 | 680 | def captured(x: Node) -> TaleObject: 681 | x_value = Value.of(x, self) 682 | x_value = self.capture(x_value) 683 | 684 | if x_value: 685 | return x_value.resolve(scope=self) 686 | else: 687 | return TaleObject(TaleType, x.content) 688 | 689 | def value(x: Node) -> TaleObject: 690 | return resolved(x) or captured(x) 691 | 692 | if isinstance(x, KeywordArgument): 693 | x = x.children[0] 694 | 695 | if isinstance(x, PrimitiveExpression): 696 | items = map(value, x.items) 697 | items = list(items) 698 | 699 | if len(items) == 1: 700 | return items[0] 701 | else: 702 | result = TaleObject(TaleTuple, None) 703 | result.items = items 704 | 705 | return result 706 | 707 | if isinstance(x, PrimitiveExpressionItem): 708 | return value(x) 709 | 710 | return captured(x) 711 | 712 | def resolve_statement(x: Statement): 713 | x = x.children[0] 714 | 715 | if isinstance(x, Assignment): 716 | return resolve_assignment(x) 717 | if isinstance(x, Expression): 718 | return resolve_expression(x) 719 | 720 | if isinstance(node, Expression): 721 | return resolve_expression(node) 722 | if isinstance(node, PrimitiveExpressionItem): 723 | return resolve_expression(node) 724 | 725 | result = None 726 | 727 | for x in node.children: 728 | if isinstance(x, Statement): 729 | result = resolve_statement(x) 730 | if isinstance(x, Expression): 731 | result = resolve_expression(x) 732 | 733 | return result or TaleNone 734 | 735 | def evaluate(node: Node) -> TaleObject: 736 | """Evaluates the syntax tree node and produces the output. 737 | 738 | Args: 739 | tree: A root node of the syntax tree that represents the program. 740 | 741 | Returns: 742 | An output of the program. 743 | """ 744 | 745 | def identifier(name) -> Node: 746 | return Node(name, [Node(name)]) 747 | 748 | def simple(name: str) -> SimpleParameter: 749 | return SimpleParameter('', children=[Node('('), Node('x'), Node(')')]) 750 | 751 | def unary(name: str): 752 | return UnaryForm(name, children=[ 753 | simple('x'), 754 | identifier(name)]) 755 | 756 | def simple_keyword(name: str): 757 | return KeywordForm(name, children=[ 758 | identifier(name), 759 | simple('x')]) 760 | 761 | def binary(operator: str): 762 | return BinaryForm(operator, children=[ 763 | simple('x'), 764 | identifier(operator), 765 | simple('y')]) 766 | 767 | def unary_type() -> PredefinedBinding: 768 | def execute(x: Captured): 769 | arg = x.arguments[0] 770 | return arg.value.type.name 771 | 772 | return PredefinedBinding(unary('type'), execute) 773 | 774 | def binary_plus() -> PredefinedBinding: 775 | def execute(x: Captured): 776 | a, b = x.arguments 777 | 778 | if a.value.type is TaleInt and a.value.type is TaleInt: 779 | result = a.value.py_instance + b.value.py_instance 780 | 781 | return TaleObject(TaleInt, result) 782 | 783 | return PredefinedBinding(binary('+'), execute) 784 | 785 | def binary_minus() -> PredefinedBinding: 786 | def execute(x: Captured): 787 | a, b = x.arguments 788 | 789 | if a.value.type is TaleInt and a.value.type is TaleInt: 790 | result = a.value.py_instance - b.value.py_instance 791 | 792 | return TaleObject(TaleInt, result) 793 | 794 | return PredefinedBinding(binary('-'), execute) 795 | 796 | def print_() -> PredefinedBinding: 797 | def execute(x: Captured): 798 | arg = x.arguments[0] 799 | print(arg.value.py_instance) 800 | 801 | return PredefinedBinding(simple_keyword('print'), execute) 802 | 803 | 804 | prelude = Scope() 805 | prelude.bindings.append(unary_type()) 806 | prelude.bindings.append(binary_plus()) 807 | prelude.bindings.append(binary_minus()) 808 | prelude.bindings.append(print_()) 809 | prelude.bindings.append(PyBinding()) 810 | 811 | scope = Scope(parent=prelude) 812 | 813 | return scope.resolve(node) 814 | -------------------------------------------------------------------------------- /src/tale/runtime/objects.py: -------------------------------------------------------------------------------- 1 | from typing import Any 2 | 3 | 4 | class TaleObject: 5 | """A basic block of Tale's object model. 6 | 7 | All values in Tale exist only as instances of this class. 8 | 9 | For example, in the following expression: 10 | x = 1 11 | `1` is an instance of `TaleObject`. 12 | 13 | Attributes: 14 | type: An instance of `TaleObject` that represents the type of the 15 | object. 16 | name: A name of the object. 17 | py_instance: An instance of the object in Python memory. 18 | """ 19 | 20 | def __init__(self, type: 'TaleObject', py_instance: Any, name = None): 21 | self.type = type 22 | self.py_instance = py_instance 23 | self.name = name 24 | 25 | 26 | TaleType = TaleObject(None, None) 27 | TaleType.type = TaleType 28 | 29 | TaleString = TaleObject(TaleType, str) 30 | TaleString.name = TaleObject(TaleString, 'String') 31 | 32 | TaleType.name = TaleObject(TaleString, 'Type') 33 | 34 | TaleNone = TaleObject(None, None, TaleObject(TaleString, 'None')) 35 | TaleInt = TaleObject(TaleType, int, TaleObject(TaleString, 'Int')) 36 | TaleTuple = TaleObject(TaleType, None, TaleObject(TaleString, 'Tuple')) 37 | -------------------------------------------------------------------------------- /src/tale/syntax/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tale-lang/tale/1779f94aa13545e58a1d5a8819b85ad02ada4144/src/tale/syntax/__init__.py -------------------------------------------------------------------------------- /src/tale/syntax/grammar/Tale.g4: -------------------------------------------------------------------------------- 1 | grammar Tale; 2 | 3 | tokens { INDENT, DEDENT } 4 | 5 | @lexer::header{ 6 | from antlr_denter.DenterHelper import DenterHelper 7 | from .TaleParser import TaleParser 8 | } 9 | 10 | @lexer::members { 11 | class TaleDenter(DenterHelper): 12 | def __init__(self, lexer, nl_token, indent_token, dedent_token, ignore_eof): 13 | super().__init__(nl_token, indent_token, dedent_token, ignore_eof) 14 | self.lexer: TaleLexer = lexer 15 | 16 | def pull_token(self): 17 | return super(TaleLexer, self.lexer).nextToken() 18 | 19 | denter = None 20 | 21 | def nextToken(self): 22 | if not self.denter: 23 | self.denter = self.TaleDenter(self, self.NEWLINE, TaleParser.INDENT, TaleParser.DEDENT, False) 24 | 25 | return self.denter.next_token() 26 | } 27 | 28 | 29 | program: (NEWLINE | statement)* EOF; 30 | statement: assignment | expression; 31 | 32 | assignment: form '=' assignmentBody; 33 | 34 | form: unaryForm 35 | | prefixOperatorForm 36 | | binaryForm 37 | | keywordForm 38 | | primitiveForm; 39 | 40 | unaryForm: parameter IDENTIFIER; 41 | prefixOperatorForm: OPERATOR singleParameter; 42 | binaryForm: parameter OPERATOR parameter; 43 | keywordForm: parameter? (IDENTIFIER ':' parameter)+; 44 | primitiveForm: IDENTIFIER; 45 | 46 | parameter: singleParameter 47 | | tupleParameter; 48 | 49 | tupleParameter: singleParameter (',' singleParameter)+; 50 | singleParameter: simpleParameter 51 | | patternMatchingParameter; 52 | 53 | simpleParameter: '(' parameterName (':' parameterType)? ')'; 54 | patternMatchingParameter: IDENTIFIER | literal; 55 | 56 | parameterName: IDENTIFIER; 57 | parameterType: IDENTIFIER; 58 | 59 | assignmentBody: simpleAssignmentBody 60 | | compoundAssignmentBody; 61 | 62 | simpleAssignmentBody: expression; 63 | compoundAssignmentBody: INDENT (NEWLINE | statement)+ DEDENT; 64 | 65 | expression: unary 66 | | prefixOperator 67 | | binary 68 | | keyword 69 | | primitive; 70 | 71 | unary: unary IDENTIFIER 72 | | primitive IDENTIFIER; 73 | 74 | prefixOperator: OPERATOR primitiveItem 75 | | OPERATOR '(' expression ')'; 76 | 77 | binary: binary OPERATOR binaryOperand | 78 | binaryOperand OPERATOR binaryOperand; 79 | binaryOperand: unary 80 | | primitive; 81 | 82 | keyword: keywordArgument? (keywordName ':' keywordArgument)+; 83 | keywordArgument: unary 84 | | binary 85 | | primitive; 86 | keywordName: IDENTIFIER; 87 | 88 | primitive: primitiveItem (',' primitiveItem)*?; 89 | primitiveItem: IDENTIFIER 90 | | literal; 91 | 92 | literal: intLiteral 93 | | stringLiteral; 94 | 95 | intLiteral: NUMBER; 96 | stringLiteral: STRING; 97 | 98 | IDENTIFIER: [a-zA-Z]+; 99 | NUMBER: [0-9]+; 100 | OPERATOR: '-' 101 | | '+' 102 | | '*' 103 | | '/' 104 | | '.' 105 | | '!' 106 | | '@' 107 | | '#' 108 | | '$' 109 | | '%' 110 | | '^' 111 | | '&' 112 | | '|' 113 | | '\\'; 114 | STRING: '"' (.)*? '"'; 115 | 116 | WS: [ \t]+ -> skip; 117 | NEWLINE: ('\r'? '\n' ' '*); 118 | 119 | fragment COMMENT: '--' ~[\r\n\f]*; 120 | 121 | SKIP_: (WS | COMMENT) -> skip; 122 | -------------------------------------------------------------------------------- /src/tale/syntax/grammar/Tale.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | '=' 4 | ':' 5 | ',' 6 | '(' 7 | ')' 8 | null 9 | null 10 | null 11 | null 12 | null 13 | null 14 | null 15 | null 16 | null 17 | 18 | token symbolic names: 19 | null 20 | null 21 | null 22 | null 23 | null 24 | null 25 | IDENTIFIER 26 | NUMBER 27 | OPERATOR 28 | STRING 29 | WS 30 | NEWLINE 31 | SKIP_ 32 | INDENT 33 | DEDENT 34 | 35 | rule names: 36 | program 37 | statement 38 | assignment 39 | form 40 | unaryForm 41 | prefixOperatorForm 42 | binaryForm 43 | keywordForm 44 | primitiveForm 45 | parameter 46 | tupleParameter 47 | singleParameter 48 | simpleParameter 49 | patternMatchingParameter 50 | parameterName 51 | parameterType 52 | assignmentBody 53 | simpleAssignmentBody 54 | compoundAssignmentBody 55 | expression 56 | unary 57 | prefixOperator 58 | binary 59 | binaryOperand 60 | keyword 61 | keywordArgument 62 | keywordName 63 | primitive 64 | primitiveItem 65 | literal 66 | intLiteral 67 | stringLiteral 68 | 69 | 70 | atn: 71 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 16, 241, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 4, 27, 9, 27, 4, 28, 9, 28, 4, 29, 9, 29, 4, 30, 9, 30, 4, 31, 9, 31, 4, 32, 9, 32, 4, 33, 9, 33, 3, 2, 3, 2, 7, 2, 69, 10, 2, 12, 2, 14, 2, 72, 11, 2, 3, 2, 3, 2, 3, 3, 3, 3, 5, 3, 78, 10, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 5, 5, 89, 10, 5, 3, 6, 3, 6, 3, 6, 3, 7, 3, 7, 3, 7, 3, 8, 3, 8, 3, 8, 3, 8, 3, 9, 5, 9, 102, 10, 9, 3, 9, 3, 9, 3, 9, 6, 9, 107, 10, 9, 13, 9, 14, 9, 108, 3, 10, 3, 10, 3, 11, 3, 11, 5, 11, 115, 10, 11, 3, 12, 3, 12, 3, 12, 6, 12, 120, 10, 12, 13, 12, 14, 12, 121, 3, 13, 3, 13, 5, 13, 126, 10, 13, 3, 14, 3, 14, 3, 14, 3, 14, 5, 14, 132, 10, 14, 3, 14, 3, 14, 3, 15, 3, 15, 5, 15, 138, 10, 15, 3, 16, 3, 16, 3, 17, 3, 17, 3, 18, 3, 18, 5, 18, 146, 10, 18, 3, 19, 3, 19, 3, 20, 3, 20, 3, 20, 6, 20, 153, 10, 20, 13, 20, 14, 20, 154, 3, 20, 3, 20, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 5, 21, 164, 10, 21, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 7, 22, 172, 10, 22, 12, 22, 14, 22, 175, 11, 22, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 3, 23, 5, 23, 184, 10, 23, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 3, 24, 7, 24, 194, 10, 24, 12, 24, 14, 24, 197, 11, 24, 3, 25, 3, 25, 5, 25, 201, 10, 25, 3, 26, 5, 26, 204, 10, 26, 3, 26, 3, 26, 3, 26, 3, 26, 6, 26, 210, 10, 26, 13, 26, 14, 26, 211, 3, 27, 3, 27, 3, 27, 5, 27, 217, 10, 27, 3, 28, 3, 28, 3, 29, 3, 29, 3, 29, 7, 29, 224, 10, 29, 12, 29, 14, 29, 227, 11, 29, 3, 30, 3, 30, 5, 30, 231, 10, 30, 3, 31, 3, 31, 5, 31, 235, 10, 31, 3, 32, 3, 32, 3, 33, 3, 33, 3, 33, 3, 225, 4, 42, 46, 34, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 2, 2, 2, 240, 2, 70, 3, 2, 2, 2, 4, 77, 3, 2, 2, 2, 6, 79, 3, 2, 2, 2, 8, 88, 3, 2, 2, 2, 10, 90, 3, 2, 2, 2, 12, 93, 3, 2, 2, 2, 14, 96, 3, 2, 2, 2, 16, 101, 3, 2, 2, 2, 18, 110, 3, 2, 2, 2, 20, 114, 3, 2, 2, 2, 22, 116, 3, 2, 2, 2, 24, 125, 3, 2, 2, 2, 26, 127, 3, 2, 2, 2, 28, 137, 3, 2, 2, 2, 30, 139, 3, 2, 2, 2, 32, 141, 3, 2, 2, 2, 34, 145, 3, 2, 2, 2, 36, 147, 3, 2, 2, 2, 38, 149, 3, 2, 2, 2, 40, 163, 3, 2, 2, 2, 42, 165, 3, 2, 2, 2, 44, 183, 3, 2, 2, 2, 46, 185, 3, 2, 2, 2, 48, 200, 3, 2, 2, 2, 50, 203, 3, 2, 2, 2, 52, 216, 3, 2, 2, 2, 54, 218, 3, 2, 2, 2, 56, 220, 3, 2, 2, 2, 58, 230, 3, 2, 2, 2, 60, 234, 3, 2, 2, 2, 62, 236, 3, 2, 2, 2, 64, 238, 3, 2, 2, 2, 66, 69, 7, 13, 2, 2, 67, 69, 5, 4, 3, 2, 68, 66, 3, 2, 2, 2, 68, 67, 3, 2, 2, 2, 69, 72, 3, 2, 2, 2, 70, 68, 3, 2, 2, 2, 70, 71, 3, 2, 2, 2, 71, 73, 3, 2, 2, 2, 72, 70, 3, 2, 2, 2, 73, 74, 7, 2, 2, 3, 74, 3, 3, 2, 2, 2, 75, 78, 5, 6, 4, 2, 76, 78, 5, 40, 21, 2, 77, 75, 3, 2, 2, 2, 77, 76, 3, 2, 2, 2, 78, 5, 3, 2, 2, 2, 79, 80, 5, 8, 5, 2, 80, 81, 7, 3, 2, 2, 81, 82, 5, 34, 18, 2, 82, 7, 3, 2, 2, 2, 83, 89, 5, 10, 6, 2, 84, 89, 5, 12, 7, 2, 85, 89, 5, 14, 8, 2, 86, 89, 5, 16, 9, 2, 87, 89, 5, 18, 10, 2, 88, 83, 3, 2, 2, 2, 88, 84, 3, 2, 2, 2, 88, 85, 3, 2, 2, 2, 88, 86, 3, 2, 2, 2, 88, 87, 3, 2, 2, 2, 89, 9, 3, 2, 2, 2, 90, 91, 5, 20, 11, 2, 91, 92, 7, 8, 2, 2, 92, 11, 3, 2, 2, 2, 93, 94, 7, 10, 2, 2, 94, 95, 5, 24, 13, 2, 95, 13, 3, 2, 2, 2, 96, 97, 5, 20, 11, 2, 97, 98, 7, 10, 2, 2, 98, 99, 5, 20, 11, 2, 99, 15, 3, 2, 2, 2, 100, 102, 5, 20, 11, 2, 101, 100, 3, 2, 2, 2, 101, 102, 3, 2, 2, 2, 102, 106, 3, 2, 2, 2, 103, 104, 7, 8, 2, 2, 104, 105, 7, 4, 2, 2, 105, 107, 5, 20, 11, 2, 106, 103, 3, 2, 2, 2, 107, 108, 3, 2, 2, 2, 108, 106, 3, 2, 2, 2, 108, 109, 3, 2, 2, 2, 109, 17, 3, 2, 2, 2, 110, 111, 7, 8, 2, 2, 111, 19, 3, 2, 2, 2, 112, 115, 5, 24, 13, 2, 113, 115, 5, 22, 12, 2, 114, 112, 3, 2, 2, 2, 114, 113, 3, 2, 2, 2, 115, 21, 3, 2, 2, 2, 116, 119, 5, 24, 13, 2, 117, 118, 7, 5, 2, 2, 118, 120, 5, 24, 13, 2, 119, 117, 3, 2, 2, 2, 120, 121, 3, 2, 2, 2, 121, 119, 3, 2, 2, 2, 121, 122, 3, 2, 2, 2, 122, 23, 3, 2, 2, 2, 123, 126, 5, 26, 14, 2, 124, 126, 5, 28, 15, 2, 125, 123, 3, 2, 2, 2, 125, 124, 3, 2, 2, 2, 126, 25, 3, 2, 2, 2, 127, 128, 7, 6, 2, 2, 128, 131, 5, 30, 16, 2, 129, 130, 7, 4, 2, 2, 130, 132, 5, 32, 17, 2, 131, 129, 3, 2, 2, 2, 131, 132, 3, 2, 2, 2, 132, 133, 3, 2, 2, 2, 133, 134, 7, 7, 2, 2, 134, 27, 3, 2, 2, 2, 135, 138, 7, 8, 2, 2, 136, 138, 5, 60, 31, 2, 137, 135, 3, 2, 2, 2, 137, 136, 3, 2, 2, 2, 138, 29, 3, 2, 2, 2, 139, 140, 7, 8, 2, 2, 140, 31, 3, 2, 2, 2, 141, 142, 7, 8, 2, 2, 142, 33, 3, 2, 2, 2, 143, 146, 5, 36, 19, 2, 144, 146, 5, 38, 20, 2, 145, 143, 3, 2, 2, 2, 145, 144, 3, 2, 2, 2, 146, 35, 3, 2, 2, 2, 147, 148, 5, 40, 21, 2, 148, 37, 3, 2, 2, 2, 149, 152, 7, 15, 2, 2, 150, 153, 7, 13, 2, 2, 151, 153, 5, 4, 3, 2, 152, 150, 3, 2, 2, 2, 152, 151, 3, 2, 2, 2, 153, 154, 3, 2, 2, 2, 154, 152, 3, 2, 2, 2, 154, 155, 3, 2, 2, 2, 155, 156, 3, 2, 2, 2, 156, 157, 7, 16, 2, 2, 157, 39, 3, 2, 2, 2, 158, 164, 5, 42, 22, 2, 159, 164, 5, 44, 23, 2, 160, 164, 5, 46, 24, 2, 161, 164, 5, 50, 26, 2, 162, 164, 5, 56, 29, 2, 163, 158, 3, 2, 2, 2, 163, 159, 3, 2, 2, 2, 163, 160, 3, 2, 2, 2, 163, 161, 3, 2, 2, 2, 163, 162, 3, 2, 2, 2, 164, 41, 3, 2, 2, 2, 165, 166, 8, 22, 1, 2, 166, 167, 5, 56, 29, 2, 167, 168, 7, 8, 2, 2, 168, 173, 3, 2, 2, 2, 169, 170, 12, 4, 2, 2, 170, 172, 7, 8, 2, 2, 171, 169, 3, 2, 2, 2, 172, 175, 3, 2, 2, 2, 173, 171, 3, 2, 2, 2, 173, 174, 3, 2, 2, 2, 174, 43, 3, 2, 2, 2, 175, 173, 3, 2, 2, 2, 176, 177, 7, 10, 2, 2, 177, 184, 5, 58, 30, 2, 178, 179, 7, 10, 2, 2, 179, 180, 7, 6, 2, 2, 180, 181, 5, 40, 21, 2, 181, 182, 7, 7, 2, 2, 182, 184, 3, 2, 2, 2, 183, 176, 3, 2, 2, 2, 183, 178, 3, 2, 2, 2, 184, 45, 3, 2, 2, 2, 185, 186, 8, 24, 1, 2, 186, 187, 5, 48, 25, 2, 187, 188, 7, 10, 2, 2, 188, 189, 5, 48, 25, 2, 189, 195, 3, 2, 2, 2, 190, 191, 12, 4, 2, 2, 191, 192, 7, 10, 2, 2, 192, 194, 5, 48, 25, 2, 193, 190, 3, 2, 2, 2, 194, 197, 3, 2, 2, 2, 195, 193, 3, 2, 2, 2, 195, 196, 3, 2, 2, 2, 196, 47, 3, 2, 2, 2, 197, 195, 3, 2, 2, 2, 198, 201, 5, 42, 22, 2, 199, 201, 5, 56, 29, 2, 200, 198, 3, 2, 2, 2, 200, 199, 3, 2, 2, 2, 201, 49, 3, 2, 2, 2, 202, 204, 5, 52, 27, 2, 203, 202, 3, 2, 2, 2, 203, 204, 3, 2, 2, 2, 204, 209, 3, 2, 2, 2, 205, 206, 5, 54, 28, 2, 206, 207, 7, 4, 2, 2, 207, 208, 5, 52, 27, 2, 208, 210, 3, 2, 2, 2, 209, 205, 3, 2, 2, 2, 210, 211, 3, 2, 2, 2, 211, 209, 3, 2, 2, 2, 211, 212, 3, 2, 2, 2, 212, 51, 3, 2, 2, 2, 213, 217, 5, 42, 22, 2, 214, 217, 5, 46, 24, 2, 215, 217, 5, 56, 29, 2, 216, 213, 3, 2, 2, 2, 216, 214, 3, 2, 2, 2, 216, 215, 3, 2, 2, 2, 217, 53, 3, 2, 2, 2, 218, 219, 7, 8, 2, 2, 219, 55, 3, 2, 2, 2, 220, 225, 5, 58, 30, 2, 221, 222, 7, 5, 2, 2, 222, 224, 5, 58, 30, 2, 223, 221, 3, 2, 2, 2, 224, 227, 3, 2, 2, 2, 225, 226, 3, 2, 2, 2, 225, 223, 3, 2, 2, 2, 226, 57, 3, 2, 2, 2, 227, 225, 3, 2, 2, 2, 228, 231, 7, 8, 2, 2, 229, 231, 5, 60, 31, 2, 230, 228, 3, 2, 2, 2, 230, 229, 3, 2, 2, 2, 231, 59, 3, 2, 2, 2, 232, 235, 5, 62, 32, 2, 233, 235, 5, 64, 33, 2, 234, 232, 3, 2, 2, 2, 234, 233, 3, 2, 2, 2, 235, 61, 3, 2, 2, 2, 236, 237, 7, 9, 2, 2, 237, 63, 3, 2, 2, 2, 238, 239, 7, 11, 2, 2, 239, 65, 3, 2, 2, 2, 27, 68, 70, 77, 88, 101, 108, 114, 121, 125, 131, 137, 145, 152, 154, 163, 173, 183, 195, 200, 203, 211, 216, 225, 230, 234] -------------------------------------------------------------------------------- /src/tale/syntax/grammar/Tale.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | T__3=4 5 | T__4=5 6 | IDENTIFIER=6 7 | NUMBER=7 8 | OPERATOR=8 9 | STRING=9 10 | WS=10 11 | NEWLINE=11 12 | SKIP_=12 13 | INDENT=13 14 | DEDENT=14 15 | '='=1 16 | ':'=2 17 | ','=3 18 | '('=4 19 | ')'=5 20 | -------------------------------------------------------------------------------- /src/tale/syntax/grammar/TaleLexer.interp: -------------------------------------------------------------------------------- 1 | token literal names: 2 | null 3 | '=' 4 | ':' 5 | ',' 6 | '(' 7 | ')' 8 | null 9 | null 10 | null 11 | null 12 | null 13 | null 14 | null 15 | 16 | token symbolic names: 17 | null 18 | null 19 | null 20 | null 21 | null 22 | null 23 | IDENTIFIER 24 | NUMBER 25 | OPERATOR 26 | STRING 27 | WS 28 | NEWLINE 29 | SKIP_ 30 | 31 | rule names: 32 | T__0 33 | T__1 34 | T__2 35 | T__3 36 | T__4 37 | IDENTIFIER 38 | NUMBER 39 | OPERATOR 40 | STRING 41 | WS 42 | NEWLINE 43 | COMMENT 44 | SKIP_ 45 | 46 | channel names: 47 | DEFAULT_TOKEN_CHANNEL 48 | HIDDEN 49 | 50 | mode names: 51 | DEFAULT_MODE 52 | 53 | atn: 54 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 14, 92, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 6, 7, 41, 10, 7, 13, 7, 14, 7, 42, 3, 8, 6, 8, 46, 10, 8, 13, 8, 14, 8, 47, 3, 9, 3, 9, 3, 10, 3, 10, 7, 10, 54, 10, 10, 12, 10, 14, 10, 57, 11, 10, 3, 10, 3, 10, 3, 11, 6, 11, 62, 10, 11, 13, 11, 14, 11, 63, 3, 11, 3, 11, 3, 12, 5, 12, 69, 10, 12, 3, 12, 3, 12, 7, 12, 73, 10, 12, 12, 12, 14, 12, 76, 11, 12, 3, 13, 3, 13, 3, 13, 3, 13, 7, 13, 82, 10, 13, 12, 13, 14, 13, 85, 11, 13, 3, 14, 3, 14, 5, 14, 89, 10, 14, 3, 14, 3, 14, 3, 55, 2, 15, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 25, 2, 27, 14, 3, 2, 7, 4, 2, 67, 92, 99, 124, 3, 2, 50, 59, 10, 2, 35, 35, 37, 40, 44, 45, 47, 49, 66, 66, 94, 94, 96, 96, 126, 126, 4, 2, 11, 11, 34, 34, 4, 2, 12, 12, 14, 15, 2, 98, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 2, 27, 3, 2, 2, 2, 3, 29, 3, 2, 2, 2, 5, 31, 3, 2, 2, 2, 7, 33, 3, 2, 2, 2, 9, 35, 3, 2, 2, 2, 11, 37, 3, 2, 2, 2, 13, 40, 3, 2, 2, 2, 15, 45, 3, 2, 2, 2, 17, 49, 3, 2, 2, 2, 19, 51, 3, 2, 2, 2, 21, 61, 3, 2, 2, 2, 23, 68, 3, 2, 2, 2, 25, 77, 3, 2, 2, 2, 27, 88, 3, 2, 2, 2, 29, 30, 7, 63, 2, 2, 30, 4, 3, 2, 2, 2, 31, 32, 7, 60, 2, 2, 32, 6, 3, 2, 2, 2, 33, 34, 7, 46, 2, 2, 34, 8, 3, 2, 2, 2, 35, 36, 7, 42, 2, 2, 36, 10, 3, 2, 2, 2, 37, 38, 7, 43, 2, 2, 38, 12, 3, 2, 2, 2, 39, 41, 9, 2, 2, 2, 40, 39, 3, 2, 2, 2, 41, 42, 3, 2, 2, 2, 42, 40, 3, 2, 2, 2, 42, 43, 3, 2, 2, 2, 43, 14, 3, 2, 2, 2, 44, 46, 9, 3, 2, 2, 45, 44, 3, 2, 2, 2, 46, 47, 3, 2, 2, 2, 47, 45, 3, 2, 2, 2, 47, 48, 3, 2, 2, 2, 48, 16, 3, 2, 2, 2, 49, 50, 9, 4, 2, 2, 50, 18, 3, 2, 2, 2, 51, 55, 7, 36, 2, 2, 52, 54, 11, 2, 2, 2, 53, 52, 3, 2, 2, 2, 54, 57, 3, 2, 2, 2, 55, 56, 3, 2, 2, 2, 55, 53, 3, 2, 2, 2, 56, 58, 3, 2, 2, 2, 57, 55, 3, 2, 2, 2, 58, 59, 7, 36, 2, 2, 59, 20, 3, 2, 2, 2, 60, 62, 9, 5, 2, 2, 61, 60, 3, 2, 2, 2, 62, 63, 3, 2, 2, 2, 63, 61, 3, 2, 2, 2, 63, 64, 3, 2, 2, 2, 64, 65, 3, 2, 2, 2, 65, 66, 8, 11, 2, 2, 66, 22, 3, 2, 2, 2, 67, 69, 7, 15, 2, 2, 68, 67, 3, 2, 2, 2, 68, 69, 3, 2, 2, 2, 69, 70, 3, 2, 2, 2, 70, 74, 7, 12, 2, 2, 71, 73, 7, 34, 2, 2, 72, 71, 3, 2, 2, 2, 73, 76, 3, 2, 2, 2, 74, 72, 3, 2, 2, 2, 74, 75, 3, 2, 2, 2, 75, 24, 3, 2, 2, 2, 76, 74, 3, 2, 2, 2, 77, 78, 7, 47, 2, 2, 78, 79, 7, 47, 2, 2, 79, 83, 3, 2, 2, 2, 80, 82, 10, 6, 2, 2, 81, 80, 3, 2, 2, 2, 82, 85, 3, 2, 2, 2, 83, 81, 3, 2, 2, 2, 83, 84, 3, 2, 2, 2, 84, 26, 3, 2, 2, 2, 85, 83, 3, 2, 2, 2, 86, 89, 5, 21, 11, 2, 87, 89, 5, 25, 13, 2, 88, 86, 3, 2, 2, 2, 88, 87, 3, 2, 2, 2, 89, 90, 3, 2, 2, 2, 90, 91, 8, 14, 2, 2, 91, 28, 3, 2, 2, 2, 11, 2, 42, 47, 55, 63, 68, 74, 83, 88, 3, 8, 2, 2] -------------------------------------------------------------------------------- /src/tale/syntax/grammar/TaleLexer.py: -------------------------------------------------------------------------------- 1 | # Generated from tale/syntax/grammar/Tale.g4 by ANTLR 4.8 2 | from antlr4 import * 3 | from io import StringIO 4 | from typing.io import TextIO 5 | import sys 6 | 7 | 8 | from antlr_denter.DenterHelper import DenterHelper 9 | from .TaleParser import TaleParser 10 | 11 | 12 | 13 | def serializedATN(): 14 | with StringIO() as buf: 15 | buf.write("\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\16") 16 | buf.write("\\\b\1\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7") 17 | buf.write("\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\4\f\t\f\4\r\t\r\4\16") 18 | buf.write("\t\16\3\2\3\2\3\3\3\3\3\4\3\4\3\5\3\5\3\6\3\6\3\7\6\7") 19 | buf.write(")\n\7\r\7\16\7*\3\b\6\b.\n\b\r\b\16\b/\3\t\3\t\3\n\3\n") 20 | buf.write("\7\n\66\n\n\f\n\16\n9\13\n\3\n\3\n\3\13\6\13>\n\13\r\13") 21 | buf.write("\16\13?\3\13\3\13\3\f\5\fE\n\f\3\f\3\f\7\fI\n\f\f\f\16") 22 | buf.write("\fL\13\f\3\r\3\r\3\r\3\r\7\rR\n\r\f\r\16\rU\13\r\3\16") 23 | buf.write("\3\16\5\16Y\n\16\3\16\3\16\3\67\2\17\3\3\5\4\7\5\t\6\13") 24 | buf.write("\7\r\b\17\t\21\n\23\13\25\f\27\r\31\2\33\16\3\2\7\4\2") 25 | buf.write("C\\c|\3\2\62;\n\2##%(,-/\61BB^^``~~\4\2\13\13\"\"\4\2") 26 | buf.write("\f\f\16\17\2b\2\3\3\2\2\2\2\5\3\2\2\2\2\7\3\2\2\2\2\t") 27 | buf.write("\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2\2\2\21\3") 28 | buf.write("\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\2\33\3\2") 29 | buf.write("\2\2\3\35\3\2\2\2\5\37\3\2\2\2\7!\3\2\2\2\t#\3\2\2\2\13") 30 | buf.write("%\3\2\2\2\r(\3\2\2\2\17-\3\2\2\2\21\61\3\2\2\2\23\63\3") 31 | buf.write("\2\2\2\25=\3\2\2\2\27D\3\2\2\2\31M\3\2\2\2\33X\3\2\2\2") 32 | buf.write("\35\36\7?\2\2\36\4\3\2\2\2\37 \7<\2\2 \6\3\2\2\2!\"\7") 33 | buf.write(".\2\2\"\b\3\2\2\2#$\7*\2\2$\n\3\2\2\2%&\7+\2\2&\f\3\2") 34 | buf.write("\2\2\')\t\2\2\2(\'\3\2\2\2)*\3\2\2\2*(\3\2\2\2*+\3\2\2") 35 | buf.write("\2+\16\3\2\2\2,.\t\3\2\2-,\3\2\2\2./\3\2\2\2/-\3\2\2\2") 36 | buf.write("/\60\3\2\2\2\60\20\3\2\2\2\61\62\t\4\2\2\62\22\3\2\2\2") 37 | buf.write("\63\67\7$\2\2\64\66\13\2\2\2\65\64\3\2\2\2\669\3\2\2\2") 38 | buf.write("\678\3\2\2\2\67\65\3\2\2\28:\3\2\2\29\67\3\2\2\2:;\7$") 39 | buf.write("\2\2;\24\3\2\2\2<>\t\5\2\2=<\3\2\2\2>?\3\2\2\2?=\3\2\2") 40 | buf.write("\2?@\3\2\2\2@A\3\2\2\2AB\b\13\2\2B\26\3\2\2\2CE\7\17\2") 41 | buf.write("\2DC\3\2\2\2DE\3\2\2\2EF\3\2\2\2FJ\7\f\2\2GI\7\"\2\2H") 42 | buf.write("G\3\2\2\2IL\3\2\2\2JH\3\2\2\2JK\3\2\2\2K\30\3\2\2\2LJ") 43 | buf.write("\3\2\2\2MN\7/\2\2NO\7/\2\2OS\3\2\2\2PR\n\6\2\2QP\3\2\2") 44 | buf.write("\2RU\3\2\2\2SQ\3\2\2\2ST\3\2\2\2T\32\3\2\2\2US\3\2\2\2") 45 | buf.write("VY\5\25\13\2WY\5\31\r\2XV\3\2\2\2XW\3\2\2\2YZ\3\2\2\2") 46 | buf.write("Z[\b\16\2\2[\34\3\2\2\2\13\2*/\67?DJSX\3\b\2\2") 47 | return buf.getvalue() 48 | 49 | 50 | class TaleLexer(Lexer): 51 | 52 | atn = ATNDeserializer().deserialize(serializedATN()) 53 | 54 | decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ] 55 | 56 | T__0 = 1 57 | T__1 = 2 58 | T__2 = 3 59 | T__3 = 4 60 | T__4 = 5 61 | IDENTIFIER = 6 62 | NUMBER = 7 63 | OPERATOR = 8 64 | STRING = 9 65 | WS = 10 66 | NEWLINE = 11 67 | SKIP_ = 12 68 | 69 | channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ] 70 | 71 | modeNames = [ "DEFAULT_MODE" ] 72 | 73 | literalNames = [ "", 74 | "'='", "':'", "','", "'('", "')'" ] 75 | 76 | symbolicNames = [ "", 77 | "IDENTIFIER", "NUMBER", "OPERATOR", "STRING", "WS", "NEWLINE", 78 | "SKIP_" ] 79 | 80 | ruleNames = [ "T__0", "T__1", "T__2", "T__3", "T__4", "IDENTIFIER", 81 | "NUMBER", "OPERATOR", "STRING", "WS", "NEWLINE", "COMMENT", 82 | "SKIP_" ] 83 | 84 | grammarFileName = "Tale.g4" 85 | 86 | def __init__(self, input=None, output:TextIO = sys.stdout): 87 | super().__init__(input, output) 88 | self.checkVersion("4.8") 89 | self._interp = LexerATNSimulator(self, self.atn, self.decisionsToDFA, PredictionContextCache()) 90 | self._actions = None 91 | self._predicates = None 92 | 93 | 94 | class TaleDenter(DenterHelper): 95 | def __init__(self, lexer, nl_token, indent_token, dedent_token, ignore_eof): 96 | super().__init__(nl_token, indent_token, dedent_token, ignore_eof) 97 | self.lexer: TaleLexer = lexer 98 | 99 | def pull_token(self): 100 | return super(TaleLexer, self.lexer).nextToken() 101 | 102 | denter = None 103 | 104 | def nextToken(self): 105 | if not self.denter: 106 | self.denter = self.TaleDenter(self, self.NEWLINE, TaleParser.INDENT, TaleParser.DEDENT, False) 107 | 108 | return self.denter.next_token() 109 | 110 | 111 | -------------------------------------------------------------------------------- /src/tale/syntax/grammar/TaleLexer.tokens: -------------------------------------------------------------------------------- 1 | T__0=1 2 | T__1=2 3 | T__2=3 4 | T__3=4 5 | T__4=5 6 | IDENTIFIER=6 7 | NUMBER=7 8 | OPERATOR=8 9 | STRING=9 10 | WS=10 11 | NEWLINE=11 12 | SKIP_=12 13 | '='=1 14 | ':'=2 15 | ','=3 16 | '('=4 17 | ')'=5 18 | -------------------------------------------------------------------------------- /src/tale/syntax/grammar/TaleListener.py: -------------------------------------------------------------------------------- 1 | # Generated from tale/syntax/grammar/Tale.g4 by ANTLR 4.8 2 | from antlr4 import * 3 | if __name__ is not None and "." in __name__: 4 | from .TaleParser import TaleParser 5 | else: 6 | from TaleParser import TaleParser 7 | 8 | # This class defines a complete listener for a parse tree produced by TaleParser. 9 | class TaleListener(ParseTreeListener): 10 | 11 | # Enter a parse tree produced by TaleParser#program. 12 | def enterProgram(self, ctx:TaleParser.ProgramContext): 13 | pass 14 | 15 | # Exit a parse tree produced by TaleParser#program. 16 | def exitProgram(self, ctx:TaleParser.ProgramContext): 17 | pass 18 | 19 | 20 | # Enter a parse tree produced by TaleParser#statement. 21 | def enterStatement(self, ctx:TaleParser.StatementContext): 22 | pass 23 | 24 | # Exit a parse tree produced by TaleParser#statement. 25 | def exitStatement(self, ctx:TaleParser.StatementContext): 26 | pass 27 | 28 | 29 | # Enter a parse tree produced by TaleParser#assignment. 30 | def enterAssignment(self, ctx:TaleParser.AssignmentContext): 31 | pass 32 | 33 | # Exit a parse tree produced by TaleParser#assignment. 34 | def exitAssignment(self, ctx:TaleParser.AssignmentContext): 35 | pass 36 | 37 | 38 | # Enter a parse tree produced by TaleParser#form. 39 | def enterForm(self, ctx:TaleParser.FormContext): 40 | pass 41 | 42 | # Exit a parse tree produced by TaleParser#form. 43 | def exitForm(self, ctx:TaleParser.FormContext): 44 | pass 45 | 46 | 47 | # Enter a parse tree produced by TaleParser#unaryForm. 48 | def enterUnaryForm(self, ctx:TaleParser.UnaryFormContext): 49 | pass 50 | 51 | # Exit a parse tree produced by TaleParser#unaryForm. 52 | def exitUnaryForm(self, ctx:TaleParser.UnaryFormContext): 53 | pass 54 | 55 | 56 | # Enter a parse tree produced by TaleParser#prefixOperatorForm. 57 | def enterPrefixOperatorForm(self, ctx:TaleParser.PrefixOperatorFormContext): 58 | pass 59 | 60 | # Exit a parse tree produced by TaleParser#prefixOperatorForm. 61 | def exitPrefixOperatorForm(self, ctx:TaleParser.PrefixOperatorFormContext): 62 | pass 63 | 64 | 65 | # Enter a parse tree produced by TaleParser#binaryForm. 66 | def enterBinaryForm(self, ctx:TaleParser.BinaryFormContext): 67 | pass 68 | 69 | # Exit a parse tree produced by TaleParser#binaryForm. 70 | def exitBinaryForm(self, ctx:TaleParser.BinaryFormContext): 71 | pass 72 | 73 | 74 | # Enter a parse tree produced by TaleParser#keywordForm. 75 | def enterKeywordForm(self, ctx:TaleParser.KeywordFormContext): 76 | pass 77 | 78 | # Exit a parse tree produced by TaleParser#keywordForm. 79 | def exitKeywordForm(self, ctx:TaleParser.KeywordFormContext): 80 | pass 81 | 82 | 83 | # Enter a parse tree produced by TaleParser#primitiveForm. 84 | def enterPrimitiveForm(self, ctx:TaleParser.PrimitiveFormContext): 85 | pass 86 | 87 | # Exit a parse tree produced by TaleParser#primitiveForm. 88 | def exitPrimitiveForm(self, ctx:TaleParser.PrimitiveFormContext): 89 | pass 90 | 91 | 92 | # Enter a parse tree produced by TaleParser#parameter. 93 | def enterParameter(self, ctx:TaleParser.ParameterContext): 94 | pass 95 | 96 | # Exit a parse tree produced by TaleParser#parameter. 97 | def exitParameter(self, ctx:TaleParser.ParameterContext): 98 | pass 99 | 100 | 101 | # Enter a parse tree produced by TaleParser#tupleParameter. 102 | def enterTupleParameter(self, ctx:TaleParser.TupleParameterContext): 103 | pass 104 | 105 | # Exit a parse tree produced by TaleParser#tupleParameter. 106 | def exitTupleParameter(self, ctx:TaleParser.TupleParameterContext): 107 | pass 108 | 109 | 110 | # Enter a parse tree produced by TaleParser#singleParameter. 111 | def enterSingleParameter(self, ctx:TaleParser.SingleParameterContext): 112 | pass 113 | 114 | # Exit a parse tree produced by TaleParser#singleParameter. 115 | def exitSingleParameter(self, ctx:TaleParser.SingleParameterContext): 116 | pass 117 | 118 | 119 | # Enter a parse tree produced by TaleParser#simpleParameter. 120 | def enterSimpleParameter(self, ctx:TaleParser.SimpleParameterContext): 121 | pass 122 | 123 | # Exit a parse tree produced by TaleParser#simpleParameter. 124 | def exitSimpleParameter(self, ctx:TaleParser.SimpleParameterContext): 125 | pass 126 | 127 | 128 | # Enter a parse tree produced by TaleParser#patternMatchingParameter. 129 | def enterPatternMatchingParameter(self, ctx:TaleParser.PatternMatchingParameterContext): 130 | pass 131 | 132 | # Exit a parse tree produced by TaleParser#patternMatchingParameter. 133 | def exitPatternMatchingParameter(self, ctx:TaleParser.PatternMatchingParameterContext): 134 | pass 135 | 136 | 137 | # Enter a parse tree produced by TaleParser#parameterName. 138 | def enterParameterName(self, ctx:TaleParser.ParameterNameContext): 139 | pass 140 | 141 | # Exit a parse tree produced by TaleParser#parameterName. 142 | def exitParameterName(self, ctx:TaleParser.ParameterNameContext): 143 | pass 144 | 145 | 146 | # Enter a parse tree produced by TaleParser#parameterType. 147 | def enterParameterType(self, ctx:TaleParser.ParameterTypeContext): 148 | pass 149 | 150 | # Exit a parse tree produced by TaleParser#parameterType. 151 | def exitParameterType(self, ctx:TaleParser.ParameterTypeContext): 152 | pass 153 | 154 | 155 | # Enter a parse tree produced by TaleParser#assignmentBody. 156 | def enterAssignmentBody(self, ctx:TaleParser.AssignmentBodyContext): 157 | pass 158 | 159 | # Exit a parse tree produced by TaleParser#assignmentBody. 160 | def exitAssignmentBody(self, ctx:TaleParser.AssignmentBodyContext): 161 | pass 162 | 163 | 164 | # Enter a parse tree produced by TaleParser#simpleAssignmentBody. 165 | def enterSimpleAssignmentBody(self, ctx:TaleParser.SimpleAssignmentBodyContext): 166 | pass 167 | 168 | # Exit a parse tree produced by TaleParser#simpleAssignmentBody. 169 | def exitSimpleAssignmentBody(self, ctx:TaleParser.SimpleAssignmentBodyContext): 170 | pass 171 | 172 | 173 | # Enter a parse tree produced by TaleParser#compoundAssignmentBody. 174 | def enterCompoundAssignmentBody(self, ctx:TaleParser.CompoundAssignmentBodyContext): 175 | pass 176 | 177 | # Exit a parse tree produced by TaleParser#compoundAssignmentBody. 178 | def exitCompoundAssignmentBody(self, ctx:TaleParser.CompoundAssignmentBodyContext): 179 | pass 180 | 181 | 182 | # Enter a parse tree produced by TaleParser#expression. 183 | def enterExpression(self, ctx:TaleParser.ExpressionContext): 184 | pass 185 | 186 | # Exit a parse tree produced by TaleParser#expression. 187 | def exitExpression(self, ctx:TaleParser.ExpressionContext): 188 | pass 189 | 190 | 191 | # Enter a parse tree produced by TaleParser#unary. 192 | def enterUnary(self, ctx:TaleParser.UnaryContext): 193 | pass 194 | 195 | # Exit a parse tree produced by TaleParser#unary. 196 | def exitUnary(self, ctx:TaleParser.UnaryContext): 197 | pass 198 | 199 | 200 | # Enter a parse tree produced by TaleParser#prefixOperator. 201 | def enterPrefixOperator(self, ctx:TaleParser.PrefixOperatorContext): 202 | pass 203 | 204 | # Exit a parse tree produced by TaleParser#prefixOperator. 205 | def exitPrefixOperator(self, ctx:TaleParser.PrefixOperatorContext): 206 | pass 207 | 208 | 209 | # Enter a parse tree produced by TaleParser#binary. 210 | def enterBinary(self, ctx:TaleParser.BinaryContext): 211 | pass 212 | 213 | # Exit a parse tree produced by TaleParser#binary. 214 | def exitBinary(self, ctx:TaleParser.BinaryContext): 215 | pass 216 | 217 | 218 | # Enter a parse tree produced by TaleParser#binaryOperand. 219 | def enterBinaryOperand(self, ctx:TaleParser.BinaryOperandContext): 220 | pass 221 | 222 | # Exit a parse tree produced by TaleParser#binaryOperand. 223 | def exitBinaryOperand(self, ctx:TaleParser.BinaryOperandContext): 224 | pass 225 | 226 | 227 | # Enter a parse tree produced by TaleParser#keyword. 228 | def enterKeyword(self, ctx:TaleParser.KeywordContext): 229 | pass 230 | 231 | # Exit a parse tree produced by TaleParser#keyword. 232 | def exitKeyword(self, ctx:TaleParser.KeywordContext): 233 | pass 234 | 235 | 236 | # Enter a parse tree produced by TaleParser#keywordArgument. 237 | def enterKeywordArgument(self, ctx:TaleParser.KeywordArgumentContext): 238 | pass 239 | 240 | # Exit a parse tree produced by TaleParser#keywordArgument. 241 | def exitKeywordArgument(self, ctx:TaleParser.KeywordArgumentContext): 242 | pass 243 | 244 | 245 | # Enter a parse tree produced by TaleParser#keywordName. 246 | def enterKeywordName(self, ctx:TaleParser.KeywordNameContext): 247 | pass 248 | 249 | # Exit a parse tree produced by TaleParser#keywordName. 250 | def exitKeywordName(self, ctx:TaleParser.KeywordNameContext): 251 | pass 252 | 253 | 254 | # Enter a parse tree produced by TaleParser#primitive. 255 | def enterPrimitive(self, ctx:TaleParser.PrimitiveContext): 256 | pass 257 | 258 | # Exit a parse tree produced by TaleParser#primitive. 259 | def exitPrimitive(self, ctx:TaleParser.PrimitiveContext): 260 | pass 261 | 262 | 263 | # Enter a parse tree produced by TaleParser#primitiveItem. 264 | def enterPrimitiveItem(self, ctx:TaleParser.PrimitiveItemContext): 265 | pass 266 | 267 | # Exit a parse tree produced by TaleParser#primitiveItem. 268 | def exitPrimitiveItem(self, ctx:TaleParser.PrimitiveItemContext): 269 | pass 270 | 271 | 272 | # Enter a parse tree produced by TaleParser#literal. 273 | def enterLiteral(self, ctx:TaleParser.LiteralContext): 274 | pass 275 | 276 | # Exit a parse tree produced by TaleParser#literal. 277 | def exitLiteral(self, ctx:TaleParser.LiteralContext): 278 | pass 279 | 280 | 281 | # Enter a parse tree produced by TaleParser#intLiteral. 282 | def enterIntLiteral(self, ctx:TaleParser.IntLiteralContext): 283 | pass 284 | 285 | # Exit a parse tree produced by TaleParser#intLiteral. 286 | def exitIntLiteral(self, ctx:TaleParser.IntLiteralContext): 287 | pass 288 | 289 | 290 | # Enter a parse tree produced by TaleParser#stringLiteral. 291 | def enterStringLiteral(self, ctx:TaleParser.StringLiteralContext): 292 | pass 293 | 294 | # Exit a parse tree produced by TaleParser#stringLiteral. 295 | def exitStringLiteral(self, ctx:TaleParser.StringLiteralContext): 296 | pass 297 | 298 | 299 | 300 | del TaleParser -------------------------------------------------------------------------------- /src/tale/syntax/grammar/TaleParser.py: -------------------------------------------------------------------------------- 1 | # Generated from tale/syntax/grammar/Tale.g4 by ANTLR 4.8 2 | # encoding: utf-8 3 | from antlr4 import * 4 | from io import StringIO 5 | import sys 6 | if sys.version_info[1] > 5: 7 | from typing import TextIO 8 | else: 9 | from typing.io import TextIO 10 | 11 | 12 | def serializedATN(): 13 | with StringIO() as buf: 14 | buf.write("\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\20") 15 | buf.write("\u00f1\4\2\t\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7") 16 | buf.write("\4\b\t\b\4\t\t\t\4\n\t\n\4\13\t\13\4\f\t\f\4\r\t\r\4\16") 17 | buf.write("\t\16\4\17\t\17\4\20\t\20\4\21\t\21\4\22\t\22\4\23\t\23") 18 | buf.write("\4\24\t\24\4\25\t\25\4\26\t\26\4\27\t\27\4\30\t\30\4\31") 19 | buf.write("\t\31\4\32\t\32\4\33\t\33\4\34\t\34\4\35\t\35\4\36\t\36") 20 | buf.write("\4\37\t\37\4 \t \4!\t!\3\2\3\2\7\2E\n\2\f\2\16\2H\13\2") 21 | buf.write("\3\2\3\2\3\3\3\3\5\3N\n\3\3\4\3\4\3\4\3\4\3\5\3\5\3\5") 22 | buf.write("\3\5\3\5\5\5Y\n\5\3\6\3\6\3\6\3\7\3\7\3\7\3\b\3\b\3\b") 23 | buf.write("\3\b\3\t\5\tf\n\t\3\t\3\t\3\t\6\tk\n\t\r\t\16\tl\3\n\3") 24 | buf.write("\n\3\13\3\13\5\13s\n\13\3\f\3\f\3\f\6\fx\n\f\r\f\16\f") 25 | buf.write("y\3\r\3\r\5\r~\n\r\3\16\3\16\3\16\3\16\5\16\u0084\n\16") 26 | buf.write("\3\16\3\16\3\17\3\17\5\17\u008a\n\17\3\20\3\20\3\21\3") 27 | buf.write("\21\3\22\3\22\5\22\u0092\n\22\3\23\3\23\3\24\3\24\3\24") 28 | buf.write("\6\24\u0099\n\24\r\24\16\24\u009a\3\24\3\24\3\25\3\25") 29 | buf.write("\3\25\3\25\3\25\5\25\u00a4\n\25\3\26\3\26\3\26\3\26\3") 30 | buf.write("\26\3\26\7\26\u00ac\n\26\f\26\16\26\u00af\13\26\3\27\3") 31 | buf.write("\27\3\27\3\27\3\27\3\27\3\27\5\27\u00b8\n\27\3\30\3\30") 32 | buf.write("\3\30\3\30\3\30\3\30\3\30\3\30\7\30\u00c2\n\30\f\30\16") 33 | buf.write("\30\u00c5\13\30\3\31\3\31\5\31\u00c9\n\31\3\32\5\32\u00cc") 34 | buf.write("\n\32\3\32\3\32\3\32\3\32\6\32\u00d2\n\32\r\32\16\32\u00d3") 35 | buf.write("\3\33\3\33\3\33\5\33\u00d9\n\33\3\34\3\34\3\35\3\35\3") 36 | buf.write("\35\7\35\u00e0\n\35\f\35\16\35\u00e3\13\35\3\36\3\36\5") 37 | buf.write("\36\u00e7\n\36\3\37\3\37\5\37\u00eb\n\37\3 \3 \3!\3!\3") 38 | buf.write("!\3\u00e1\4*.\"\2\4\6\b\n\f\16\20\22\24\26\30\32\34\36") 39 | buf.write(" \"$&(*,.\60\62\64\668:<>@\2\2\2\u00f0\2F\3\2\2\2\4M\3") 40 | buf.write("\2\2\2\6O\3\2\2\2\bX\3\2\2\2\nZ\3\2\2\2\f]\3\2\2\2\16") 41 | buf.write("`\3\2\2\2\20e\3\2\2\2\22n\3\2\2\2\24r\3\2\2\2\26t\3\2") 42 | buf.write("\2\2\30}\3\2\2\2\32\177\3\2\2\2\34\u0089\3\2\2\2\36\u008b") 43 | buf.write("\3\2\2\2 \u008d\3\2\2\2\"\u0091\3\2\2\2$\u0093\3\2\2\2") 44 | buf.write("&\u0095\3\2\2\2(\u00a3\3\2\2\2*\u00a5\3\2\2\2,\u00b7\3") 45 | buf.write("\2\2\2.\u00b9\3\2\2\2\60\u00c8\3\2\2\2\62\u00cb\3\2\2") 46 | buf.write("\2\64\u00d8\3\2\2\2\66\u00da\3\2\2\28\u00dc\3\2\2\2:\u00e6") 47 | buf.write("\3\2\2\2<\u00ea\3\2\2\2>\u00ec\3\2\2\2@\u00ee\3\2\2\2") 48 | buf.write("BE\7\r\2\2CE\5\4\3\2DB\3\2\2\2DC\3\2\2\2EH\3\2\2\2FD\3") 49 | buf.write("\2\2\2FG\3\2\2\2GI\3\2\2\2HF\3\2\2\2IJ\7\2\2\3J\3\3\2") 50 | buf.write("\2\2KN\5\6\4\2LN\5(\25\2MK\3\2\2\2ML\3\2\2\2N\5\3\2\2") 51 | buf.write("\2OP\5\b\5\2PQ\7\3\2\2QR\5\"\22\2R\7\3\2\2\2SY\5\n\6\2") 52 | buf.write("TY\5\f\7\2UY\5\16\b\2VY\5\20\t\2WY\5\22\n\2XS\3\2\2\2") 53 | buf.write("XT\3\2\2\2XU\3\2\2\2XV\3\2\2\2XW\3\2\2\2Y\t\3\2\2\2Z[") 54 | buf.write("\5\24\13\2[\\\7\b\2\2\\\13\3\2\2\2]^\7\n\2\2^_\5\30\r") 55 | buf.write("\2_\r\3\2\2\2`a\5\24\13\2ab\7\n\2\2bc\5\24\13\2c\17\3") 56 | buf.write("\2\2\2df\5\24\13\2ed\3\2\2\2ef\3\2\2\2fj\3\2\2\2gh\7\b") 57 | buf.write("\2\2hi\7\4\2\2ik\5\24\13\2jg\3\2\2\2kl\3\2\2\2lj\3\2\2") 58 | buf.write("\2lm\3\2\2\2m\21\3\2\2\2no\7\b\2\2o\23\3\2\2\2ps\5\30") 59 | buf.write("\r\2qs\5\26\f\2rp\3\2\2\2rq\3\2\2\2s\25\3\2\2\2tw\5\30") 60 | buf.write("\r\2uv\7\5\2\2vx\5\30\r\2wu\3\2\2\2xy\3\2\2\2yw\3\2\2") 61 | buf.write("\2yz\3\2\2\2z\27\3\2\2\2{~\5\32\16\2|~\5\34\17\2}{\3\2") 62 | buf.write("\2\2}|\3\2\2\2~\31\3\2\2\2\177\u0080\7\6\2\2\u0080\u0083") 63 | buf.write("\5\36\20\2\u0081\u0082\7\4\2\2\u0082\u0084\5 \21\2\u0083") 64 | buf.write("\u0081\3\2\2\2\u0083\u0084\3\2\2\2\u0084\u0085\3\2\2\2") 65 | buf.write("\u0085\u0086\7\7\2\2\u0086\33\3\2\2\2\u0087\u008a\7\b") 66 | buf.write("\2\2\u0088\u008a\5<\37\2\u0089\u0087\3\2\2\2\u0089\u0088") 67 | buf.write("\3\2\2\2\u008a\35\3\2\2\2\u008b\u008c\7\b\2\2\u008c\37") 68 | buf.write("\3\2\2\2\u008d\u008e\7\b\2\2\u008e!\3\2\2\2\u008f\u0092") 69 | buf.write("\5$\23\2\u0090\u0092\5&\24\2\u0091\u008f\3\2\2\2\u0091") 70 | buf.write("\u0090\3\2\2\2\u0092#\3\2\2\2\u0093\u0094\5(\25\2\u0094") 71 | buf.write("%\3\2\2\2\u0095\u0098\7\17\2\2\u0096\u0099\7\r\2\2\u0097") 72 | buf.write("\u0099\5\4\3\2\u0098\u0096\3\2\2\2\u0098\u0097\3\2\2\2") 73 | buf.write("\u0099\u009a\3\2\2\2\u009a\u0098\3\2\2\2\u009a\u009b\3") 74 | buf.write("\2\2\2\u009b\u009c\3\2\2\2\u009c\u009d\7\20\2\2\u009d") 75 | buf.write("\'\3\2\2\2\u009e\u00a4\5*\26\2\u009f\u00a4\5,\27\2\u00a0") 76 | buf.write("\u00a4\5.\30\2\u00a1\u00a4\5\62\32\2\u00a2\u00a4\58\35") 77 | buf.write("\2\u00a3\u009e\3\2\2\2\u00a3\u009f\3\2\2\2\u00a3\u00a0") 78 | buf.write("\3\2\2\2\u00a3\u00a1\3\2\2\2\u00a3\u00a2\3\2\2\2\u00a4") 79 | buf.write(")\3\2\2\2\u00a5\u00a6\b\26\1\2\u00a6\u00a7\58\35\2\u00a7") 80 | buf.write("\u00a8\7\b\2\2\u00a8\u00ad\3\2\2\2\u00a9\u00aa\f\4\2\2") 81 | buf.write("\u00aa\u00ac\7\b\2\2\u00ab\u00a9\3\2\2\2\u00ac\u00af\3") 82 | buf.write("\2\2\2\u00ad\u00ab\3\2\2\2\u00ad\u00ae\3\2\2\2\u00ae+") 83 | buf.write("\3\2\2\2\u00af\u00ad\3\2\2\2\u00b0\u00b1\7\n\2\2\u00b1") 84 | buf.write("\u00b8\5:\36\2\u00b2\u00b3\7\n\2\2\u00b3\u00b4\7\6\2\2") 85 | buf.write("\u00b4\u00b5\5(\25\2\u00b5\u00b6\7\7\2\2\u00b6\u00b8\3") 86 | buf.write("\2\2\2\u00b7\u00b0\3\2\2\2\u00b7\u00b2\3\2\2\2\u00b8-") 87 | buf.write("\3\2\2\2\u00b9\u00ba\b\30\1\2\u00ba\u00bb\5\60\31\2\u00bb") 88 | buf.write("\u00bc\7\n\2\2\u00bc\u00bd\5\60\31\2\u00bd\u00c3\3\2\2") 89 | buf.write("\2\u00be\u00bf\f\4\2\2\u00bf\u00c0\7\n\2\2\u00c0\u00c2") 90 | buf.write("\5\60\31\2\u00c1\u00be\3\2\2\2\u00c2\u00c5\3\2\2\2\u00c3") 91 | buf.write("\u00c1\3\2\2\2\u00c3\u00c4\3\2\2\2\u00c4/\3\2\2\2\u00c5") 92 | buf.write("\u00c3\3\2\2\2\u00c6\u00c9\5*\26\2\u00c7\u00c9\58\35\2") 93 | buf.write("\u00c8\u00c6\3\2\2\2\u00c8\u00c7\3\2\2\2\u00c9\61\3\2") 94 | buf.write("\2\2\u00ca\u00cc\5\64\33\2\u00cb\u00ca\3\2\2\2\u00cb\u00cc") 95 | buf.write("\3\2\2\2\u00cc\u00d1\3\2\2\2\u00cd\u00ce\5\66\34\2\u00ce") 96 | buf.write("\u00cf\7\4\2\2\u00cf\u00d0\5\64\33\2\u00d0\u00d2\3\2\2") 97 | buf.write("\2\u00d1\u00cd\3\2\2\2\u00d2\u00d3\3\2\2\2\u00d3\u00d1") 98 | buf.write("\3\2\2\2\u00d3\u00d4\3\2\2\2\u00d4\63\3\2\2\2\u00d5\u00d9") 99 | buf.write("\5*\26\2\u00d6\u00d9\5.\30\2\u00d7\u00d9\58\35\2\u00d8") 100 | buf.write("\u00d5\3\2\2\2\u00d8\u00d6\3\2\2\2\u00d8\u00d7\3\2\2\2") 101 | buf.write("\u00d9\65\3\2\2\2\u00da\u00db\7\b\2\2\u00db\67\3\2\2\2") 102 | buf.write("\u00dc\u00e1\5:\36\2\u00dd\u00de\7\5\2\2\u00de\u00e0\5") 103 | buf.write(":\36\2\u00df\u00dd\3\2\2\2\u00e0\u00e3\3\2\2\2\u00e1\u00e2") 104 | buf.write("\3\2\2\2\u00e1\u00df\3\2\2\2\u00e29\3\2\2\2\u00e3\u00e1") 105 | buf.write("\3\2\2\2\u00e4\u00e7\7\b\2\2\u00e5\u00e7\5<\37\2\u00e6") 106 | buf.write("\u00e4\3\2\2\2\u00e6\u00e5\3\2\2\2\u00e7;\3\2\2\2\u00e8") 107 | buf.write("\u00eb\5> \2\u00e9\u00eb\5@!\2\u00ea\u00e8\3\2\2\2\u00ea") 108 | buf.write("\u00e9\3\2\2\2\u00eb=\3\2\2\2\u00ec\u00ed\7\t\2\2\u00ed") 109 | buf.write("?\3\2\2\2\u00ee\u00ef\7\13\2\2\u00efA\3\2\2\2\33DFMXe") 110 | buf.write("lry}\u0083\u0089\u0091\u0098\u009a\u00a3\u00ad\u00b7\u00c3") 111 | buf.write("\u00c8\u00cb\u00d3\u00d8\u00e1\u00e6\u00ea") 112 | return buf.getvalue() 113 | 114 | 115 | class TaleParser ( Parser ): 116 | 117 | grammarFileName = "Tale.g4" 118 | 119 | atn = ATNDeserializer().deserialize(serializedATN()) 120 | 121 | decisionsToDFA = [ DFA(ds, i) for i, ds in enumerate(atn.decisionToState) ] 122 | 123 | sharedContextCache = PredictionContextCache() 124 | 125 | literalNames = [ "", "'='", "':'", "','", "'('", "')'" ] 126 | 127 | symbolicNames = [ "", "", "", "", 128 | "", "", "IDENTIFIER", "NUMBER", 129 | "OPERATOR", "STRING", "WS", "NEWLINE", "SKIP_", "INDENT", 130 | "DEDENT" ] 131 | 132 | RULE_program = 0 133 | RULE_statement = 1 134 | RULE_assignment = 2 135 | RULE_form = 3 136 | RULE_unaryForm = 4 137 | RULE_prefixOperatorForm = 5 138 | RULE_binaryForm = 6 139 | RULE_keywordForm = 7 140 | RULE_primitiveForm = 8 141 | RULE_parameter = 9 142 | RULE_tupleParameter = 10 143 | RULE_singleParameter = 11 144 | RULE_simpleParameter = 12 145 | RULE_patternMatchingParameter = 13 146 | RULE_parameterName = 14 147 | RULE_parameterType = 15 148 | RULE_assignmentBody = 16 149 | RULE_simpleAssignmentBody = 17 150 | RULE_compoundAssignmentBody = 18 151 | RULE_expression = 19 152 | RULE_unary = 20 153 | RULE_prefixOperator = 21 154 | RULE_binary = 22 155 | RULE_binaryOperand = 23 156 | RULE_keyword = 24 157 | RULE_keywordArgument = 25 158 | RULE_keywordName = 26 159 | RULE_primitive = 27 160 | RULE_primitiveItem = 28 161 | RULE_literal = 29 162 | RULE_intLiteral = 30 163 | RULE_stringLiteral = 31 164 | 165 | ruleNames = [ "program", "statement", "assignment", "form", "unaryForm", 166 | "prefixOperatorForm", "binaryForm", "keywordForm", "primitiveForm", 167 | "parameter", "tupleParameter", "singleParameter", "simpleParameter", 168 | "patternMatchingParameter", "parameterName", "parameterType", 169 | "assignmentBody", "simpleAssignmentBody", "compoundAssignmentBody", 170 | "expression", "unary", "prefixOperator", "binary", "binaryOperand", 171 | "keyword", "keywordArgument", "keywordName", "primitive", 172 | "primitiveItem", "literal", "intLiteral", "stringLiteral" ] 173 | 174 | EOF = Token.EOF 175 | T__0=1 176 | T__1=2 177 | T__2=3 178 | T__3=4 179 | T__4=5 180 | IDENTIFIER=6 181 | NUMBER=7 182 | OPERATOR=8 183 | STRING=9 184 | WS=10 185 | NEWLINE=11 186 | SKIP_=12 187 | INDENT=13 188 | DEDENT=14 189 | 190 | def __init__(self, input:TokenStream, output:TextIO = sys.stdout): 191 | super().__init__(input, output) 192 | self.checkVersion("4.8") 193 | self._interp = ParserATNSimulator(self, self.atn, self.decisionsToDFA, self.sharedContextCache) 194 | self._predicates = None 195 | 196 | 197 | 198 | 199 | class ProgramContext(ParserRuleContext): 200 | 201 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 202 | super().__init__(parent, invokingState) 203 | self.parser = parser 204 | 205 | def EOF(self): 206 | return self.getToken(TaleParser.EOF, 0) 207 | 208 | def NEWLINE(self, i:int=None): 209 | if i is None: 210 | return self.getTokens(TaleParser.NEWLINE) 211 | else: 212 | return self.getToken(TaleParser.NEWLINE, i) 213 | 214 | def statement(self, i:int=None): 215 | if i is None: 216 | return self.getTypedRuleContexts(TaleParser.StatementContext) 217 | else: 218 | return self.getTypedRuleContext(TaleParser.StatementContext,i) 219 | 220 | 221 | def getRuleIndex(self): 222 | return TaleParser.RULE_program 223 | 224 | def enterRule(self, listener:ParseTreeListener): 225 | if hasattr( listener, "enterProgram" ): 226 | listener.enterProgram(self) 227 | 228 | def exitRule(self, listener:ParseTreeListener): 229 | if hasattr( listener, "exitProgram" ): 230 | listener.exitProgram(self) 231 | 232 | 233 | 234 | 235 | def program(self): 236 | 237 | localctx = TaleParser.ProgramContext(self, self._ctx, self.state) 238 | self.enterRule(localctx, 0, self.RULE_program) 239 | self._la = 0 # Token type 240 | try: 241 | self.enterOuterAlt(localctx, 1) 242 | self.state = 68 243 | self._errHandler.sync(self) 244 | _la = self._input.LA(1) 245 | while (((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << TaleParser.T__3) | (1 << TaleParser.IDENTIFIER) | (1 << TaleParser.NUMBER) | (1 << TaleParser.OPERATOR) | (1 << TaleParser.STRING) | (1 << TaleParser.NEWLINE))) != 0): 246 | self.state = 66 247 | self._errHandler.sync(self) 248 | token = self._input.LA(1) 249 | if token in [TaleParser.NEWLINE]: 250 | self.state = 64 251 | self.match(TaleParser.NEWLINE) 252 | pass 253 | elif token in [TaleParser.T__3, TaleParser.IDENTIFIER, TaleParser.NUMBER, TaleParser.OPERATOR, TaleParser.STRING]: 254 | self.state = 65 255 | self.statement() 256 | pass 257 | else: 258 | raise NoViableAltException(self) 259 | 260 | self.state = 70 261 | self._errHandler.sync(self) 262 | _la = self._input.LA(1) 263 | 264 | self.state = 71 265 | self.match(TaleParser.EOF) 266 | except RecognitionException as re: 267 | localctx.exception = re 268 | self._errHandler.reportError(self, re) 269 | self._errHandler.recover(self, re) 270 | finally: 271 | self.exitRule() 272 | return localctx 273 | 274 | 275 | class StatementContext(ParserRuleContext): 276 | 277 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 278 | super().__init__(parent, invokingState) 279 | self.parser = parser 280 | 281 | def assignment(self): 282 | return self.getTypedRuleContext(TaleParser.AssignmentContext,0) 283 | 284 | 285 | def expression(self): 286 | return self.getTypedRuleContext(TaleParser.ExpressionContext,0) 287 | 288 | 289 | def getRuleIndex(self): 290 | return TaleParser.RULE_statement 291 | 292 | def enterRule(self, listener:ParseTreeListener): 293 | if hasattr( listener, "enterStatement" ): 294 | listener.enterStatement(self) 295 | 296 | def exitRule(self, listener:ParseTreeListener): 297 | if hasattr( listener, "exitStatement" ): 298 | listener.exitStatement(self) 299 | 300 | 301 | 302 | 303 | def statement(self): 304 | 305 | localctx = TaleParser.StatementContext(self, self._ctx, self.state) 306 | self.enterRule(localctx, 2, self.RULE_statement) 307 | try: 308 | self.state = 75 309 | self._errHandler.sync(self) 310 | la_ = self._interp.adaptivePredict(self._input,2,self._ctx) 311 | if la_ == 1: 312 | self.enterOuterAlt(localctx, 1) 313 | self.state = 73 314 | self.assignment() 315 | pass 316 | 317 | elif la_ == 2: 318 | self.enterOuterAlt(localctx, 2) 319 | self.state = 74 320 | self.expression() 321 | pass 322 | 323 | 324 | except RecognitionException as re: 325 | localctx.exception = re 326 | self._errHandler.reportError(self, re) 327 | self._errHandler.recover(self, re) 328 | finally: 329 | self.exitRule() 330 | return localctx 331 | 332 | 333 | class AssignmentContext(ParserRuleContext): 334 | 335 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 336 | super().__init__(parent, invokingState) 337 | self.parser = parser 338 | 339 | def form(self): 340 | return self.getTypedRuleContext(TaleParser.FormContext,0) 341 | 342 | 343 | def assignmentBody(self): 344 | return self.getTypedRuleContext(TaleParser.AssignmentBodyContext,0) 345 | 346 | 347 | def getRuleIndex(self): 348 | return TaleParser.RULE_assignment 349 | 350 | def enterRule(self, listener:ParseTreeListener): 351 | if hasattr( listener, "enterAssignment" ): 352 | listener.enterAssignment(self) 353 | 354 | def exitRule(self, listener:ParseTreeListener): 355 | if hasattr( listener, "exitAssignment" ): 356 | listener.exitAssignment(self) 357 | 358 | 359 | 360 | 361 | def assignment(self): 362 | 363 | localctx = TaleParser.AssignmentContext(self, self._ctx, self.state) 364 | self.enterRule(localctx, 4, self.RULE_assignment) 365 | try: 366 | self.enterOuterAlt(localctx, 1) 367 | self.state = 77 368 | self.form() 369 | self.state = 78 370 | self.match(TaleParser.T__0) 371 | self.state = 79 372 | self.assignmentBody() 373 | except RecognitionException as re: 374 | localctx.exception = re 375 | self._errHandler.reportError(self, re) 376 | self._errHandler.recover(self, re) 377 | finally: 378 | self.exitRule() 379 | return localctx 380 | 381 | 382 | class FormContext(ParserRuleContext): 383 | 384 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 385 | super().__init__(parent, invokingState) 386 | self.parser = parser 387 | 388 | def unaryForm(self): 389 | return self.getTypedRuleContext(TaleParser.UnaryFormContext,0) 390 | 391 | 392 | def prefixOperatorForm(self): 393 | return self.getTypedRuleContext(TaleParser.PrefixOperatorFormContext,0) 394 | 395 | 396 | def binaryForm(self): 397 | return self.getTypedRuleContext(TaleParser.BinaryFormContext,0) 398 | 399 | 400 | def keywordForm(self): 401 | return self.getTypedRuleContext(TaleParser.KeywordFormContext,0) 402 | 403 | 404 | def primitiveForm(self): 405 | return self.getTypedRuleContext(TaleParser.PrimitiveFormContext,0) 406 | 407 | 408 | def getRuleIndex(self): 409 | return TaleParser.RULE_form 410 | 411 | def enterRule(self, listener:ParseTreeListener): 412 | if hasattr( listener, "enterForm" ): 413 | listener.enterForm(self) 414 | 415 | def exitRule(self, listener:ParseTreeListener): 416 | if hasattr( listener, "exitForm" ): 417 | listener.exitForm(self) 418 | 419 | 420 | 421 | 422 | def form(self): 423 | 424 | localctx = TaleParser.FormContext(self, self._ctx, self.state) 425 | self.enterRule(localctx, 6, self.RULE_form) 426 | try: 427 | self.state = 86 428 | self._errHandler.sync(self) 429 | la_ = self._interp.adaptivePredict(self._input,3,self._ctx) 430 | if la_ == 1: 431 | self.enterOuterAlt(localctx, 1) 432 | self.state = 81 433 | self.unaryForm() 434 | pass 435 | 436 | elif la_ == 2: 437 | self.enterOuterAlt(localctx, 2) 438 | self.state = 82 439 | self.prefixOperatorForm() 440 | pass 441 | 442 | elif la_ == 3: 443 | self.enterOuterAlt(localctx, 3) 444 | self.state = 83 445 | self.binaryForm() 446 | pass 447 | 448 | elif la_ == 4: 449 | self.enterOuterAlt(localctx, 4) 450 | self.state = 84 451 | self.keywordForm() 452 | pass 453 | 454 | elif la_ == 5: 455 | self.enterOuterAlt(localctx, 5) 456 | self.state = 85 457 | self.primitiveForm() 458 | pass 459 | 460 | 461 | except RecognitionException as re: 462 | localctx.exception = re 463 | self._errHandler.reportError(self, re) 464 | self._errHandler.recover(self, re) 465 | finally: 466 | self.exitRule() 467 | return localctx 468 | 469 | 470 | class UnaryFormContext(ParserRuleContext): 471 | 472 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 473 | super().__init__(parent, invokingState) 474 | self.parser = parser 475 | 476 | def parameter(self): 477 | return self.getTypedRuleContext(TaleParser.ParameterContext,0) 478 | 479 | 480 | def IDENTIFIER(self): 481 | return self.getToken(TaleParser.IDENTIFIER, 0) 482 | 483 | def getRuleIndex(self): 484 | return TaleParser.RULE_unaryForm 485 | 486 | def enterRule(self, listener:ParseTreeListener): 487 | if hasattr( listener, "enterUnaryForm" ): 488 | listener.enterUnaryForm(self) 489 | 490 | def exitRule(self, listener:ParseTreeListener): 491 | if hasattr( listener, "exitUnaryForm" ): 492 | listener.exitUnaryForm(self) 493 | 494 | 495 | 496 | 497 | def unaryForm(self): 498 | 499 | localctx = TaleParser.UnaryFormContext(self, self._ctx, self.state) 500 | self.enterRule(localctx, 8, self.RULE_unaryForm) 501 | try: 502 | self.enterOuterAlt(localctx, 1) 503 | self.state = 88 504 | self.parameter() 505 | self.state = 89 506 | self.match(TaleParser.IDENTIFIER) 507 | except RecognitionException as re: 508 | localctx.exception = re 509 | self._errHandler.reportError(self, re) 510 | self._errHandler.recover(self, re) 511 | finally: 512 | self.exitRule() 513 | return localctx 514 | 515 | 516 | class PrefixOperatorFormContext(ParserRuleContext): 517 | 518 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 519 | super().__init__(parent, invokingState) 520 | self.parser = parser 521 | 522 | def OPERATOR(self): 523 | return self.getToken(TaleParser.OPERATOR, 0) 524 | 525 | def singleParameter(self): 526 | return self.getTypedRuleContext(TaleParser.SingleParameterContext,0) 527 | 528 | 529 | def getRuleIndex(self): 530 | return TaleParser.RULE_prefixOperatorForm 531 | 532 | def enterRule(self, listener:ParseTreeListener): 533 | if hasattr( listener, "enterPrefixOperatorForm" ): 534 | listener.enterPrefixOperatorForm(self) 535 | 536 | def exitRule(self, listener:ParseTreeListener): 537 | if hasattr( listener, "exitPrefixOperatorForm" ): 538 | listener.exitPrefixOperatorForm(self) 539 | 540 | 541 | 542 | 543 | def prefixOperatorForm(self): 544 | 545 | localctx = TaleParser.PrefixOperatorFormContext(self, self._ctx, self.state) 546 | self.enterRule(localctx, 10, self.RULE_prefixOperatorForm) 547 | try: 548 | self.enterOuterAlt(localctx, 1) 549 | self.state = 91 550 | self.match(TaleParser.OPERATOR) 551 | self.state = 92 552 | self.singleParameter() 553 | except RecognitionException as re: 554 | localctx.exception = re 555 | self._errHandler.reportError(self, re) 556 | self._errHandler.recover(self, re) 557 | finally: 558 | self.exitRule() 559 | return localctx 560 | 561 | 562 | class BinaryFormContext(ParserRuleContext): 563 | 564 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 565 | super().__init__(parent, invokingState) 566 | self.parser = parser 567 | 568 | def parameter(self, i:int=None): 569 | if i is None: 570 | return self.getTypedRuleContexts(TaleParser.ParameterContext) 571 | else: 572 | return self.getTypedRuleContext(TaleParser.ParameterContext,i) 573 | 574 | 575 | def OPERATOR(self): 576 | return self.getToken(TaleParser.OPERATOR, 0) 577 | 578 | def getRuleIndex(self): 579 | return TaleParser.RULE_binaryForm 580 | 581 | def enterRule(self, listener:ParseTreeListener): 582 | if hasattr( listener, "enterBinaryForm" ): 583 | listener.enterBinaryForm(self) 584 | 585 | def exitRule(self, listener:ParseTreeListener): 586 | if hasattr( listener, "exitBinaryForm" ): 587 | listener.exitBinaryForm(self) 588 | 589 | 590 | 591 | 592 | def binaryForm(self): 593 | 594 | localctx = TaleParser.BinaryFormContext(self, self._ctx, self.state) 595 | self.enterRule(localctx, 12, self.RULE_binaryForm) 596 | try: 597 | self.enterOuterAlt(localctx, 1) 598 | self.state = 94 599 | self.parameter() 600 | self.state = 95 601 | self.match(TaleParser.OPERATOR) 602 | self.state = 96 603 | self.parameter() 604 | except RecognitionException as re: 605 | localctx.exception = re 606 | self._errHandler.reportError(self, re) 607 | self._errHandler.recover(self, re) 608 | finally: 609 | self.exitRule() 610 | return localctx 611 | 612 | 613 | class KeywordFormContext(ParserRuleContext): 614 | 615 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 616 | super().__init__(parent, invokingState) 617 | self.parser = parser 618 | 619 | def parameter(self, i:int=None): 620 | if i is None: 621 | return self.getTypedRuleContexts(TaleParser.ParameterContext) 622 | else: 623 | return self.getTypedRuleContext(TaleParser.ParameterContext,i) 624 | 625 | 626 | def IDENTIFIER(self, i:int=None): 627 | if i is None: 628 | return self.getTokens(TaleParser.IDENTIFIER) 629 | else: 630 | return self.getToken(TaleParser.IDENTIFIER, i) 631 | 632 | def getRuleIndex(self): 633 | return TaleParser.RULE_keywordForm 634 | 635 | def enterRule(self, listener:ParseTreeListener): 636 | if hasattr( listener, "enterKeywordForm" ): 637 | listener.enterKeywordForm(self) 638 | 639 | def exitRule(self, listener:ParseTreeListener): 640 | if hasattr( listener, "exitKeywordForm" ): 641 | listener.exitKeywordForm(self) 642 | 643 | 644 | 645 | 646 | def keywordForm(self): 647 | 648 | localctx = TaleParser.KeywordFormContext(self, self._ctx, self.state) 649 | self.enterRule(localctx, 14, self.RULE_keywordForm) 650 | self._la = 0 # Token type 651 | try: 652 | self.enterOuterAlt(localctx, 1) 653 | self.state = 99 654 | self._errHandler.sync(self) 655 | la_ = self._interp.adaptivePredict(self._input,4,self._ctx) 656 | if la_ == 1: 657 | self.state = 98 658 | self.parameter() 659 | 660 | 661 | self.state = 104 662 | self._errHandler.sync(self) 663 | _la = self._input.LA(1) 664 | while True: 665 | self.state = 101 666 | self.match(TaleParser.IDENTIFIER) 667 | self.state = 102 668 | self.match(TaleParser.T__1) 669 | self.state = 103 670 | self.parameter() 671 | self.state = 106 672 | self._errHandler.sync(self) 673 | _la = self._input.LA(1) 674 | if not (_la==TaleParser.IDENTIFIER): 675 | break 676 | 677 | except RecognitionException as re: 678 | localctx.exception = re 679 | self._errHandler.reportError(self, re) 680 | self._errHandler.recover(self, re) 681 | finally: 682 | self.exitRule() 683 | return localctx 684 | 685 | 686 | class PrimitiveFormContext(ParserRuleContext): 687 | 688 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 689 | super().__init__(parent, invokingState) 690 | self.parser = parser 691 | 692 | def IDENTIFIER(self): 693 | return self.getToken(TaleParser.IDENTIFIER, 0) 694 | 695 | def getRuleIndex(self): 696 | return TaleParser.RULE_primitiveForm 697 | 698 | def enterRule(self, listener:ParseTreeListener): 699 | if hasattr( listener, "enterPrimitiveForm" ): 700 | listener.enterPrimitiveForm(self) 701 | 702 | def exitRule(self, listener:ParseTreeListener): 703 | if hasattr( listener, "exitPrimitiveForm" ): 704 | listener.exitPrimitiveForm(self) 705 | 706 | 707 | 708 | 709 | def primitiveForm(self): 710 | 711 | localctx = TaleParser.PrimitiveFormContext(self, self._ctx, self.state) 712 | self.enterRule(localctx, 16, self.RULE_primitiveForm) 713 | try: 714 | self.enterOuterAlt(localctx, 1) 715 | self.state = 108 716 | self.match(TaleParser.IDENTIFIER) 717 | except RecognitionException as re: 718 | localctx.exception = re 719 | self._errHandler.reportError(self, re) 720 | self._errHandler.recover(self, re) 721 | finally: 722 | self.exitRule() 723 | return localctx 724 | 725 | 726 | class ParameterContext(ParserRuleContext): 727 | 728 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 729 | super().__init__(parent, invokingState) 730 | self.parser = parser 731 | 732 | def singleParameter(self): 733 | return self.getTypedRuleContext(TaleParser.SingleParameterContext,0) 734 | 735 | 736 | def tupleParameter(self): 737 | return self.getTypedRuleContext(TaleParser.TupleParameterContext,0) 738 | 739 | 740 | def getRuleIndex(self): 741 | return TaleParser.RULE_parameter 742 | 743 | def enterRule(self, listener:ParseTreeListener): 744 | if hasattr( listener, "enterParameter" ): 745 | listener.enterParameter(self) 746 | 747 | def exitRule(self, listener:ParseTreeListener): 748 | if hasattr( listener, "exitParameter" ): 749 | listener.exitParameter(self) 750 | 751 | 752 | 753 | 754 | def parameter(self): 755 | 756 | localctx = TaleParser.ParameterContext(self, self._ctx, self.state) 757 | self.enterRule(localctx, 18, self.RULE_parameter) 758 | try: 759 | self.state = 112 760 | self._errHandler.sync(self) 761 | la_ = self._interp.adaptivePredict(self._input,6,self._ctx) 762 | if la_ == 1: 763 | self.enterOuterAlt(localctx, 1) 764 | self.state = 110 765 | self.singleParameter() 766 | pass 767 | 768 | elif la_ == 2: 769 | self.enterOuterAlt(localctx, 2) 770 | self.state = 111 771 | self.tupleParameter() 772 | pass 773 | 774 | 775 | except RecognitionException as re: 776 | localctx.exception = re 777 | self._errHandler.reportError(self, re) 778 | self._errHandler.recover(self, re) 779 | finally: 780 | self.exitRule() 781 | return localctx 782 | 783 | 784 | class TupleParameterContext(ParserRuleContext): 785 | 786 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 787 | super().__init__(parent, invokingState) 788 | self.parser = parser 789 | 790 | def singleParameter(self, i:int=None): 791 | if i is None: 792 | return self.getTypedRuleContexts(TaleParser.SingleParameterContext) 793 | else: 794 | return self.getTypedRuleContext(TaleParser.SingleParameterContext,i) 795 | 796 | 797 | def getRuleIndex(self): 798 | return TaleParser.RULE_tupleParameter 799 | 800 | def enterRule(self, listener:ParseTreeListener): 801 | if hasattr( listener, "enterTupleParameter" ): 802 | listener.enterTupleParameter(self) 803 | 804 | def exitRule(self, listener:ParseTreeListener): 805 | if hasattr( listener, "exitTupleParameter" ): 806 | listener.exitTupleParameter(self) 807 | 808 | 809 | 810 | 811 | def tupleParameter(self): 812 | 813 | localctx = TaleParser.TupleParameterContext(self, self._ctx, self.state) 814 | self.enterRule(localctx, 20, self.RULE_tupleParameter) 815 | self._la = 0 # Token type 816 | try: 817 | self.enterOuterAlt(localctx, 1) 818 | self.state = 114 819 | self.singleParameter() 820 | self.state = 117 821 | self._errHandler.sync(self) 822 | _la = self._input.LA(1) 823 | while True: 824 | self.state = 115 825 | self.match(TaleParser.T__2) 826 | self.state = 116 827 | self.singleParameter() 828 | self.state = 119 829 | self._errHandler.sync(self) 830 | _la = self._input.LA(1) 831 | if not (_la==TaleParser.T__2): 832 | break 833 | 834 | except RecognitionException as re: 835 | localctx.exception = re 836 | self._errHandler.reportError(self, re) 837 | self._errHandler.recover(self, re) 838 | finally: 839 | self.exitRule() 840 | return localctx 841 | 842 | 843 | class SingleParameterContext(ParserRuleContext): 844 | 845 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 846 | super().__init__(parent, invokingState) 847 | self.parser = parser 848 | 849 | def simpleParameter(self): 850 | return self.getTypedRuleContext(TaleParser.SimpleParameterContext,0) 851 | 852 | 853 | def patternMatchingParameter(self): 854 | return self.getTypedRuleContext(TaleParser.PatternMatchingParameterContext,0) 855 | 856 | 857 | def getRuleIndex(self): 858 | return TaleParser.RULE_singleParameter 859 | 860 | def enterRule(self, listener:ParseTreeListener): 861 | if hasattr( listener, "enterSingleParameter" ): 862 | listener.enterSingleParameter(self) 863 | 864 | def exitRule(self, listener:ParseTreeListener): 865 | if hasattr( listener, "exitSingleParameter" ): 866 | listener.exitSingleParameter(self) 867 | 868 | 869 | 870 | 871 | def singleParameter(self): 872 | 873 | localctx = TaleParser.SingleParameterContext(self, self._ctx, self.state) 874 | self.enterRule(localctx, 22, self.RULE_singleParameter) 875 | try: 876 | self.state = 123 877 | self._errHandler.sync(self) 878 | token = self._input.LA(1) 879 | if token in [TaleParser.T__3]: 880 | self.enterOuterAlt(localctx, 1) 881 | self.state = 121 882 | self.simpleParameter() 883 | pass 884 | elif token in [TaleParser.IDENTIFIER, TaleParser.NUMBER, TaleParser.STRING]: 885 | self.enterOuterAlt(localctx, 2) 886 | self.state = 122 887 | self.patternMatchingParameter() 888 | pass 889 | else: 890 | raise NoViableAltException(self) 891 | 892 | except RecognitionException as re: 893 | localctx.exception = re 894 | self._errHandler.reportError(self, re) 895 | self._errHandler.recover(self, re) 896 | finally: 897 | self.exitRule() 898 | return localctx 899 | 900 | 901 | class SimpleParameterContext(ParserRuleContext): 902 | 903 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 904 | super().__init__(parent, invokingState) 905 | self.parser = parser 906 | 907 | def parameterName(self): 908 | return self.getTypedRuleContext(TaleParser.ParameterNameContext,0) 909 | 910 | 911 | def parameterType(self): 912 | return self.getTypedRuleContext(TaleParser.ParameterTypeContext,0) 913 | 914 | 915 | def getRuleIndex(self): 916 | return TaleParser.RULE_simpleParameter 917 | 918 | def enterRule(self, listener:ParseTreeListener): 919 | if hasattr( listener, "enterSimpleParameter" ): 920 | listener.enterSimpleParameter(self) 921 | 922 | def exitRule(self, listener:ParseTreeListener): 923 | if hasattr( listener, "exitSimpleParameter" ): 924 | listener.exitSimpleParameter(self) 925 | 926 | 927 | 928 | 929 | def simpleParameter(self): 930 | 931 | localctx = TaleParser.SimpleParameterContext(self, self._ctx, self.state) 932 | self.enterRule(localctx, 24, self.RULE_simpleParameter) 933 | self._la = 0 # Token type 934 | try: 935 | self.enterOuterAlt(localctx, 1) 936 | self.state = 125 937 | self.match(TaleParser.T__3) 938 | self.state = 126 939 | self.parameterName() 940 | self.state = 129 941 | self._errHandler.sync(self) 942 | _la = self._input.LA(1) 943 | if _la==TaleParser.T__1: 944 | self.state = 127 945 | self.match(TaleParser.T__1) 946 | self.state = 128 947 | self.parameterType() 948 | 949 | 950 | self.state = 131 951 | self.match(TaleParser.T__4) 952 | except RecognitionException as re: 953 | localctx.exception = re 954 | self._errHandler.reportError(self, re) 955 | self._errHandler.recover(self, re) 956 | finally: 957 | self.exitRule() 958 | return localctx 959 | 960 | 961 | class PatternMatchingParameterContext(ParserRuleContext): 962 | 963 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 964 | super().__init__(parent, invokingState) 965 | self.parser = parser 966 | 967 | def IDENTIFIER(self): 968 | return self.getToken(TaleParser.IDENTIFIER, 0) 969 | 970 | def literal(self): 971 | return self.getTypedRuleContext(TaleParser.LiteralContext,0) 972 | 973 | 974 | def getRuleIndex(self): 975 | return TaleParser.RULE_patternMatchingParameter 976 | 977 | def enterRule(self, listener:ParseTreeListener): 978 | if hasattr( listener, "enterPatternMatchingParameter" ): 979 | listener.enterPatternMatchingParameter(self) 980 | 981 | def exitRule(self, listener:ParseTreeListener): 982 | if hasattr( listener, "exitPatternMatchingParameter" ): 983 | listener.exitPatternMatchingParameter(self) 984 | 985 | 986 | 987 | 988 | def patternMatchingParameter(self): 989 | 990 | localctx = TaleParser.PatternMatchingParameterContext(self, self._ctx, self.state) 991 | self.enterRule(localctx, 26, self.RULE_patternMatchingParameter) 992 | try: 993 | self.state = 135 994 | self._errHandler.sync(self) 995 | token = self._input.LA(1) 996 | if token in [TaleParser.IDENTIFIER]: 997 | self.enterOuterAlt(localctx, 1) 998 | self.state = 133 999 | self.match(TaleParser.IDENTIFIER) 1000 | pass 1001 | elif token in [TaleParser.NUMBER, TaleParser.STRING]: 1002 | self.enterOuterAlt(localctx, 2) 1003 | self.state = 134 1004 | self.literal() 1005 | pass 1006 | else: 1007 | raise NoViableAltException(self) 1008 | 1009 | except RecognitionException as re: 1010 | localctx.exception = re 1011 | self._errHandler.reportError(self, re) 1012 | self._errHandler.recover(self, re) 1013 | finally: 1014 | self.exitRule() 1015 | return localctx 1016 | 1017 | 1018 | class ParameterNameContext(ParserRuleContext): 1019 | 1020 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1021 | super().__init__(parent, invokingState) 1022 | self.parser = parser 1023 | 1024 | def IDENTIFIER(self): 1025 | return self.getToken(TaleParser.IDENTIFIER, 0) 1026 | 1027 | def getRuleIndex(self): 1028 | return TaleParser.RULE_parameterName 1029 | 1030 | def enterRule(self, listener:ParseTreeListener): 1031 | if hasattr( listener, "enterParameterName" ): 1032 | listener.enterParameterName(self) 1033 | 1034 | def exitRule(self, listener:ParseTreeListener): 1035 | if hasattr( listener, "exitParameterName" ): 1036 | listener.exitParameterName(self) 1037 | 1038 | 1039 | 1040 | 1041 | def parameterName(self): 1042 | 1043 | localctx = TaleParser.ParameterNameContext(self, self._ctx, self.state) 1044 | self.enterRule(localctx, 28, self.RULE_parameterName) 1045 | try: 1046 | self.enterOuterAlt(localctx, 1) 1047 | self.state = 137 1048 | self.match(TaleParser.IDENTIFIER) 1049 | except RecognitionException as re: 1050 | localctx.exception = re 1051 | self._errHandler.reportError(self, re) 1052 | self._errHandler.recover(self, re) 1053 | finally: 1054 | self.exitRule() 1055 | return localctx 1056 | 1057 | 1058 | class ParameterTypeContext(ParserRuleContext): 1059 | 1060 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1061 | super().__init__(parent, invokingState) 1062 | self.parser = parser 1063 | 1064 | def IDENTIFIER(self): 1065 | return self.getToken(TaleParser.IDENTIFIER, 0) 1066 | 1067 | def getRuleIndex(self): 1068 | return TaleParser.RULE_parameterType 1069 | 1070 | def enterRule(self, listener:ParseTreeListener): 1071 | if hasattr( listener, "enterParameterType" ): 1072 | listener.enterParameterType(self) 1073 | 1074 | def exitRule(self, listener:ParseTreeListener): 1075 | if hasattr( listener, "exitParameterType" ): 1076 | listener.exitParameterType(self) 1077 | 1078 | 1079 | 1080 | 1081 | def parameterType(self): 1082 | 1083 | localctx = TaleParser.ParameterTypeContext(self, self._ctx, self.state) 1084 | self.enterRule(localctx, 30, self.RULE_parameterType) 1085 | try: 1086 | self.enterOuterAlt(localctx, 1) 1087 | self.state = 139 1088 | self.match(TaleParser.IDENTIFIER) 1089 | except RecognitionException as re: 1090 | localctx.exception = re 1091 | self._errHandler.reportError(self, re) 1092 | self._errHandler.recover(self, re) 1093 | finally: 1094 | self.exitRule() 1095 | return localctx 1096 | 1097 | 1098 | class AssignmentBodyContext(ParserRuleContext): 1099 | 1100 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1101 | super().__init__(parent, invokingState) 1102 | self.parser = parser 1103 | 1104 | def simpleAssignmentBody(self): 1105 | return self.getTypedRuleContext(TaleParser.SimpleAssignmentBodyContext,0) 1106 | 1107 | 1108 | def compoundAssignmentBody(self): 1109 | return self.getTypedRuleContext(TaleParser.CompoundAssignmentBodyContext,0) 1110 | 1111 | 1112 | def getRuleIndex(self): 1113 | return TaleParser.RULE_assignmentBody 1114 | 1115 | def enterRule(self, listener:ParseTreeListener): 1116 | if hasattr( listener, "enterAssignmentBody" ): 1117 | listener.enterAssignmentBody(self) 1118 | 1119 | def exitRule(self, listener:ParseTreeListener): 1120 | if hasattr( listener, "exitAssignmentBody" ): 1121 | listener.exitAssignmentBody(self) 1122 | 1123 | 1124 | 1125 | 1126 | def assignmentBody(self): 1127 | 1128 | localctx = TaleParser.AssignmentBodyContext(self, self._ctx, self.state) 1129 | self.enterRule(localctx, 32, self.RULE_assignmentBody) 1130 | try: 1131 | self.state = 143 1132 | self._errHandler.sync(self) 1133 | token = self._input.LA(1) 1134 | if token in [TaleParser.IDENTIFIER, TaleParser.NUMBER, TaleParser.OPERATOR, TaleParser.STRING]: 1135 | self.enterOuterAlt(localctx, 1) 1136 | self.state = 141 1137 | self.simpleAssignmentBody() 1138 | pass 1139 | elif token in [TaleParser.INDENT]: 1140 | self.enterOuterAlt(localctx, 2) 1141 | self.state = 142 1142 | self.compoundAssignmentBody() 1143 | pass 1144 | else: 1145 | raise NoViableAltException(self) 1146 | 1147 | except RecognitionException as re: 1148 | localctx.exception = re 1149 | self._errHandler.reportError(self, re) 1150 | self._errHandler.recover(self, re) 1151 | finally: 1152 | self.exitRule() 1153 | return localctx 1154 | 1155 | 1156 | class SimpleAssignmentBodyContext(ParserRuleContext): 1157 | 1158 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1159 | super().__init__(parent, invokingState) 1160 | self.parser = parser 1161 | 1162 | def expression(self): 1163 | return self.getTypedRuleContext(TaleParser.ExpressionContext,0) 1164 | 1165 | 1166 | def getRuleIndex(self): 1167 | return TaleParser.RULE_simpleAssignmentBody 1168 | 1169 | def enterRule(self, listener:ParseTreeListener): 1170 | if hasattr( listener, "enterSimpleAssignmentBody" ): 1171 | listener.enterSimpleAssignmentBody(self) 1172 | 1173 | def exitRule(self, listener:ParseTreeListener): 1174 | if hasattr( listener, "exitSimpleAssignmentBody" ): 1175 | listener.exitSimpleAssignmentBody(self) 1176 | 1177 | 1178 | 1179 | 1180 | def simpleAssignmentBody(self): 1181 | 1182 | localctx = TaleParser.SimpleAssignmentBodyContext(self, self._ctx, self.state) 1183 | self.enterRule(localctx, 34, self.RULE_simpleAssignmentBody) 1184 | try: 1185 | self.enterOuterAlt(localctx, 1) 1186 | self.state = 145 1187 | self.expression() 1188 | except RecognitionException as re: 1189 | localctx.exception = re 1190 | self._errHandler.reportError(self, re) 1191 | self._errHandler.recover(self, re) 1192 | finally: 1193 | self.exitRule() 1194 | return localctx 1195 | 1196 | 1197 | class CompoundAssignmentBodyContext(ParserRuleContext): 1198 | 1199 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1200 | super().__init__(parent, invokingState) 1201 | self.parser = parser 1202 | 1203 | def INDENT(self): 1204 | return self.getToken(TaleParser.INDENT, 0) 1205 | 1206 | def DEDENT(self): 1207 | return self.getToken(TaleParser.DEDENT, 0) 1208 | 1209 | def NEWLINE(self, i:int=None): 1210 | if i is None: 1211 | return self.getTokens(TaleParser.NEWLINE) 1212 | else: 1213 | return self.getToken(TaleParser.NEWLINE, i) 1214 | 1215 | def statement(self, i:int=None): 1216 | if i is None: 1217 | return self.getTypedRuleContexts(TaleParser.StatementContext) 1218 | else: 1219 | return self.getTypedRuleContext(TaleParser.StatementContext,i) 1220 | 1221 | 1222 | def getRuleIndex(self): 1223 | return TaleParser.RULE_compoundAssignmentBody 1224 | 1225 | def enterRule(self, listener:ParseTreeListener): 1226 | if hasattr( listener, "enterCompoundAssignmentBody" ): 1227 | listener.enterCompoundAssignmentBody(self) 1228 | 1229 | def exitRule(self, listener:ParseTreeListener): 1230 | if hasattr( listener, "exitCompoundAssignmentBody" ): 1231 | listener.exitCompoundAssignmentBody(self) 1232 | 1233 | 1234 | 1235 | 1236 | def compoundAssignmentBody(self): 1237 | 1238 | localctx = TaleParser.CompoundAssignmentBodyContext(self, self._ctx, self.state) 1239 | self.enterRule(localctx, 36, self.RULE_compoundAssignmentBody) 1240 | self._la = 0 # Token type 1241 | try: 1242 | self.enterOuterAlt(localctx, 1) 1243 | self.state = 147 1244 | self.match(TaleParser.INDENT) 1245 | self.state = 150 1246 | self._errHandler.sync(self) 1247 | _la = self._input.LA(1) 1248 | while True: 1249 | self.state = 150 1250 | self._errHandler.sync(self) 1251 | token = self._input.LA(1) 1252 | if token in [TaleParser.NEWLINE]: 1253 | self.state = 148 1254 | self.match(TaleParser.NEWLINE) 1255 | pass 1256 | elif token in [TaleParser.T__3, TaleParser.IDENTIFIER, TaleParser.NUMBER, TaleParser.OPERATOR, TaleParser.STRING]: 1257 | self.state = 149 1258 | self.statement() 1259 | pass 1260 | else: 1261 | raise NoViableAltException(self) 1262 | 1263 | self.state = 152 1264 | self._errHandler.sync(self) 1265 | _la = self._input.LA(1) 1266 | if not ((((_la) & ~0x3f) == 0 and ((1 << _la) & ((1 << TaleParser.T__3) | (1 << TaleParser.IDENTIFIER) | (1 << TaleParser.NUMBER) | (1 << TaleParser.OPERATOR) | (1 << TaleParser.STRING) | (1 << TaleParser.NEWLINE))) != 0)): 1267 | break 1268 | 1269 | self.state = 154 1270 | self.match(TaleParser.DEDENT) 1271 | except RecognitionException as re: 1272 | localctx.exception = re 1273 | self._errHandler.reportError(self, re) 1274 | self._errHandler.recover(self, re) 1275 | finally: 1276 | self.exitRule() 1277 | return localctx 1278 | 1279 | 1280 | class ExpressionContext(ParserRuleContext): 1281 | 1282 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1283 | super().__init__(parent, invokingState) 1284 | self.parser = parser 1285 | 1286 | def unary(self): 1287 | return self.getTypedRuleContext(TaleParser.UnaryContext,0) 1288 | 1289 | 1290 | def prefixOperator(self): 1291 | return self.getTypedRuleContext(TaleParser.PrefixOperatorContext,0) 1292 | 1293 | 1294 | def binary(self): 1295 | return self.getTypedRuleContext(TaleParser.BinaryContext,0) 1296 | 1297 | 1298 | def keyword(self): 1299 | return self.getTypedRuleContext(TaleParser.KeywordContext,0) 1300 | 1301 | 1302 | def primitive(self): 1303 | return self.getTypedRuleContext(TaleParser.PrimitiveContext,0) 1304 | 1305 | 1306 | def getRuleIndex(self): 1307 | return TaleParser.RULE_expression 1308 | 1309 | def enterRule(self, listener:ParseTreeListener): 1310 | if hasattr( listener, "enterExpression" ): 1311 | listener.enterExpression(self) 1312 | 1313 | def exitRule(self, listener:ParseTreeListener): 1314 | if hasattr( listener, "exitExpression" ): 1315 | listener.exitExpression(self) 1316 | 1317 | 1318 | 1319 | 1320 | def expression(self): 1321 | 1322 | localctx = TaleParser.ExpressionContext(self, self._ctx, self.state) 1323 | self.enterRule(localctx, 38, self.RULE_expression) 1324 | try: 1325 | self.state = 161 1326 | self._errHandler.sync(self) 1327 | la_ = self._interp.adaptivePredict(self._input,14,self._ctx) 1328 | if la_ == 1: 1329 | self.enterOuterAlt(localctx, 1) 1330 | self.state = 156 1331 | self.unary(0) 1332 | pass 1333 | 1334 | elif la_ == 2: 1335 | self.enterOuterAlt(localctx, 2) 1336 | self.state = 157 1337 | self.prefixOperator() 1338 | pass 1339 | 1340 | elif la_ == 3: 1341 | self.enterOuterAlt(localctx, 3) 1342 | self.state = 158 1343 | self.binary(0) 1344 | pass 1345 | 1346 | elif la_ == 4: 1347 | self.enterOuterAlt(localctx, 4) 1348 | self.state = 159 1349 | self.keyword() 1350 | pass 1351 | 1352 | elif la_ == 5: 1353 | self.enterOuterAlt(localctx, 5) 1354 | self.state = 160 1355 | self.primitive() 1356 | pass 1357 | 1358 | 1359 | except RecognitionException as re: 1360 | localctx.exception = re 1361 | self._errHandler.reportError(self, re) 1362 | self._errHandler.recover(self, re) 1363 | finally: 1364 | self.exitRule() 1365 | return localctx 1366 | 1367 | 1368 | class UnaryContext(ParserRuleContext): 1369 | 1370 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1371 | super().__init__(parent, invokingState) 1372 | self.parser = parser 1373 | 1374 | def primitive(self): 1375 | return self.getTypedRuleContext(TaleParser.PrimitiveContext,0) 1376 | 1377 | 1378 | def IDENTIFIER(self): 1379 | return self.getToken(TaleParser.IDENTIFIER, 0) 1380 | 1381 | def unary(self): 1382 | return self.getTypedRuleContext(TaleParser.UnaryContext,0) 1383 | 1384 | 1385 | def getRuleIndex(self): 1386 | return TaleParser.RULE_unary 1387 | 1388 | def enterRule(self, listener:ParseTreeListener): 1389 | if hasattr( listener, "enterUnary" ): 1390 | listener.enterUnary(self) 1391 | 1392 | def exitRule(self, listener:ParseTreeListener): 1393 | if hasattr( listener, "exitUnary" ): 1394 | listener.exitUnary(self) 1395 | 1396 | 1397 | 1398 | def unary(self, _p:int=0): 1399 | _parentctx = self._ctx 1400 | _parentState = self.state 1401 | localctx = TaleParser.UnaryContext(self, self._ctx, _parentState) 1402 | _prevctx = localctx 1403 | _startState = 40 1404 | self.enterRecursionRule(localctx, 40, self.RULE_unary, _p) 1405 | try: 1406 | self.enterOuterAlt(localctx, 1) 1407 | self.state = 164 1408 | self.primitive() 1409 | self.state = 165 1410 | self.match(TaleParser.IDENTIFIER) 1411 | self._ctx.stop = self._input.LT(-1) 1412 | self.state = 171 1413 | self._errHandler.sync(self) 1414 | _alt = self._interp.adaptivePredict(self._input,15,self._ctx) 1415 | while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: 1416 | if _alt==1: 1417 | if self._parseListeners is not None: 1418 | self.triggerExitRuleEvent() 1419 | _prevctx = localctx 1420 | localctx = TaleParser.UnaryContext(self, _parentctx, _parentState) 1421 | self.pushNewRecursionContext(localctx, _startState, self.RULE_unary) 1422 | self.state = 167 1423 | if not self.precpred(self._ctx, 2): 1424 | from antlr4.error.Errors import FailedPredicateException 1425 | raise FailedPredicateException(self, "self.precpred(self._ctx, 2)") 1426 | self.state = 168 1427 | self.match(TaleParser.IDENTIFIER) 1428 | self.state = 173 1429 | self._errHandler.sync(self) 1430 | _alt = self._interp.adaptivePredict(self._input,15,self._ctx) 1431 | 1432 | except RecognitionException as re: 1433 | localctx.exception = re 1434 | self._errHandler.reportError(self, re) 1435 | self._errHandler.recover(self, re) 1436 | finally: 1437 | self.unrollRecursionContexts(_parentctx) 1438 | return localctx 1439 | 1440 | 1441 | class PrefixOperatorContext(ParserRuleContext): 1442 | 1443 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1444 | super().__init__(parent, invokingState) 1445 | self.parser = parser 1446 | 1447 | def OPERATOR(self): 1448 | return self.getToken(TaleParser.OPERATOR, 0) 1449 | 1450 | def primitiveItem(self): 1451 | return self.getTypedRuleContext(TaleParser.PrimitiveItemContext,0) 1452 | 1453 | 1454 | def expression(self): 1455 | return self.getTypedRuleContext(TaleParser.ExpressionContext,0) 1456 | 1457 | 1458 | def getRuleIndex(self): 1459 | return TaleParser.RULE_prefixOperator 1460 | 1461 | def enterRule(self, listener:ParseTreeListener): 1462 | if hasattr( listener, "enterPrefixOperator" ): 1463 | listener.enterPrefixOperator(self) 1464 | 1465 | def exitRule(self, listener:ParseTreeListener): 1466 | if hasattr( listener, "exitPrefixOperator" ): 1467 | listener.exitPrefixOperator(self) 1468 | 1469 | 1470 | 1471 | 1472 | def prefixOperator(self): 1473 | 1474 | localctx = TaleParser.PrefixOperatorContext(self, self._ctx, self.state) 1475 | self.enterRule(localctx, 42, self.RULE_prefixOperator) 1476 | try: 1477 | self.state = 181 1478 | self._errHandler.sync(self) 1479 | la_ = self._interp.adaptivePredict(self._input,16,self._ctx) 1480 | if la_ == 1: 1481 | self.enterOuterAlt(localctx, 1) 1482 | self.state = 174 1483 | self.match(TaleParser.OPERATOR) 1484 | self.state = 175 1485 | self.primitiveItem() 1486 | pass 1487 | 1488 | elif la_ == 2: 1489 | self.enterOuterAlt(localctx, 2) 1490 | self.state = 176 1491 | self.match(TaleParser.OPERATOR) 1492 | self.state = 177 1493 | self.match(TaleParser.T__3) 1494 | self.state = 178 1495 | self.expression() 1496 | self.state = 179 1497 | self.match(TaleParser.T__4) 1498 | pass 1499 | 1500 | 1501 | except RecognitionException as re: 1502 | localctx.exception = re 1503 | self._errHandler.reportError(self, re) 1504 | self._errHandler.recover(self, re) 1505 | finally: 1506 | self.exitRule() 1507 | return localctx 1508 | 1509 | 1510 | class BinaryContext(ParserRuleContext): 1511 | 1512 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1513 | super().__init__(parent, invokingState) 1514 | self.parser = parser 1515 | 1516 | def binaryOperand(self, i:int=None): 1517 | if i is None: 1518 | return self.getTypedRuleContexts(TaleParser.BinaryOperandContext) 1519 | else: 1520 | return self.getTypedRuleContext(TaleParser.BinaryOperandContext,i) 1521 | 1522 | 1523 | def OPERATOR(self): 1524 | return self.getToken(TaleParser.OPERATOR, 0) 1525 | 1526 | def binary(self): 1527 | return self.getTypedRuleContext(TaleParser.BinaryContext,0) 1528 | 1529 | 1530 | def getRuleIndex(self): 1531 | return TaleParser.RULE_binary 1532 | 1533 | def enterRule(self, listener:ParseTreeListener): 1534 | if hasattr( listener, "enterBinary" ): 1535 | listener.enterBinary(self) 1536 | 1537 | def exitRule(self, listener:ParseTreeListener): 1538 | if hasattr( listener, "exitBinary" ): 1539 | listener.exitBinary(self) 1540 | 1541 | 1542 | 1543 | def binary(self, _p:int=0): 1544 | _parentctx = self._ctx 1545 | _parentState = self.state 1546 | localctx = TaleParser.BinaryContext(self, self._ctx, _parentState) 1547 | _prevctx = localctx 1548 | _startState = 44 1549 | self.enterRecursionRule(localctx, 44, self.RULE_binary, _p) 1550 | try: 1551 | self.enterOuterAlt(localctx, 1) 1552 | self.state = 184 1553 | self.binaryOperand() 1554 | self.state = 185 1555 | self.match(TaleParser.OPERATOR) 1556 | self.state = 186 1557 | self.binaryOperand() 1558 | self._ctx.stop = self._input.LT(-1) 1559 | self.state = 193 1560 | self._errHandler.sync(self) 1561 | _alt = self._interp.adaptivePredict(self._input,17,self._ctx) 1562 | while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: 1563 | if _alt==1: 1564 | if self._parseListeners is not None: 1565 | self.triggerExitRuleEvent() 1566 | _prevctx = localctx 1567 | localctx = TaleParser.BinaryContext(self, _parentctx, _parentState) 1568 | self.pushNewRecursionContext(localctx, _startState, self.RULE_binary) 1569 | self.state = 188 1570 | if not self.precpred(self._ctx, 2): 1571 | from antlr4.error.Errors import FailedPredicateException 1572 | raise FailedPredicateException(self, "self.precpred(self._ctx, 2)") 1573 | self.state = 189 1574 | self.match(TaleParser.OPERATOR) 1575 | self.state = 190 1576 | self.binaryOperand() 1577 | self.state = 195 1578 | self._errHandler.sync(self) 1579 | _alt = self._interp.adaptivePredict(self._input,17,self._ctx) 1580 | 1581 | except RecognitionException as re: 1582 | localctx.exception = re 1583 | self._errHandler.reportError(self, re) 1584 | self._errHandler.recover(self, re) 1585 | finally: 1586 | self.unrollRecursionContexts(_parentctx) 1587 | return localctx 1588 | 1589 | 1590 | class BinaryOperandContext(ParserRuleContext): 1591 | 1592 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1593 | super().__init__(parent, invokingState) 1594 | self.parser = parser 1595 | 1596 | def unary(self): 1597 | return self.getTypedRuleContext(TaleParser.UnaryContext,0) 1598 | 1599 | 1600 | def primitive(self): 1601 | return self.getTypedRuleContext(TaleParser.PrimitiveContext,0) 1602 | 1603 | 1604 | def getRuleIndex(self): 1605 | return TaleParser.RULE_binaryOperand 1606 | 1607 | def enterRule(self, listener:ParseTreeListener): 1608 | if hasattr( listener, "enterBinaryOperand" ): 1609 | listener.enterBinaryOperand(self) 1610 | 1611 | def exitRule(self, listener:ParseTreeListener): 1612 | if hasattr( listener, "exitBinaryOperand" ): 1613 | listener.exitBinaryOperand(self) 1614 | 1615 | 1616 | 1617 | 1618 | def binaryOperand(self): 1619 | 1620 | localctx = TaleParser.BinaryOperandContext(self, self._ctx, self.state) 1621 | self.enterRule(localctx, 46, self.RULE_binaryOperand) 1622 | try: 1623 | self.state = 198 1624 | self._errHandler.sync(self) 1625 | la_ = self._interp.adaptivePredict(self._input,18,self._ctx) 1626 | if la_ == 1: 1627 | self.enterOuterAlt(localctx, 1) 1628 | self.state = 196 1629 | self.unary(0) 1630 | pass 1631 | 1632 | elif la_ == 2: 1633 | self.enterOuterAlt(localctx, 2) 1634 | self.state = 197 1635 | self.primitive() 1636 | pass 1637 | 1638 | 1639 | except RecognitionException as re: 1640 | localctx.exception = re 1641 | self._errHandler.reportError(self, re) 1642 | self._errHandler.recover(self, re) 1643 | finally: 1644 | self.exitRule() 1645 | return localctx 1646 | 1647 | 1648 | class KeywordContext(ParserRuleContext): 1649 | 1650 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1651 | super().__init__(parent, invokingState) 1652 | self.parser = parser 1653 | 1654 | def keywordArgument(self, i:int=None): 1655 | if i is None: 1656 | return self.getTypedRuleContexts(TaleParser.KeywordArgumentContext) 1657 | else: 1658 | return self.getTypedRuleContext(TaleParser.KeywordArgumentContext,i) 1659 | 1660 | 1661 | def keywordName(self, i:int=None): 1662 | if i is None: 1663 | return self.getTypedRuleContexts(TaleParser.KeywordNameContext) 1664 | else: 1665 | return self.getTypedRuleContext(TaleParser.KeywordNameContext,i) 1666 | 1667 | 1668 | def getRuleIndex(self): 1669 | return TaleParser.RULE_keyword 1670 | 1671 | def enterRule(self, listener:ParseTreeListener): 1672 | if hasattr( listener, "enterKeyword" ): 1673 | listener.enterKeyword(self) 1674 | 1675 | def exitRule(self, listener:ParseTreeListener): 1676 | if hasattr( listener, "exitKeyword" ): 1677 | listener.exitKeyword(self) 1678 | 1679 | 1680 | 1681 | 1682 | def keyword(self): 1683 | 1684 | localctx = TaleParser.KeywordContext(self, self._ctx, self.state) 1685 | self.enterRule(localctx, 48, self.RULE_keyword) 1686 | try: 1687 | self.enterOuterAlt(localctx, 1) 1688 | self.state = 201 1689 | self._errHandler.sync(self) 1690 | la_ = self._interp.adaptivePredict(self._input,19,self._ctx) 1691 | if la_ == 1: 1692 | self.state = 200 1693 | self.keywordArgument() 1694 | 1695 | 1696 | self.state = 207 1697 | self._errHandler.sync(self) 1698 | _alt = 1 1699 | while _alt!=2 and _alt!=ATN.INVALID_ALT_NUMBER: 1700 | if _alt == 1: 1701 | self.state = 203 1702 | self.keywordName() 1703 | self.state = 204 1704 | self.match(TaleParser.T__1) 1705 | self.state = 205 1706 | self.keywordArgument() 1707 | 1708 | else: 1709 | raise NoViableAltException(self) 1710 | self.state = 209 1711 | self._errHandler.sync(self) 1712 | _alt = self._interp.adaptivePredict(self._input,20,self._ctx) 1713 | 1714 | except RecognitionException as re: 1715 | localctx.exception = re 1716 | self._errHandler.reportError(self, re) 1717 | self._errHandler.recover(self, re) 1718 | finally: 1719 | self.exitRule() 1720 | return localctx 1721 | 1722 | 1723 | class KeywordArgumentContext(ParserRuleContext): 1724 | 1725 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1726 | super().__init__(parent, invokingState) 1727 | self.parser = parser 1728 | 1729 | def unary(self): 1730 | return self.getTypedRuleContext(TaleParser.UnaryContext,0) 1731 | 1732 | 1733 | def binary(self): 1734 | return self.getTypedRuleContext(TaleParser.BinaryContext,0) 1735 | 1736 | 1737 | def primitive(self): 1738 | return self.getTypedRuleContext(TaleParser.PrimitiveContext,0) 1739 | 1740 | 1741 | def getRuleIndex(self): 1742 | return TaleParser.RULE_keywordArgument 1743 | 1744 | def enterRule(self, listener:ParseTreeListener): 1745 | if hasattr( listener, "enterKeywordArgument" ): 1746 | listener.enterKeywordArgument(self) 1747 | 1748 | def exitRule(self, listener:ParseTreeListener): 1749 | if hasattr( listener, "exitKeywordArgument" ): 1750 | listener.exitKeywordArgument(self) 1751 | 1752 | 1753 | 1754 | 1755 | def keywordArgument(self): 1756 | 1757 | localctx = TaleParser.KeywordArgumentContext(self, self._ctx, self.state) 1758 | self.enterRule(localctx, 50, self.RULE_keywordArgument) 1759 | try: 1760 | self.state = 214 1761 | self._errHandler.sync(self) 1762 | la_ = self._interp.adaptivePredict(self._input,21,self._ctx) 1763 | if la_ == 1: 1764 | self.enterOuterAlt(localctx, 1) 1765 | self.state = 211 1766 | self.unary(0) 1767 | pass 1768 | 1769 | elif la_ == 2: 1770 | self.enterOuterAlt(localctx, 2) 1771 | self.state = 212 1772 | self.binary(0) 1773 | pass 1774 | 1775 | elif la_ == 3: 1776 | self.enterOuterAlt(localctx, 3) 1777 | self.state = 213 1778 | self.primitive() 1779 | pass 1780 | 1781 | 1782 | except RecognitionException as re: 1783 | localctx.exception = re 1784 | self._errHandler.reportError(self, re) 1785 | self._errHandler.recover(self, re) 1786 | finally: 1787 | self.exitRule() 1788 | return localctx 1789 | 1790 | 1791 | class KeywordNameContext(ParserRuleContext): 1792 | 1793 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1794 | super().__init__(parent, invokingState) 1795 | self.parser = parser 1796 | 1797 | def IDENTIFIER(self): 1798 | return self.getToken(TaleParser.IDENTIFIER, 0) 1799 | 1800 | def getRuleIndex(self): 1801 | return TaleParser.RULE_keywordName 1802 | 1803 | def enterRule(self, listener:ParseTreeListener): 1804 | if hasattr( listener, "enterKeywordName" ): 1805 | listener.enterKeywordName(self) 1806 | 1807 | def exitRule(self, listener:ParseTreeListener): 1808 | if hasattr( listener, "exitKeywordName" ): 1809 | listener.exitKeywordName(self) 1810 | 1811 | 1812 | 1813 | 1814 | def keywordName(self): 1815 | 1816 | localctx = TaleParser.KeywordNameContext(self, self._ctx, self.state) 1817 | self.enterRule(localctx, 52, self.RULE_keywordName) 1818 | try: 1819 | self.enterOuterAlt(localctx, 1) 1820 | self.state = 216 1821 | self.match(TaleParser.IDENTIFIER) 1822 | except RecognitionException as re: 1823 | localctx.exception = re 1824 | self._errHandler.reportError(self, re) 1825 | self._errHandler.recover(self, re) 1826 | finally: 1827 | self.exitRule() 1828 | return localctx 1829 | 1830 | 1831 | class PrimitiveContext(ParserRuleContext): 1832 | 1833 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1834 | super().__init__(parent, invokingState) 1835 | self.parser = parser 1836 | 1837 | def primitiveItem(self, i:int=None): 1838 | if i is None: 1839 | return self.getTypedRuleContexts(TaleParser.PrimitiveItemContext) 1840 | else: 1841 | return self.getTypedRuleContext(TaleParser.PrimitiveItemContext,i) 1842 | 1843 | 1844 | def getRuleIndex(self): 1845 | return TaleParser.RULE_primitive 1846 | 1847 | def enterRule(self, listener:ParseTreeListener): 1848 | if hasattr( listener, "enterPrimitive" ): 1849 | listener.enterPrimitive(self) 1850 | 1851 | def exitRule(self, listener:ParseTreeListener): 1852 | if hasattr( listener, "exitPrimitive" ): 1853 | listener.exitPrimitive(self) 1854 | 1855 | 1856 | 1857 | 1858 | def primitive(self): 1859 | 1860 | localctx = TaleParser.PrimitiveContext(self, self._ctx, self.state) 1861 | self.enterRule(localctx, 54, self.RULE_primitive) 1862 | try: 1863 | self.enterOuterAlt(localctx, 1) 1864 | self.state = 218 1865 | self.primitiveItem() 1866 | self.state = 223 1867 | self._errHandler.sync(self) 1868 | _alt = self._interp.adaptivePredict(self._input,22,self._ctx) 1869 | while _alt!=1 and _alt!=ATN.INVALID_ALT_NUMBER: 1870 | if _alt==1+1: 1871 | self.state = 219 1872 | self.match(TaleParser.T__2) 1873 | self.state = 220 1874 | self.primitiveItem() 1875 | self.state = 225 1876 | self._errHandler.sync(self) 1877 | _alt = self._interp.adaptivePredict(self._input,22,self._ctx) 1878 | 1879 | except RecognitionException as re: 1880 | localctx.exception = re 1881 | self._errHandler.reportError(self, re) 1882 | self._errHandler.recover(self, re) 1883 | finally: 1884 | self.exitRule() 1885 | return localctx 1886 | 1887 | 1888 | class PrimitiveItemContext(ParserRuleContext): 1889 | 1890 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1891 | super().__init__(parent, invokingState) 1892 | self.parser = parser 1893 | 1894 | def IDENTIFIER(self): 1895 | return self.getToken(TaleParser.IDENTIFIER, 0) 1896 | 1897 | def literal(self): 1898 | return self.getTypedRuleContext(TaleParser.LiteralContext,0) 1899 | 1900 | 1901 | def getRuleIndex(self): 1902 | return TaleParser.RULE_primitiveItem 1903 | 1904 | def enterRule(self, listener:ParseTreeListener): 1905 | if hasattr( listener, "enterPrimitiveItem" ): 1906 | listener.enterPrimitiveItem(self) 1907 | 1908 | def exitRule(self, listener:ParseTreeListener): 1909 | if hasattr( listener, "exitPrimitiveItem" ): 1910 | listener.exitPrimitiveItem(self) 1911 | 1912 | 1913 | 1914 | 1915 | def primitiveItem(self): 1916 | 1917 | localctx = TaleParser.PrimitiveItemContext(self, self._ctx, self.state) 1918 | self.enterRule(localctx, 56, self.RULE_primitiveItem) 1919 | try: 1920 | self.state = 228 1921 | self._errHandler.sync(self) 1922 | token = self._input.LA(1) 1923 | if token in [TaleParser.IDENTIFIER]: 1924 | self.enterOuterAlt(localctx, 1) 1925 | self.state = 226 1926 | self.match(TaleParser.IDENTIFIER) 1927 | pass 1928 | elif token in [TaleParser.NUMBER, TaleParser.STRING]: 1929 | self.enterOuterAlt(localctx, 2) 1930 | self.state = 227 1931 | self.literal() 1932 | pass 1933 | else: 1934 | raise NoViableAltException(self) 1935 | 1936 | except RecognitionException as re: 1937 | localctx.exception = re 1938 | self._errHandler.reportError(self, re) 1939 | self._errHandler.recover(self, re) 1940 | finally: 1941 | self.exitRule() 1942 | return localctx 1943 | 1944 | 1945 | class LiteralContext(ParserRuleContext): 1946 | 1947 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 1948 | super().__init__(parent, invokingState) 1949 | self.parser = parser 1950 | 1951 | def intLiteral(self): 1952 | return self.getTypedRuleContext(TaleParser.IntLiteralContext,0) 1953 | 1954 | 1955 | def stringLiteral(self): 1956 | return self.getTypedRuleContext(TaleParser.StringLiteralContext,0) 1957 | 1958 | 1959 | def getRuleIndex(self): 1960 | return TaleParser.RULE_literal 1961 | 1962 | def enterRule(self, listener:ParseTreeListener): 1963 | if hasattr( listener, "enterLiteral" ): 1964 | listener.enterLiteral(self) 1965 | 1966 | def exitRule(self, listener:ParseTreeListener): 1967 | if hasattr( listener, "exitLiteral" ): 1968 | listener.exitLiteral(self) 1969 | 1970 | 1971 | 1972 | 1973 | def literal(self): 1974 | 1975 | localctx = TaleParser.LiteralContext(self, self._ctx, self.state) 1976 | self.enterRule(localctx, 58, self.RULE_literal) 1977 | try: 1978 | self.state = 232 1979 | self._errHandler.sync(self) 1980 | token = self._input.LA(1) 1981 | if token in [TaleParser.NUMBER]: 1982 | self.enterOuterAlt(localctx, 1) 1983 | self.state = 230 1984 | self.intLiteral() 1985 | pass 1986 | elif token in [TaleParser.STRING]: 1987 | self.enterOuterAlt(localctx, 2) 1988 | self.state = 231 1989 | self.stringLiteral() 1990 | pass 1991 | else: 1992 | raise NoViableAltException(self) 1993 | 1994 | except RecognitionException as re: 1995 | localctx.exception = re 1996 | self._errHandler.reportError(self, re) 1997 | self._errHandler.recover(self, re) 1998 | finally: 1999 | self.exitRule() 2000 | return localctx 2001 | 2002 | 2003 | class IntLiteralContext(ParserRuleContext): 2004 | 2005 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 2006 | super().__init__(parent, invokingState) 2007 | self.parser = parser 2008 | 2009 | def NUMBER(self): 2010 | return self.getToken(TaleParser.NUMBER, 0) 2011 | 2012 | def getRuleIndex(self): 2013 | return TaleParser.RULE_intLiteral 2014 | 2015 | def enterRule(self, listener:ParseTreeListener): 2016 | if hasattr( listener, "enterIntLiteral" ): 2017 | listener.enterIntLiteral(self) 2018 | 2019 | def exitRule(self, listener:ParseTreeListener): 2020 | if hasattr( listener, "exitIntLiteral" ): 2021 | listener.exitIntLiteral(self) 2022 | 2023 | 2024 | 2025 | 2026 | def intLiteral(self): 2027 | 2028 | localctx = TaleParser.IntLiteralContext(self, self._ctx, self.state) 2029 | self.enterRule(localctx, 60, self.RULE_intLiteral) 2030 | try: 2031 | self.enterOuterAlt(localctx, 1) 2032 | self.state = 234 2033 | self.match(TaleParser.NUMBER) 2034 | except RecognitionException as re: 2035 | localctx.exception = re 2036 | self._errHandler.reportError(self, re) 2037 | self._errHandler.recover(self, re) 2038 | finally: 2039 | self.exitRule() 2040 | return localctx 2041 | 2042 | 2043 | class StringLiteralContext(ParserRuleContext): 2044 | 2045 | def __init__(self, parser, parent:ParserRuleContext=None, invokingState:int=-1): 2046 | super().__init__(parent, invokingState) 2047 | self.parser = parser 2048 | 2049 | def STRING(self): 2050 | return self.getToken(TaleParser.STRING, 0) 2051 | 2052 | def getRuleIndex(self): 2053 | return TaleParser.RULE_stringLiteral 2054 | 2055 | def enterRule(self, listener:ParseTreeListener): 2056 | if hasattr( listener, "enterStringLiteral" ): 2057 | listener.enterStringLiteral(self) 2058 | 2059 | def exitRule(self, listener:ParseTreeListener): 2060 | if hasattr( listener, "exitStringLiteral" ): 2061 | listener.exitStringLiteral(self) 2062 | 2063 | 2064 | 2065 | 2066 | def stringLiteral(self): 2067 | 2068 | localctx = TaleParser.StringLiteralContext(self, self._ctx, self.state) 2069 | self.enterRule(localctx, 62, self.RULE_stringLiteral) 2070 | try: 2071 | self.enterOuterAlt(localctx, 1) 2072 | self.state = 236 2073 | self.match(TaleParser.STRING) 2074 | except RecognitionException as re: 2075 | localctx.exception = re 2076 | self._errHandler.reportError(self, re) 2077 | self._errHandler.recover(self, re) 2078 | finally: 2079 | self.exitRule() 2080 | return localctx 2081 | 2082 | 2083 | 2084 | def sempred(self, localctx:RuleContext, ruleIndex:int, predIndex:int): 2085 | if self._predicates == None: 2086 | self._predicates = dict() 2087 | self._predicates[20] = self.unary_sempred 2088 | self._predicates[22] = self.binary_sempred 2089 | pred = self._predicates.get(ruleIndex, None) 2090 | if pred is None: 2091 | raise Exception("No predicate with index:" + str(ruleIndex)) 2092 | else: 2093 | return pred(localctx, predIndex) 2094 | 2095 | def unary_sempred(self, localctx:UnaryContext, predIndex:int): 2096 | if predIndex == 0: 2097 | return self.precpred(self._ctx, 2) 2098 | 2099 | 2100 | def binary_sempred(self, localctx:BinaryContext, predIndex:int): 2101 | if predIndex == 1: 2102 | return self.precpred(self._ctx, 2) 2103 | 2104 | 2105 | 2106 | 2107 | 2108 | -------------------------------------------------------------------------------- /src/tale/syntax/nodes.py: -------------------------------------------------------------------------------- 1 | from typing import Any, Iterable, Optional, Sequence, Tuple 2 | 3 | from tree_format import format_tree 4 | 5 | from tale.common import group 6 | 7 | 8 | class Node: 9 | """A node of the abstract syntax tree. 10 | 11 | Attributes: 12 | kind: A string that represents the node kind. For example, `Statement`, 13 | `Assignment`, `Form`, etc. 14 | children: A sequence of child nodes. 15 | """ 16 | 17 | def __init__(self, content: str, children: Optional[Sequence['Node']] = None): 18 | self.content = content 19 | self.children = children or [] 20 | 21 | def __str__(self): 22 | def name(x) -> str: 23 | if isinstance(x, Token): 24 | return ' "' + x.content + '"' 25 | else: 26 | return '' 27 | 28 | return format_tree(self, 29 | format_node=lambda x: f'{type(x).__name__}{name(x)}', 30 | get_children=lambda x: x.children) 31 | 32 | 33 | class Program(Node): 34 | """A main program.""" 35 | 36 | 37 | class Statement(Node): 38 | """A statement. 39 | 40 | Statement is either an expression or an assignment. 41 | """ 42 | 43 | 44 | class Identifier(Node): 45 | """An identifier. 46 | 47 | For example, in the expression: 48 | x = 1 49 | `x` is an identifier. 50 | """ 51 | 52 | 53 | class Assignment(Statement): 54 | """An assignment. 55 | 56 | The following is an example of the assignment: 57 | y = x 58 | where: 59 | `y` is a form (the `form` property of the node); 60 | `x` is a value (the `value` property of the node). 61 | """ 62 | 63 | @property 64 | def form(self) -> 'Form': 65 | return self.children[0] 66 | 67 | @property 68 | def value(self) -> Node: 69 | return self.children[2] 70 | 71 | 72 | class Form(Node): 73 | """A form of an expression. 74 | 75 | Represents a template that may capture a number of expressions. 76 | 77 | For example, the form `(x) squared` captures `1 squared`, `2 squared`, 78 | `3 squared`, and so on. 79 | 80 | Attributes: 81 | node: A syntax node that represents the form. 82 | """ 83 | 84 | 85 | class UnaryForm(Form): 86 | """An unary form. 87 | 88 | An unary form consists of an argument and an identifier. 89 | 90 | For example, the following is an unary form: 91 | (x) squared 92 | where: 93 | `(x)` is a variable argument of a form; 94 | `squared` is a simple identifier. 95 | """ 96 | 97 | @property 98 | def parameter(self) -> 'Parameter': 99 | return self.children[0] 100 | 101 | @property 102 | def identifier(self) -> str: 103 | return self.children[1].content 104 | 105 | 106 | class PrefixOperatorForm(Form): 107 | """A prefix operator form. 108 | 109 | An prefix operator form consists of operator followed by a parameter. 110 | 111 | For example, the following is a prefix operator form: 112 | -(x) 113 | where: 114 | `-` is an operator; 115 | `(x)` is a parameter. 116 | 117 | Prefix operators have higher precedence than unary forms. 118 | For example, the following: 119 | -1 asString 120 | Is equal to: 121 | (-1) asString 122 | """ 123 | 124 | @property 125 | def operator(self) -> str: 126 | return self.children[0].content 127 | 128 | @property 129 | def parameter(self) -> 'Parameter': 130 | if isinstance(self.children[1], Parameter): 131 | return self.children[1] 132 | else: 133 | return self.children[1] 134 | 135 | 136 | class BinaryForm(Form): 137 | """A binary form. 138 | 139 | A binary form consists of two parameters that are separated by some special 140 | character. 141 | For example, the following is a binary form: 142 | (x) + (y) 143 | where: 144 | `(x)` is a first parameter; 145 | `+` is an operator; 146 | `(y)` is a second parameter. 147 | """ 148 | 149 | @property 150 | def first_parameter(self) -> 'Parameter': 151 | return self.children[0] 152 | 153 | @property 154 | def operator(self) -> Node: 155 | return self.children[1] 156 | 157 | @property 158 | def second_parameter(self) -> 'Parameter': 159 | return self.children[2] 160 | 161 | 162 | class KeywordForm(Form): 163 | """A keyword form. 164 | 165 | A keyword form consists of parameters and identifiers. 166 | Unlike unary form, parameters and identifiers could be placed anywhere. 167 | The only rule here is that an parameter couldn't be followed by an parameter, 168 | or an identifier couldn't be followed by an identifier. 169 | 170 | For example, the following is a keyword form: 171 | just: (x) 172 | where: 173 | `just` is an identifier; 174 | `(x)` is an parameter. 175 | 176 | Consider a more complex example: 177 | add: (x) to: (y) 178 | where: 179 | `add` and `to` are identifiers; 180 | `(x)` and `(y)` are parameters. 181 | """ 182 | 183 | @property 184 | def prefix(self) -> 'Parameter': 185 | if isinstance(self.children[0], Parameter): 186 | return self.children[0] 187 | 188 | @property 189 | def parts(self) -> Iterable[Tuple[Node, Node]]: 190 | def is_not_prefix_and_colon(x: Node): 191 | return x is not self.prefix and x.content != ':' 192 | 193 | children = filter(is_not_prefix_and_colon, self.children) 194 | children = group(children, by=2) 195 | 196 | return children 197 | 198 | 199 | class PrimitiveForm(Form): 200 | """A primitive form. 201 | 202 | Primitive form captures only plain values. 203 | """ 204 | 205 | 206 | class Parameter(Node): 207 | """A parameter. 208 | 209 | An parameter is either a single or a tuple one. 210 | 211 | For example, in the following form: 212 | (x) squared = x * x 213 | `(x)` is a single parameter. 214 | 215 | On the other hand, in the form: 216 | first: (x), (y) = x 217 | `(x), (y)` is a tuple parameter: it consists of two single ones. 218 | """ 219 | 220 | 221 | class TupleParameter(Parameter): 222 | """A comma separated sequence of sigle parameters.""" 223 | 224 | @property 225 | def items(self) -> Iterable['Parameter']: 226 | return (x for x in self.children if isinstance(x, Parameter)) 227 | 228 | 229 | class SingleParameter(Parameter): 230 | """A single parameter. 231 | 232 | A single parameter is either a simple or a pattern matching one. 233 | 234 | For example, in the following form: 235 | (x) squared = x * x 236 | `(x)` is a simple parameter. 237 | 238 | On the other hand, in the form: 239 | 2 squared = 4 240 | `2` is a pattern matching parameter. 241 | """ 242 | 243 | @property 244 | def type_(self) -> str: 245 | return self.children[3] if len(self.children) > 3 else None 246 | 247 | 248 | class SimpleParameter(SingleParameter): 249 | """A single parameter. 250 | 251 | A single parameter is either a simple or a pattern matching one. 252 | 253 | For example, in the following form: 254 | (x) squared = x * x 255 | `(x)` is a simple parameter. 256 | 257 | On the other hand, in the form: 258 | 2 squared = 4 259 | `2` is a pattern matching parameter. 260 | """ 261 | 262 | @property 263 | def type_(self) -> str: 264 | return self.children[3] if len(self.children) > 3 else None 265 | 266 | @property 267 | def name(self) -> str: 268 | return self.children[1].content 269 | 270 | 271 | class PatternMatchingParameter(SingleParameter): 272 | """A pattern matching parameter. 273 | 274 | Represents a plain value. 275 | 276 | For example, in the following form: 277 | 2 squared = 4 278 | `2` is a pattern matching parameter. 279 | """ 280 | 281 | 282 | class AssignmentBody(Node): 283 | """An assignment body. 284 | 285 | Can be either a simple expression: 286 | x = 1 287 | Or a sequence of statements: 288 | x = 289 | y = 1 290 | y 291 | """ 292 | 293 | 294 | class Expression(Statement): 295 | """An expression. 296 | 297 | Represents a value that could be captured by form. 298 | 299 | For example, the following is an expression: 300 | 1 squared 301 | It could be captured by the form: 302 | (x) squared 303 | """ 304 | 305 | 306 | class UnaryExpression(Expression): 307 | """An unary expression. 308 | 309 | An unary expression consist of two parts: an argument and the identifier. 310 | """ 311 | 312 | @property 313 | def argument(self) -> 'Node': 314 | return self.children[0] 315 | 316 | @property 317 | def identifier(self) -> str: 318 | return self.children[1].content 319 | 320 | 321 | class PrefixOperatorExpression(Expression): 322 | """A prefix operator expression. 323 | 324 | A prefix operator consist of two parts: an operator and the value. 325 | """ 326 | 327 | @property 328 | def operator(self) -> str: 329 | return self.children[0].content 330 | 331 | @property 332 | def argument(self) -> 'Node': 333 | if self.children[1].content == '(': 334 | return self.children[2] 335 | else: 336 | return self.children[1] 337 | 338 | 339 | class BinaryExpression(Expression): 340 | """A binary expression. 341 | 342 | Consists of two arguments and an operator. 343 | 344 | For example, the following is an example of binary expression: 345 | 1 + 1 346 | where: 347 | `1` is a first argument; 348 | `+` is an operator; 349 | `2` is a second argument. 350 | """ 351 | 352 | @property 353 | def first_argument(self) -> Expression: 354 | return self.children[0] 355 | 356 | @property 357 | def operator(self) -> Node: 358 | return self.children[1] 359 | 360 | @property 361 | def second_argument(self) -> Expression: 362 | return self.children[2] 363 | 364 | 365 | class KeywordExpression(Expression): 366 | """A keyword expression. 367 | 368 | Unlike unary expression, a keyword expression consists of pairs 369 | of arguments and identifiers. 370 | 371 | For example, the following is a keyword expression: 372 | add: 1 to: list 373 | """ 374 | 375 | @property 376 | def prefix(self) -> 'KeywordArgument': 377 | """Returns a prefix of the keyword expression. 378 | 379 | Usually, a keyword expression consists of sequence of pairs where each pair 380 | represents an identifier and a value. 381 | For example, the `add: 1 to: list` expression consists of two pairs: 382 | `(add, 1)` and `(to, 1)`. 383 | 384 | However, sometimes the first node of a keyword expression is an argument node. 385 | For example, the `1 added_to: list` expression consists of `1` and a pair 386 | `(added_to, list)`. Here the `1` expression is a prefix. 387 | """ 388 | 389 | if isinstance(self.children[0], KeywordArgument): 390 | return self.children[0] 391 | 392 | @property 393 | def parts(self) -> Iterable[Tuple['KeywordName', 'KeywordArgument']]: 394 | def is_not_prefix_and_colon(x: Node): 395 | return x is not self.prefix and x.content != ':' 396 | 397 | children = filter(is_not_prefix_and_colon, self.children) 398 | children = group(children, by=2) 399 | 400 | return children 401 | 402 | 403 | class KeywordArgument(Expression): 404 | """An argument of the keyword expression. 405 | 406 | For example, the `add: 1 to: list` expression consists of two arguments: 407 | `1` and `list`. 408 | """ 409 | 410 | 411 | class KeywordName(Node): 412 | """A name of the keyword expression part. 413 | 414 | For example, the `add: 1 to: list` expression consists of two names: 415 | `add` and `to`. 416 | """ 417 | 418 | 419 | class PrimitiveExpression(Expression): 420 | """A primitive expression. 421 | 422 | Primitive expression is just a plain value. 423 | """ 424 | 425 | @property 426 | def items(self) -> Iterable['PrimitiveExpressionItem']: 427 | return (x for x in self.children if isinstance(x, PrimitiveExpressionItem)) 428 | 429 | 430 | class PrimitiveExpressionItem(Node): 431 | """An item of the primitive expression. 432 | 433 | For example, the following expression: 434 | just: 1, 2 435 | Contains `1, 2` as primitive expression with two items: `1` and `2`. 436 | """ 437 | 438 | 439 | class IntLiteral(Node): 440 | """An integer literal. 441 | 442 | Represents a positive integer number. 443 | """ 444 | 445 | 446 | class StringLiteral(Node): 447 | """A string literal.""" 448 | 449 | 450 | class Token(Node): 451 | """A plain text. 452 | 453 | For example, in the expression: 454 | x = 1 455 | `=` is a token. 456 | """ 457 | -------------------------------------------------------------------------------- /src/tale/syntax/parsers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tale-lang/tale/1779f94aa13545e58a1d5a8819b85ad02ada4144/src/tale/syntax/parsers/__init__.py -------------------------------------------------------------------------------- /src/tale/syntax/parsers/antlr4.py: -------------------------------------------------------------------------------- 1 | import io 2 | import os 3 | from contextlib import redirect_stderr 4 | from typing import Any, Iterable 5 | 6 | import antlr4 7 | from tree_format import format_tree 8 | 9 | from tale.common import pipe 10 | from tale.syntax.grammar.TaleLexer import TaleLexer 11 | from tale.syntax.grammar.TaleParser import TaleParser 12 | from tale.syntax.nodes import (Assignment, AssignmentBody, BinaryExpression, 13 | BinaryForm, Expression, IntLiteral, 14 | KeywordArgument, KeywordExpression, KeywordForm, 15 | KeywordName, Node, PatternMatchingParameter, 16 | PrefixOperatorExpression, PrefixOperatorForm, 17 | PrimitiveExpression, PrimitiveExpressionItem, 18 | PrimitiveForm, Program, SimpleParameter, 19 | SingleParameter, Statement, StringLiteral, 20 | Token, TupleParameter, UnaryExpression, 21 | UnaryForm) 22 | from tale.syntax.parsers.parser import Parser 23 | 24 | 25 | class Antlr4DebugNode: 26 | """An ANTLR4 syntax node that is used for debugging purposes. 27 | 28 | It's mainly needed for checking the raw syntax tree created by ANTLR4. 29 | The raw syntax tree is a bit longer than the one created for Tale. 30 | """ 31 | 32 | def __init__(self, node): 33 | def content(x): 34 | result = x.getText() 35 | return result if result != os.linesep else '' 36 | 37 | def children(x): 38 | if isinstance(x, antlr4.tree.Tree.TerminalNode): 39 | return [] 40 | else: 41 | return list(map(Antlr4DebugNode, x.getChildren())) 42 | 43 | self.node = node 44 | self.content = content(node) 45 | self.children = children(node) 46 | 47 | def __str__(self): 48 | return format_tree(self, 49 | format_node=lambda x: f'{type(x.node).__name__} "{x.content}"', 50 | get_children=lambda x: x.children) 51 | 52 | 53 | class Antlr4Parser(Parser): 54 | """A parser that uses ANTLR4 under the hood. 55 | 56 | Uses `grammar.TaleLexer` and `grammar.TaleParser` to tokenize the input, 57 | and to produce an abstract syntax tree. 58 | """ 59 | 60 | def ast(self, code: str) -> Node: 61 | def content(x): 62 | result = x.getText() 63 | return result if result != os.linesep else '' 64 | 65 | def children(x): 66 | if isinstance(x, antlr4.tree.Tree.TerminalNode): 67 | return [] 68 | else: 69 | return list(map(node, x.getChildren())) 70 | 71 | def node(x): 72 | def new(node: Any, as_: type) -> Node: 73 | return as_(content(node), children(node)) 74 | 75 | if isinstance(x, TaleParser.ProgramContext): 76 | return new(x, as_=Program) 77 | 78 | if isinstance(x, TaleParser.StatementContext): 79 | return new(x, as_=Statement) 80 | 81 | if isinstance(x, TaleParser.AssignmentContext): 82 | return new(x, as_=Assignment) 83 | 84 | if isinstance(x, TaleParser.FormContext): 85 | x = next(x.getChildren()) 86 | 87 | if isinstance(x, TaleParser.UnaryFormContext): 88 | return new(x, as_=UnaryForm) 89 | 90 | if isinstance(x, TaleParser.PrefixOperatorFormContext): 91 | return new(x, as_=PrefixOperatorForm) 92 | 93 | if isinstance(x, TaleParser.KeywordFormContext): 94 | return new(x, as_=KeywordForm) 95 | 96 | if isinstance(x, TaleParser.BinaryFormContext): 97 | return new(x, as_=BinaryForm) 98 | 99 | if isinstance(x, TaleParser.PrimitiveFormContext): 100 | return new(x, as_=PrimitiveForm) 101 | 102 | if isinstance(x, TaleParser.ParameterContext): 103 | x = next(x.getChildren()) 104 | 105 | if isinstance(x, TaleParser.TupleParameterContext): 106 | return new(x, as_=TupleParameter) 107 | 108 | return node(x) 109 | 110 | if isinstance(x, TaleParser.SingleParameterContext): 111 | x = next(x.getChildren()) 112 | return node(x) 113 | 114 | if isinstance(x, TaleParser.SimpleParameterContext): 115 | return new(x, as_=SimpleParameter) 116 | 117 | if isinstance(x, TaleParser.PatternMatchingParameterContext): 118 | return new(x, as_=PatternMatchingParameter) 119 | 120 | if isinstance(x, TaleParser.ParameterContext): 121 | x = next(x.getChildren()) 122 | 123 | if isinstance(x, TaleParser.SimpleParameterContext): 124 | return new(x, as_=SimpleParameter) 125 | 126 | if isinstance(x, TaleParser.PatternMatchingParameterContext): 127 | return new(x, as_=PatternMatchingParameter) 128 | 129 | if isinstance(x, TaleParser.AssignmentBodyContext): 130 | x = next(x.getChildren()) 131 | return new(x, as_=AssignmentBody) 132 | 133 | if isinstance(x, TaleParser.SimpleAssignmentBodyContext): 134 | x = next(x.getChildren()) 135 | return node(x) 136 | 137 | if isinstance(x, TaleParser.ExpressionContext): 138 | x = next(x.getChildren()) 139 | 140 | if isinstance(x, TaleParser.UnaryContext): 141 | return new(x, as_=UnaryExpression) 142 | 143 | if isinstance(x, TaleParser.PrefixOperatorContext): 144 | return new(x, as_=PrefixOperatorExpression) 145 | 146 | if isinstance(x, TaleParser.BinaryContext): 147 | return new(x, as_=BinaryExpression) 148 | 149 | if isinstance(x, TaleParser.KeywordContext): 150 | return new(x, as_=KeywordExpression) 151 | 152 | if isinstance(x, TaleParser.PrimitiveContext): 153 | return new(x, as_=PrimitiveExpression) 154 | 155 | return new(x, as_=Expression) 156 | 157 | if isinstance(x, TaleParser.UnaryContext): 158 | return new(x, as_=UnaryExpression) 159 | 160 | if isinstance(x, TaleParser.PrefixOperatorContext): 161 | return new(x, as_=PrefixOperatorExpression) 162 | 163 | if isinstance(x, TaleParser.BinaryContext): 164 | return new(x, as_=BinaryExpression) 165 | 166 | if isinstance(x, TaleParser.KeywordNameContext): 167 | return new(x, as_=KeywordName) 168 | 169 | if isinstance(x, TaleParser.KeywordArgumentContext): 170 | return new(x, as_=KeywordArgument) 171 | 172 | if isinstance(x, TaleParser.PrimitiveContext): 173 | return new(x, as_=PrimitiveExpression) 174 | 175 | if isinstance(x, TaleParser.PrimitiveItemContext): 176 | return new(x, as_=PrimitiveExpressionItem) 177 | 178 | if isinstance(x, TaleParser.LiteralContext): 179 | x = next(x.getChildren()) 180 | 181 | if isinstance(x, TaleParser.IntLiteralContext): 182 | return new(x, as_=IntLiteral) 183 | 184 | if isinstance(x, TaleParser.StringLiteralContext): 185 | return new(x, as_=StringLiteral) 186 | 187 | if (x.getText() == 'indent'): 188 | return Token('') 189 | 190 | if (x.getText() == 'dedent'): 191 | return Token('') 192 | 193 | if (x.getText() == 'newLine'): 194 | return Token('') 195 | 196 | if isinstance(x, antlr4.TerminalNode): 197 | return new(x, as_=Token) 198 | 199 | return new(x, as_=Node) 200 | 201 | err = io.StringIO() 202 | 203 | with redirect_stderr(err): 204 | parser = pipe( 205 | antlr4.InputStream, 206 | TaleLexer, 207 | antlr4.CommonTokenStream, 208 | TaleParser) 209 | program = parser(code).program() 210 | 211 | print(Antlr4DebugNode(program)) 212 | 213 | err = err.getvalue() 214 | 215 | if len(err) > 0: 216 | raise Exception(err) 217 | 218 | return node(program) 219 | -------------------------------------------------------------------------------- /src/tale/syntax/parsers/parser.py: -------------------------------------------------------------------------------- 1 | from abc import ABCMeta, abstractmethod 2 | 3 | from tale.syntax.nodes import Node 4 | 5 | 6 | class Parser(metaclass=ABCMeta): 7 | """A parser for the Tale language.""" 8 | 9 | @abstractmethod 10 | def ast(self, code: str) -> Node: 11 | """Produces an abstract syntax tree from the string. 12 | 13 | Args: 14 | code: A string that represents a Tale program. 15 | 16 | Returns: 17 | An instance of `tale.syntax.nodes.node.Node` that represents 18 | a root of the abstract syntax tree. 19 | 20 | Raises: 21 | ValueError: If the specified `code` string is empty or represents 22 | an invalid Tale program. 23 | """ 24 | -------------------------------------------------------------------------------- /src/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tale-lang/tale/1779f94aa13545e58a1d5a8819b85ad02ada4144/src/tests/__init__.py -------------------------------------------------------------------------------- /src/tests/integration/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tale-lang/tale/1779f94aa13545e58a1d5a8819b85ad02ada4144/src/tests/integration/__init__.py -------------------------------------------------------------------------------- /src/tests/integration/forms/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tale-lang/tale/1779f94aa13545e58a1d5a8819b85ad02ada4144/src/tests/integration/forms/__init__.py -------------------------------------------------------------------------------- /src/tests/integration/forms/binary_forms_test.py: -------------------------------------------------------------------------------- 1 | from tale.core import execute 2 | 3 | 4 | def test_first_argument(): 5 | # Arrange. 6 | program = """ 7 | (x) + (y) = x 8 | 9 | a + b 10 | """ 11 | 12 | # Act. 13 | out = execute(program) 14 | 15 | # Assert. 16 | assert out == 'a' 17 | 18 | 19 | def test_second_argument(): 20 | # Arrange. 21 | program = """ 22 | (x) + (y) = y 23 | 24 | a + b 25 | """ 26 | 27 | # Act. 28 | out = execute(program) 29 | 30 | # Assert. 31 | assert out == 'b' 32 | 33 | 34 | def test_calling_keyword_form_in_body(): 35 | # Arrange. 36 | program = """ 37 | (x) and: (y) = x 38 | (x) + (y) = x and: y 39 | 40 | a + b 41 | """ 42 | 43 | # Act. 44 | out = execute(program) 45 | 46 | # Assert. 47 | assert out == 'a' 48 | 49 | 50 | def test_compound_binary_expression(): 51 | # Arrange. 52 | program = """ 53 | (x) + (y) = y 54 | 55 | a + b + c + d 56 | """ 57 | 58 | # Act. 59 | out = execute(program) 60 | 61 | # Assert. 62 | assert out == 'd' 63 | -------------------------------------------------------------------------------- /src/tests/integration/forms/keyword_forms_test.py: -------------------------------------------------------------------------------- 1 | from tale.core import execute 2 | 3 | 4 | def test_simple_keyword_form(): 5 | # Arrange. 6 | program = """ 7 | just: (x) = 1 8 | just: 2 9 | """ 10 | 11 | # Act. 12 | out = execute(program) 13 | 14 | # Assert. 15 | assert out == 1 16 | 17 | 18 | def test_simple_keyword_form_returns_arg(): 19 | # Arrange. 20 | program = """ 21 | just: (x) = x 22 | just: 1 23 | """ 24 | 25 | # Act. 26 | out = execute(program) 27 | 28 | # Assert. 29 | assert out == 1 30 | 31 | 32 | def test_keyword_form_with_two_parts_first_arg(): 33 | # Arrange. 34 | program = """ 35 | add: (x) to: (y) = x 36 | add: 1 to: 2 37 | """ 38 | 39 | # Act. 40 | out = execute(program) 41 | 42 | # Assert. 43 | assert out == 1 44 | 45 | 46 | def test_keyword_form_with_two_parts_second_arg(): 47 | # Arrange. 48 | program = """ 49 | add: (x) to: (y) = y 50 | add: 1 to: 2 51 | """ 52 | 53 | # Act. 54 | out = execute(program) 55 | 56 | # Assert. 57 | assert out == 2 58 | 59 | 60 | def test_keyword_form_with_prefix_first_arg(): 61 | # Arrange. 62 | program = """ 63 | (x) just: (y) = x 64 | 1 just: 2 65 | """ 66 | 67 | # Act. 68 | out = execute(program) 69 | 70 | # Assert. 71 | assert out == 1 72 | 73 | 74 | def test_keyword_form_combined_with_unary_form(): 75 | # Arrange. 76 | program = """ 77 | (x) squared = x 78 | just: (x) = x 79 | just: 1 squared 80 | """ 81 | 82 | # Act. 83 | out = execute(program) 84 | 85 | # Assert. 86 | assert out == 1 87 | 88 | 89 | def test_keyword_form_has_less_priority_than_binary(): 90 | # Arrange. 91 | program = """ 92 | just: (x) = x 93 | just: 1 + 2 94 | """ 95 | 96 | # Act. 97 | out = execute(program) 98 | 99 | # Assert. 100 | assert out == 3 101 | -------------------------------------------------------------------------------- /src/tests/integration/forms/prefix_operators_test.py: -------------------------------------------------------------------------------- 1 | from tale.core import execute 2 | 3 | 4 | def test_simple_prefix_operator(): 5 | # Arrange. 6 | program = """ 7 | -(x) = x 8 | 9 | -1 10 | """ 11 | 12 | # Act. 13 | out = execute(program) 14 | 15 | # Assert. 16 | assert out == 1 17 | 18 | 19 | def test_multiple_prefix_operators_in_expression(): 20 | # Arrange. 21 | program = """ 22 | -(x) = x + 1 23 | 24 | -(-1) 25 | """ 26 | 27 | # Act. 28 | out = execute(program) 29 | 30 | # Assert. 31 | assert out == 3 32 | -------------------------------------------------------------------------------- /src/tests/integration/forms/unary_forms_test.py: -------------------------------------------------------------------------------- 1 | from tale.core import execute 2 | 3 | 4 | def test_simple_assignment(): 5 | # Arrange. 6 | program = """ 7 | (x) just = x 8 | 1 just 9 | """ 10 | 11 | # Act. 12 | out = execute(program) 13 | 14 | # Assert. 15 | assert out == 1 16 | 17 | 18 | def test_not_matched_expression(): 19 | # Arrange. 20 | program = """ 21 | (x) just = x 22 | 1 jusx 23 | """ 24 | 25 | # Act. 26 | out = execute(program) 27 | 28 | # Assert. 29 | assert out == '1jusx' 30 | 31 | 32 | def test_unary_form_span_on_multiple_lines(): 33 | # Arrange. 34 | program = """ 35 | (x) just = 36 | y = x 37 | y 38 | 39 | 1 just 40 | """ 41 | 42 | # Act. 43 | out = execute(program) 44 | 45 | # Assert. 46 | assert out == 1 47 | 48 | 49 | def test_same_unary_form_called_many_times(): 50 | # Arrange. 51 | program = """ 52 | (x) just = x 53 | 1 just just 54 | """ 55 | 56 | # Act. 57 | out = execute(program) 58 | 59 | # Assert. 60 | assert out == 1 61 | 62 | 63 | def test_two_unary_forms_composed(): 64 | # Arrange. 65 | program = """ 66 | (x) a = x 67 | (x) b = x 68 | 69 | 1 a b a b 70 | """ 71 | 72 | # Act. 73 | out = execute(program) 74 | 75 | # Assert. 76 | assert out == 1 77 | -------------------------------------------------------------------------------- /src/tests/integration/forms/unary_operator_forms_test.py: -------------------------------------------------------------------------------- 1 | from tale.core import execute 2 | 3 | 4 | def test_simple_form(): 5 | # Arrange. 6 | program = """ 7 | -(x) = x 8 | -1 9 | """ 10 | 11 | # Act. 12 | out = execute(program) 13 | 14 | # Assert. 15 | assert out == 1 16 | -------------------------------------------------------------------------------- /src/tests/integration/interop_test.py: -------------------------------------------------------------------------------- 1 | from tale.core import execute 2 | 3 | 4 | def test_random(): 5 | # Arrange. 6 | program = """ 7 | x = py: "import random; result = random.randint", 1, 1 8 | x 9 | """ 10 | 11 | # Act. 12 | out = execute(program) 13 | 14 | # Assert. 15 | assert out == 1 16 | 17 | 18 | def test_invalid_first_arg(): 19 | # Arrange. 20 | program = """ 21 | x = py: 1 22 | x 23 | """ 24 | 25 | # Act. 26 | out = execute(program) 27 | 28 | # Assert. 29 | assert out == 'py:1' 30 | 31 | 32 | def test_overriden(): 33 | # Arrange. 34 | program = """ 35 | py: (x) = x 36 | py: 1 37 | """ 38 | 39 | # Act. 40 | out = execute(program) 41 | 42 | # Assert. 43 | assert out == 1 44 | -------------------------------------------------------------------------------- /src/tests/integration/syntax/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tale-lang/tale/1779f94aa13545e58a1d5a8819b85ad02ada4144/src/tests/integration/syntax/__init__.py -------------------------------------------------------------------------------- /src/tests/integration/syntax/assignments_test.py: -------------------------------------------------------------------------------- 1 | from tale.core import execute 2 | 3 | 4 | def test_simple_assignment(): 5 | # Arrange. 6 | program = """ 7 | x = 1 8 | x 9 | """ 10 | 11 | # Act. 12 | out = execute(program) 13 | 14 | # Assert. 15 | assert out == 1 16 | -------------------------------------------------------------------------------- /src/tests/integration/syntax/comments_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from tale.core import execute 4 | 5 | 6 | def test_one_comment(): 7 | # Arrange. 8 | program = """ 9 | -- A. 10 | 1 11 | """ 12 | 13 | # Act. 14 | out = execute(program) 15 | 16 | # Assert. 17 | assert out == 1 18 | 19 | 20 | def test_two_comments(): 21 | # Arrange. 22 | program = """ 23 | -- A. 24 | -- B. 25 | 1 26 | """ 27 | 28 | # Act. 29 | out = execute(program) 30 | 31 | # Assert. 32 | assert out == 1 33 | 34 | 35 | def test_comments_after_code(): 36 | # Arrange. 37 | program = """ 38 | -- A. 39 | 1 40 | -- B. 41 | """ 42 | 43 | # Act. 44 | out = execute(program) 45 | 46 | # Assert. 47 | assert out == 1 48 | 49 | 50 | def test_invalid_comment(): 51 | # Arrange. 52 | program = """ 53 | - A. 54 | 1 55 | """ 56 | 57 | # Act & Assert. 58 | with pytest.raises(Exception): 59 | out = execute(program) 60 | -------------------------------------------------------------------------------- /src/tests/integration/syntax/implicit_return_test.py: -------------------------------------------------------------------------------- 1 | from tale.core import execute 2 | 3 | 4 | def test_one_expression(): 5 | # Arrange. 6 | program = """ 7 | x 8 | """ 9 | 10 | # Act. 11 | out = execute(program) 12 | 13 | # Assert. 14 | assert out == 'x' 15 | 16 | 17 | def test_two_expressions(): 18 | # Arrange. 19 | program = """ 20 | x 21 | y 22 | """ 23 | 24 | # Act. 25 | out = execute(program) 26 | 27 | # Assert. 28 | assert out == 'y' 29 | -------------------------------------------------------------------------------- /src/tests/integration/syntax/indentation_test.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from tale.core import execute 4 | 5 | 6 | def test_one_indentation_level(): 7 | # Arrange. 8 | program = """ 9 | x = 10 | 1 11 | 2 12 | 3 13 | x 14 | """ 15 | 16 | # Act. 17 | out = execute(program) 18 | 19 | # Assert. 20 | assert out == 3 21 | 22 | 23 | def test_double_indentation_level(): 24 | # Arrange. 25 | program = """ 26 | x = 27 | y = 28 | 1 29 | 2 30 | 3 31 | y 32 | x 33 | """ 34 | 35 | # Act. 36 | out = execute(program) 37 | 38 | # Assert. 39 | assert out == 3 40 | 41 | 42 | def test_wrong_indentation(): 43 | # Arrange. 44 | program = """ 45 | x = 46 | 1 47 | 2 48 | x 49 | """ 50 | 51 | # Act & Assert. 52 | with pytest.raises(Exception): 53 | execute(program) 54 | 55 | 56 | def test_one_indentation_level_with_complex_return(): 57 | # Arrange. 58 | program = """ 59 | x = 60 | just: 1 61 | x 62 | """ 63 | 64 | # Act. 65 | out = execute(program) 66 | 67 | # Assert. 68 | assert out == 'just:1' 69 | -------------------------------------------------------------------------------- /src/tests/integration/syntax/pattern_matching_test.py: -------------------------------------------------------------------------------- 1 | from tale.core import execute 2 | 3 | 4 | def test_common_branch(): 5 | # Arrange. 6 | program = """ 7 | just: (x) = x 8 | just: b = c 9 | 10 | just: a 11 | """ 12 | 13 | # Act. 14 | out = execute(program) 15 | 16 | # Assert. 17 | assert out == 'a' 18 | 19 | 20 | def test_specific_branch_bottom(): 21 | # Arrange. 22 | program = """ 23 | just: (x) = x 24 | just: b = c 25 | 26 | just: b 27 | """ 28 | 29 | # Act. 30 | out = execute(program) 31 | 32 | # Assert. 33 | assert out == 'b' 34 | 35 | 36 | def test_specific_branch_top(): 37 | # Arrange. 38 | program = """ 39 | just: b = c 40 | just: (x) = x 41 | 42 | just: b 43 | """ 44 | 45 | # Act. 46 | out = execute(program) 47 | 48 | # Assert. 49 | assert out == 'c' 50 | 51 | 52 | def test_common_branch_with_three_branches(): 53 | # Arrange. 54 | program = """ 55 | just: a = b 56 | just: b = c 57 | just: (x) = x 58 | 59 | just: c 60 | """ 61 | 62 | # Act. 63 | out = execute(program) 64 | 65 | # Assert. 66 | assert out == 'c' 67 | 68 | 69 | def test_first_specific_branch_with_three_branches(): 70 | # Arrange. 71 | program = """ 72 | just: a = b 73 | just: b = c 74 | just: (x) = x 75 | 76 | just: a 77 | """ 78 | 79 | # Act. 80 | out = execute(program) 81 | 82 | # Assert. 83 | assert out == 'b' 84 | 85 | 86 | def test_second_specific_branch_with_three_branches(): 87 | # Arrange. 88 | program = """ 89 | just: a = b 90 | just: b = c 91 | just: (x) = x 92 | 93 | just: b 94 | """ 95 | 96 | # Act. 97 | out = execute(program) 98 | 99 | # Assert. 100 | assert out == 'c' 101 | 102 | 103 | def test_unary_form_common_branch(): 104 | # Arrange. 105 | program = """ 106 | a just = b 107 | b just = c 108 | (x) just = x 109 | 110 | c just 111 | """ 112 | 113 | # Act. 114 | out = execute(program) 115 | 116 | # Assert. 117 | assert out == 'c' 118 | 119 | 120 | def test_unary_form_specific_branch(): 121 | # Arrange. 122 | program = """ 123 | a just = b 124 | b just = c 125 | (x) just = x 126 | 127 | a just 128 | """ 129 | 130 | # Act. 131 | out = execute(program) 132 | 133 | # Assert. 134 | assert out == 'b' 135 | 136 | 137 | def test_binary_form_common_branch(): 138 | # Arrange. 139 | program = """ 140 | a + b = c 141 | (x) + (y) = x 142 | 143 | a + c 144 | """ 145 | 146 | # Act. 147 | out = execute(program) 148 | 149 | # Assert. 150 | assert out == 'a' 151 | 152 | 153 | def test_binary_form_specific_branch(): 154 | # Arrange. 155 | program = """ 156 | a + b = c 157 | (x) + (y) = x 158 | 159 | a + b 160 | """ 161 | 162 | # Act. 163 | out = execute(program) 164 | 165 | # Assert. 166 | assert out == 'c' 167 | 168 | 169 | def test_pattern_matching_without_common_branch(): 170 | # Arrange. 171 | program = """ 172 | a + b = c 173 | a + c = d 174 | 175 | a + c 176 | """ 177 | 178 | # Act. 179 | out = execute(program) 180 | 181 | # Assert. 182 | assert out == 'd' 183 | 184 | 185 | def test_pattern_matching_of_keyword_form_with_prefix(): 186 | # Arrange. 187 | program = """ 188 | 1 plus: 2 = 3 189 | 1 plus: 2 190 | """ 191 | 192 | # Act. 193 | out = execute(program) 194 | 195 | # Assert. 196 | assert out == 3 197 | 198 | 199 | def test_pattern_matching_with_tuple_argument_common_branch(): 200 | # Arrange. 201 | program = """ 202 | 1, 2 just = 3 203 | (x), (y) just = x 204 | 205 | 1, 1 just 206 | """ 207 | 208 | # Act. 209 | out = execute(program) 210 | 211 | # Assert. 212 | assert out == 1 213 | 214 | 215 | def test_pattern_matching_with_tuple_argument_specific_branch(): 216 | # Arrange. 217 | program = """ 218 | 1, 2 just = 3 219 | (x), (y) just = x 220 | 221 | 1, 2 just 222 | """ 223 | 224 | # Act. 225 | out = execute(program) 226 | 227 | # Assert. 228 | assert out == 3 229 | 230 | 231 | def test_pattern_matching_with_half_of_tuple_argument(): 232 | # Arrange. 233 | program = """ 234 | 1, 2 just = 3 235 | (x), 2 just = 4 236 | (x),(y) just = x 237 | 238 | 2, 2 just 239 | """ 240 | 241 | # Act. 242 | out = execute(program) 243 | 244 | # Assert. 245 | assert out == 4 246 | 247 | 248 | def test_pattern_matching_with_prefix_operator_specific_branch(): 249 | # Arrange. 250 | program = """ 251 | -1 = 2 252 | -(x) = x 253 | 254 | -1 255 | """ 256 | 257 | # Act. 258 | out = execute(program) 259 | 260 | # Assert. 261 | assert out == 2 262 | 263 | 264 | def test_pattern_matching_with_prefix_operator_common_branch(): 265 | # Arrange. 266 | program = """ 267 | -1 = 2 268 | -(x) = x 269 | 270 | -3 271 | """ 272 | 273 | # Act. 274 | out = execute(program) 275 | 276 | # Assert. 277 | assert out == 3 278 | -------------------------------------------------------------------------------- /src/tests/integration/syntax/tuple_arguments_test.py: -------------------------------------------------------------------------------- 1 | from tale.core import execute 2 | 3 | 4 | def test_unary(): 5 | # Arrange. 6 | program = """ 7 | (x), (y) first = x 8 | 9 | 1, 2 first 10 | """ 11 | 12 | # Act. 13 | out = execute(program) 14 | 15 | # Assert. 16 | assert out == 1 17 | 18 | 19 | def test_keyword(): 20 | # Arrange. 21 | program = """ 22 | second: (x), (y) = y 23 | 24 | second: 1, 2 25 | """ 26 | 27 | # Act. 28 | out = execute(program) 29 | 30 | # Assert. 31 | assert out == 2 32 | -------------------------------------------------------------------------------- /src/tests/integration/types/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tale-lang/tale/1779f94aa13545e58a1d5a8819b85ad02ada4144/src/tests/integration/types/__init__.py -------------------------------------------------------------------------------- /src/tests/integration/types/int_test.py: -------------------------------------------------------------------------------- 1 | from tale.core import execute 2 | 3 | 4 | def test_type(): 5 | # Arrange. 6 | program = """ 7 | x = 1 8 | x type 9 | """ 10 | 11 | # Act. 12 | out = execute(program) 13 | 14 | # Assert. 15 | assert out == 'Int' 16 | 17 | 18 | def test_pattern_matching_integer_branch(): 19 | # Arrange. 20 | program = """ 21 | just: (x: Int) = x 22 | just: (x) = Error 23 | 24 | just: 1 25 | """ 26 | 27 | # Act. 28 | out = execute(program) 29 | 30 | # Assert. 31 | assert out == 1 32 | 33 | 34 | def test_pattern_matching_common_branch(): 35 | # Arrange. 36 | program = """ 37 | just: (x: Int) = x 38 | just: (x) = Error 39 | 40 | just: a 41 | """ 42 | 43 | # Act. 44 | out = execute(program) 45 | 46 | # Assert. 47 | assert out == 'Error' 48 | 49 | 50 | def test_plus_operator(): 51 | # Arrange. 52 | program = """ 53 | 1 + 2 54 | """ 55 | 56 | # Act. 57 | out = execute(program) 58 | 59 | # Assert. 60 | assert out == 3 61 | 62 | 63 | def test_minus_operator(): 64 | # Arrange. 65 | program = """ 66 | 2 - 1 67 | """ 68 | 69 | # Act. 70 | out = execute(program) 71 | 72 | # Assert. 73 | assert out == 1 74 | -------------------------------------------------------------------------------- /src/tests/integration/types/string_test.py: -------------------------------------------------------------------------------- 1 | from tale.core import execute 2 | 3 | 4 | def test_type(): 5 | # Arrange. 6 | program = """ 7 | x = "a" 8 | x type 9 | """ 10 | 11 | # Act. 12 | out = execute(program) 13 | 14 | # Assert. 15 | assert out == 'String' 16 | --------------------------------------------------------------------------------