Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
def parse_string_constant(string: str) -> Maybe[Tuple[str, str]]:
    matchObj = re.match(r"\"(.*?)\"", string)
    if matchObj:
        return Some((matchObj.group(), "stringConstant"))
    return Fail()
Ejemplo n.º 5
0
def parse_symbol(string: str) -> Maybe[Tuple[str, str]]:
    matchObj = re.match(r"[{}()[\].,;+\-*/&|<>=~]", string)
    if matchObj:
        return Some((matchObj.group(), "symbol"))
    return Fail()