def parse_keyword(string: str) -> Maybe[Tuple[str, str]]: matchObj = re.match( r"class |constructor |function |method |field |static |var |int|char|boolean|void|true|false|null|this|let |do |if|else|while|return", string, ) if matchObj: return Some((matchObj.group(), "keyword")) return Fail()
def parse_identifier(string: str) -> Maybe[Tuple[str, str]]: matchObj = re.match(r"(_|[a-z]|[A-Z])\w*", string) if matchObj: return Some((matchObj.group(), "identifier")) return Fail()
def parse_integer_constant(string: str) -> Maybe[Tuple[str, str]]: matchObj = re.match(r"\d+", string) if matchObj: return Some((matchObj.group(), "integerConstant")) return Fail()
def parse_string_constant(string: str) -> Maybe[Tuple[str, str]]: matchObj = re.match(r"\"(.*?)\"", string) if matchObj: return Some((matchObj.group(), "stringConstant")) return Fail()
def parse_symbol(string: str) -> Maybe[Tuple[str, str]]: matchObj = re.match(r"[{}()[\].,;+\-*/&|<>=~]", string) if matchObj: return Some((matchObj.group(), "symbol")) return Fail()