diff --git a/grammar b/grammar index e576f37..b89deb0 100644 --- a/grammar +++ b/grammar @@ -33,6 +33,8 @@ PITCH_MODIFIER = 'b' | '#' ::= '(' ')' | '(' ::= ', ' | ')' + = ? '...'? | '...'? + ::= ? ::= '{' '}' | '{' diff --git a/smnp/ast/node/function.py b/smnp/ast/node/function.py index 8d1fdbe..8539e5e 100644 --- a/smnp/ast/node/function.py +++ b/smnp/ast/node/function.py @@ -1,10 +1,11 @@ from smnp.ast.node.block import BlockNode +from smnp.ast.node.expression import ExpressionNode from smnp.ast.node.identifier import IdentifierNode from smnp.ast.node.iterable import abstractIterableParser from smnp.ast.node.model import Node from smnp.ast.node.none import NoneNode from smnp.ast.node.statement import StatementNode -from smnp.ast.node.variable import TypedVariableNode +from smnp.ast.node.type import TypeNode from smnp.ast.parser import Parser from smnp.token.type import TokenType @@ -16,6 +17,48 @@ class ArgumentsDeclarationNode(Node): raise RuntimeError("This class is not supposed to be automatically called") +class ArgumentDefinitionNode(ExpressionNode): + def __init__(self, pos): + super().__init__(pos) + self.children.append(NoneNode()) + + @property + def type(self): + return self[0] + + @type.setter + def type(self, value): + self[0] = value + + @property + def variable(self): + return self[1] + + @variable.setter + def variable(self, value): + self[1] = value + + @classmethod + def parser(cls): + def createNode(type, variable): + node = ArgumentDefinitionNode(type.pos) + node.type = type + node.variable = variable + return node + + return Parser.allOf( + TypeNode.parse, + Parser.doAssert(IdentifierNode.identifierParser(), "variable name"), + createNode=createNode + ) + + @classmethod + def _parse(cls, input): + #TODO + raise RuntimeError("Not implemented yet. There is still required work to correctly build AST related to IdentifierNode") + + + class FunctionDefinitionNode(StatementNode): def __init__(self, pos): super().__init__(pos) @@ -64,4 +107,4 @@ class FunctionDefinitionNode(StatementNode): @staticmethod def _argumentsDeclarationParser(): - return abstractIterableParser(ArgumentsDeclarationNode, TokenType.OPEN_PAREN, TokenType.CLOSE_PAREN, TypedVariableNode.parser()) \ No newline at end of file + return abstractIterableParser(ArgumentsDeclarationNode, TokenType.OPEN_PAREN, TokenType.CLOSE_PAREN, ArgumentDefinitionNode.parser()) \ No newline at end of file diff --git a/smnp/ast/node/variable.py b/smnp/ast/node/variable.py index 68b830f..b28b04f 100644 --- a/smnp/ast/node/variable.py +++ b/smnp/ast/node/variable.py @@ -1,46 +1,3 @@ -from smnp.ast.node.expression import ExpressionNode -from smnp.ast.node.identifier import IdentifierNode -from smnp.ast.node.none import NoneNode -from smnp.ast.node.type import TypeNode -from smnp.ast.parser import Parser -class TypedVariableNode(ExpressionNode): - def __init__(self, pos): - super().__init__(pos) - self.children.append(NoneNode()) - @property - def type(self): - return self[0] - - @type.setter - def type(self, value): - self[0] = value - - @property - def variable(self): - return self[1] - - @variable.setter - def variable(self, value): - self[1] = value - - @classmethod - def parser(cls): - def createNode(type, variable): - node = TypedVariableNode(type.pos) - node.type = type - node.variable = variable - return node - - return Parser.allOf( - TypeNode.parse, - Parser.doAssert(IdentifierNode.identifierParser(), "variable name"), - createNode=createNode - ) - - @classmethod - def _parse(cls, input): - #TODO - raise RuntimeError("Not implemented yet. There is still required work to correctly build AST related to IdentifierNode") diff --git a/smnp/runtime/evaluators/function.py b/smnp/runtime/evaluators/function.py index 102b603..92c7247 100644 --- a/smnp/runtime/evaluators/function.py +++ b/smnp/runtime/evaluators/function.py @@ -1,6 +1,6 @@ +from smnp.ast.node.function import ArgumentDefinitionNode from smnp.ast.node.none import NoneNode from smnp.ast.node.ret import ReturnNode -from smnp.ast.node.variable import TypedVariableNode from smnp.error.runtime import RuntimeException from smnp.function.signature import signature from smnp.runtime.evaluator import Evaluator, evaluate @@ -45,7 +45,7 @@ def argumentsNodeToMethodSignature(node): sign = [] for child in node.children: - if type(child) == TypedVariableNode: + if type(child) == ArgumentDefinitionNode: if type(child.type.specifiers) == NoneNode: sign.append(ofType(child.type.type)) elif child.type.type == Type.LIST and len(child.type.specifiers) == 1: