parser Linglish: ignore: '\\s+' token END: "$" token WORD: r"[a-zA-Z_.]+" token NUM: r"[0-9]+" token POSSESSIVE: r"[a-zA-Z_.]+'s" token SINGLEQUOTED: r"'[^']*'" token DOUBLEQUOTED: r'"[^"]*"' rule script: {{ scriptlist = [] }} ( command {{ scriptlist.append(command) }} ["then"] | END {{ return scriptlist }} )* rule command: ( tell {{ return tell }} | wait {{ return wait }} | ask {{ return ask }} | run {{ return run }} ) rule run: {{ dic = {"cmd": "run"} }} ( "run" quoted {{ dic["runnee"] = quoted }} ) {{ return dic }} rule wait: {{ dic = {"cmd": "wait"} }} ( "wait for" {{ dic["wait_count"] = 1 }} | "wait repeatedly for" {{ dic["wait_count"] = -1 }} | "wait" NUM {{ dic["wait_count"] = int(NUM) }} "times for" ) possessive {{ dic['application'] = possessive }} WORD {{ dic['signal'] = WORD }} {{ dic["bus"] = None }} ( "on System" {{ dic["bus"] = "System" }} | "on the System bus" {{ dic["bus"] = "System" }} | "on Session" {{ dic["bus"] = "Session" }} | "on the Session bus" {{ dic["bus"] = "Session" }} )? {{ dic["retvals"] = [] }} ( "as" paramlist {{ dic["retvals"] = paramlist }} )? {{ dic["required_value"] = None }} ( "to be" rvalue {{ dic["required_value"] = rvalue }} )? {{ return dic }} rule ask: "ask" {{ dic = {"cmd": "ask"} }} ( possessive {{ dic['application'] = possessive }} WORD {{ dic['obj'] = WORD }} | WORD {{ dic['application'] = WORD }} {{ dic['obj'] = None }} ) {{ dic["bus"] = None }} ( "on System" {{ dic["bus"] = "System" }} | "on the System bus" {{ dic["bus"] = "System" }} | "on Session" {{ dic["bus"] = "Session" }} | "on the Session bus" {{ dic["bus"] = "Session" }} )? "for" WORD {{ dic['prop'] = WORD }} {{ return dic }} rule rvalue: ( quoted {{ return {"type": "string", "value": quoted} }} | NUM {{ return {"type": "integer", "value": NUM} }} | WORD {{ return {"type": "var", "name": WORD} }} | "the result" {{ return {"type": "var", "name": "the result"} }} | "it" {{ return {"type": "var", "name": "it"} }} ) rule quoted: ( SINGLEQUOTED {{ return SINGLEQUOTED[1:-1] }} | DOUBLEQUOTED {{ return DOUBLEQUOTED[1:-1] }} ) rule tell: "tell" {{ dic = { "cmd": "tell" } }} ( WORD {{ dic["application"] = WORD }} {{ dic["obj"] = None }} | possessive {{ dic["application"] = possessive }} WORD {{ dic["obj"] = WORD }} ) {{ dic["interface"] = None }} ( "via" WORD {{ dic["interface"] = WORD }} )? {{ dic["bus"] = None }} ( "on System" {{ dic["bus"] = "System" }} | "on the System bus" {{ dic["bus"] = "System" }} | "on Session" {{ dic["bus"] = "Session" }} | "on the Session bus" {{ dic["bus"] = "Session" }} )? "to" WORD {{ dic["action"] = WORD }} {{ dic["params"] = [] }} ( "with" paramlist {{ dic["params"] = paramlist }} )? {{ dic["retvals"] = [] }} ( "as" paramlist {{ dic["retvals"] = paramlist }} )? {{ return dic }} rule possessive: POSSESSIVE {{ return POSSESSIVE[:-2] }} rule paramlist: {{ params = [] }} # init the list rvalue {{ params.append(rvalue) }} # first word ( # begin loop "," rvalue {{ params.append(rvalue) }} # add each extra word ) * # rpt as necessary {{ return params }} # return list # note for ask: ask linglish about tomboy should document it # note for tell: check all objects, if command is unambiguous then, use it # control statements like if?