Create assertions on import and function definition parsers
This commit is contained in:
@@ -103,7 +103,7 @@ def ArgumentParser(input):
|
||||
|
||||
return Parser.allOf(
|
||||
Parser.optional(TypeParser),
|
||||
IdentifierLiteralParser,
|
||||
Parser.doAssert(IdentifierLiteralParser, "argument name"),
|
||||
Parser.optional(Parser.terminal(TokenType.DOTS, lambda val, pos: True)),
|
||||
createNode=createNode,
|
||||
name="function argument"
|
||||
@@ -115,24 +115,26 @@ def ArgumentsDeclarationParser(input):
|
||||
ArgumentsDeclaration,
|
||||
TokenType.OPEN_PAREN,
|
||||
TokenType.CLOSE_PAREN,
|
||||
ArgumentParser
|
||||
Parser.doAssert(ArgumentParser, "function/method argument")
|
||||
)(input)
|
||||
|
||||
|
||||
def FunctionDefinitionParser(input):
|
||||
return Parser.allOf(
|
||||
Parser.terminal(TokenType.FUNCTION),
|
||||
IdentifierLiteralParser,
|
||||
ArgumentsDeclarationParser,
|
||||
MethodBodyParser,
|
||||
Parser.doAssert(IdentifierLiteralParser, "function/method name"),
|
||||
Parser.doAssert(ArgumentsDeclarationParser, "function/method arguments"),
|
||||
Parser.doAssert(MethodBodyParser, "function/method body"),
|
||||
createNode=lambda _, name, args, body: FunctionDefinition.withValues(name, args, body),
|
||||
name="function definition"
|
||||
)(input)
|
||||
|
||||
|
||||
def MethodBodyParser(input):
|
||||
bodyItem = Parser.oneOf(
|
||||
StatementParser,
|
||||
ReturnParser,
|
||||
StatementParser,
|
||||
assertExpected="statement",
|
||||
name="function body item"
|
||||
)
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class Import(Node):
|
||||
def ImportParser(input):
|
||||
return Parser.allOf(
|
||||
Parser.terminal(TokenType.IMPORT),
|
||||
StringParser,
|
||||
Parser.doAssert(StringParser, "import source as string"),
|
||||
createNode=lambda imp, source: Import.withValue(source),
|
||||
name="import"
|
||||
)(input)
|
||||
|
||||
@@ -14,7 +14,7 @@ def noteTokenizer(input, current, line):
|
||||
rawValue = ''
|
||||
if input[current] == '@':
|
||||
rawValue += input[current+consumedChars]
|
||||
consumedChars += 1
|
||||
consumedChars += 1 # TODO: Check if next item does even exist
|
||||
if input[current+consumedChars] in ('C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'A', 'a', 'H', 'h', 'B', 'b'):
|
||||
rawValue += input[current + consumedChars]
|
||||
notePitch = input[current+consumedChars]
|
||||
|
||||
Reference in New Issue
Block a user