Refactor tokenizer: remove colon, add colon as duration separator to note and create TokenType.TYPE

This commit is contained in:
Bartłomiej Pluta
2019-07-05 23:09:27 +02:00
parent f7b8704516
commit c1fbc2fe23
6 changed files with 43 additions and 30 deletions

View File

@@ -1,5 +0,0 @@
from smnp.token.tools import tokenizeChar
from smnp.token.type import TokenType
def tokenizeColon(input, current, line):
return tokenizeChar(TokenType.COLON, ':', input, current, line)

View File

@@ -25,7 +25,7 @@ def tokenizeNote(input, current, line):
octave = input[current+consumedChars]
consumedChars += 1
if current+consumedChars < len(input) and input[current+consumedChars] == '^':
if current+consumedChars < len(input) and input[current+consumedChars] == ':':
duration = ''
consumedChars += 1
while current+consumedChars < len(input) and re.match(r'\d', input[current+consumedChars]):

View File

@@ -0,0 +1,8 @@
from smnp.token.tools import tokenizeKeywords
from smnp.token.type import TokenType
from smnp.type.model import Type
def tokenizeType(input, current, line):
types = [ type.name.lower() for type in Type ]
return tokenizeKeywords(TokenType.TYPE, input, current, line, *types)