Create assertions on import and function definition parsers
This commit is contained in:
@@ -103,7 +103,7 @@ def ArgumentParser(input):
|
|||||||
|
|
||||||
return Parser.allOf(
|
return Parser.allOf(
|
||||||
Parser.optional(TypeParser),
|
Parser.optional(TypeParser),
|
||||||
IdentifierLiteralParser,
|
Parser.doAssert(IdentifierLiteralParser, "argument name"),
|
||||||
Parser.optional(Parser.terminal(TokenType.DOTS, lambda val, pos: True)),
|
Parser.optional(Parser.terminal(TokenType.DOTS, lambda val, pos: True)),
|
||||||
createNode=createNode,
|
createNode=createNode,
|
||||||
name="function argument"
|
name="function argument"
|
||||||
@@ -115,24 +115,26 @@ def ArgumentsDeclarationParser(input):
|
|||||||
ArgumentsDeclaration,
|
ArgumentsDeclaration,
|
||||||
TokenType.OPEN_PAREN,
|
TokenType.OPEN_PAREN,
|
||||||
TokenType.CLOSE_PAREN,
|
TokenType.CLOSE_PAREN,
|
||||||
ArgumentParser
|
Parser.doAssert(ArgumentParser, "function/method argument")
|
||||||
)(input)
|
)(input)
|
||||||
|
|
||||||
|
|
||||||
def FunctionDefinitionParser(input):
|
def FunctionDefinitionParser(input):
|
||||||
return Parser.allOf(
|
return Parser.allOf(
|
||||||
Parser.terminal(TokenType.FUNCTION),
|
Parser.terminal(TokenType.FUNCTION),
|
||||||
IdentifierLiteralParser,
|
Parser.doAssert(IdentifierLiteralParser, "function/method name"),
|
||||||
ArgumentsDeclarationParser,
|
Parser.doAssert(ArgumentsDeclarationParser, "function/method arguments"),
|
||||||
MethodBodyParser,
|
Parser.doAssert(MethodBodyParser, "function/method body"),
|
||||||
createNode=lambda _, name, args, body: FunctionDefinition.withValues(name, args, body),
|
createNode=lambda _, name, args, body: FunctionDefinition.withValues(name, args, body),
|
||||||
name="function definition"
|
name="function definition"
|
||||||
)(input)
|
)(input)
|
||||||
|
|
||||||
|
|
||||||
def MethodBodyParser(input):
|
def MethodBodyParser(input):
|
||||||
bodyItem = Parser.oneOf(
|
bodyItem = Parser.oneOf(
|
||||||
StatementParser,
|
|
||||||
ReturnParser,
|
ReturnParser,
|
||||||
|
StatementParser,
|
||||||
|
assertExpected="statement",
|
||||||
name="function body item"
|
name="function body item"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class Import(Node):
|
|||||||
def ImportParser(input):
|
def ImportParser(input):
|
||||||
return Parser.allOf(
|
return Parser.allOf(
|
||||||
Parser.terminal(TokenType.IMPORT),
|
Parser.terminal(TokenType.IMPORT),
|
||||||
StringParser,
|
Parser.doAssert(StringParser, "import source as string"),
|
||||||
createNode=lambda imp, source: Import.withValue(source),
|
createNode=lambda imp, source: Import.withValue(source),
|
||||||
name="import"
|
name="import"
|
||||||
)(input)
|
)(input)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ def noteTokenizer(input, current, line):
|
|||||||
rawValue = ''
|
rawValue = ''
|
||||||
if input[current] == '@':
|
if input[current] == '@':
|
||||||
rawValue += input[current+consumedChars]
|
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'):
|
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]
|
rawValue += input[current + consumedChars]
|
||||||
notePitch = input[current+consumedChars]
|
notePitch = input[current+consumedChars]
|
||||||
|
|||||||
Reference in New Issue
Block a user