def main(cls, args): """ generated source for method main """ if len(args) == 1: print("Uso: IdentifierMain <string>") else: id = Identifier() if id.validateIdentifier(args[1]): print("Valido") else: print("Invalido")
def start(update, context): IDF = Identifier(Tokens=["DOGE-USD"]) while (True): identifier = IDF.update() for token in identifier: if identifier[token] > 3: context.bot.send_message(chat_id=update.effective_chat.id, text="{} is striking {} downs".format( token, identifier["DOGE-USD"])) time.sleep(60)
def parseCommand(): if (Parser.tokens.actual.token_type == "PTVIRGULA"): node = NoOp() Parser.tokens.selectNext() return node elif (Parser.tokens.actual.token_type == "DATA_TYPE"): identifier = Identifier() identifier.tipo = Parser.tokens.actual.value Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "NOME"): identifier.value = Parser.tokens.actual.value Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "EQUAL"): node = Assignment(Parser.tokens.actual.value) Parser.tokens.selectNext() node.children.append(identifier) node.children.append(Parser.parseRelexpr()) if (Parser.tokens.actual.token_type == "PTVIRGULA"): Parser.tokens.selectNext() return node else: raise ValueError('Esperado um ponto e virgula') else: raise ValueError('Esperado um assignment') elif (Parser.tokens.actual.token_type == "LOG"): node = Echo(Parser.tokens.actual.value) Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "APAR"): Parser.tokens.selectNext() node.children.append(Parser.parseRelexpr()) if (Parser.tokens.actual.token_type == "FPAR"): Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "PTVIRGULA"): Parser.tokens.selectNext() return node else: raise ValueError('Esperado um ponto e virgula') else: raise ValueError('Esperado um parentesis') else: raise ValueError('Esperado um parentesis') elif (Parser.tokens.actual.token_type == "IF"): node = If(Parser.tokens.actual.value) Parser.tokens.selectNext() node.children.append(Parser.parseRelexpr()) # if(Parser.tokens.actual.token_type == "INTERR"): # Parser.tokens.selectNext() node.children.append(Parser.parseCommand()) # if(Parser.tokens.actual.token_type == "DOISP"): # Parser.tokens.selectNext() node.children.append(Parser.parseCommand()) return node # else: # return node # else: # raise ValueError('Esperado um parenteses') elif (Parser.tokens.actual.token_type == "WHILE"): node = While(Parser.tokens.actual.value) Parser.tokens.selectNext() node.children.append(Parser.parseRelexpr()) node.children.append(Parser.parseCommand()) return node elif (Parser.tokens.actual.token_type == "FUNCTION"): Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "NOME"): node = FuncDec(Parser.tokens.actual.value) Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "EQUAL"): Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "DATA_TYPE"): node.return_type = Parser.tokens.actual.value Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "APAR"): Parser.tokens.selectNext() while (True): if (Parser.tokens.actual.token_type == "DATA_TYPE"): identifier = Identifier() identifier.tipo = Parser.tokens.actual.value Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "NOME"): identifier.value = Parser.tokens.actual.value Parser.tokens.selectNext() node.children.append(identifier) if (Parser.tokens.actual.token_type == "VIRGULA"): Parser.tokens.selectNext() elif (Parser.tokens.actual.token_type == "FPAR"): Parser.tokens.selectNext() node.children.append( Parser.parseBlock()) return node else: raise ValueError( "Esperado uma virgula ou parentesis" ) elif (Parser.tokens.actual.token_type == "FPAR" ): Parser.tokens.selectNext() node.children.append(Parser.parseBlock()) return node else: raise ValueError("Esperado um identifier") else: raise ValueError("Esperado um parentesis") else: raise ValueError( "Esperado o tipo do retorno da funcao") else: raise ValueError("Esperado o nome da funcao") elif (Parser.tokens.actual.token_type == "RETURN"): node = Return(Parser.tokens.actual.token_type) Parser.tokens.selectNext() node.children.append(Parser.parseRelexpr()) if (Parser.tokens.actual.token_type == "PTVIRGULA"): Parser.tokens.selectNext() return node else: raise ValueError('Esperado um ponto e virgula') elif (Parser.tokens.actual.token_type == "NOME"): node = FuncCall(Parser.tokens.actual.value) Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "APAR"): Parser.tokens.selectNext() while (True): if (Parser.tokens.actual.token_type == "FPAR"): Parser.tokens.selectNext() return node else: node.children.append(Parser.parseRelexpr()) if (Parser.tokens.actual.token_type == "VIRGULA"): Parser.tokens.selectNext() elif (Parser.tokens.actual.token_type == "FPAR"): Parser.tokens.selectNext() return node else: raise ValueError( "Esperado uma virgula ou parentesis") else: raise ValueError("Esperado um parentesis") else: return Parser.parseBlock()
def parseFactor(): if (Parser.tokens.actual.token_type == "INT"): node = IntVal(Parser.tokens.actual.value) Parser.tokens.selectNext() return node if (Parser.tokens.actual.token_type == "FLOAT"): node = FloatVal(Parser.tokens.actual.value) Parser.tokens.selectNext() return node elif (Parser.tokens.actual.token_type == "BOOL"): node = BoolVal(Parser.tokens.actual.value) Parser.tokens.selectNext() return node elif (Parser.tokens.actual.token_type == "STRING"): node = StringVal(Parser.tokens.actual.value) Parser.tokens.selectNext() return node elif (Parser.tokens.actual.token_type == "IDENTIFIER"): identifier = Identifier() identifier.value = Parser.tokens.actual.value Parser.tokens.selectNext() return identifier elif ((Parser.tokens.actual.token_type == "PLUS") or (Parser.tokens.actual.token_type == "MINUS")): if (Parser.tokens.actual.token_type == "PLUS"): node = UnOp(Parser.tokens.actual.value) Parser.tokens.selectNext() res_factor = Parser.parseFactor() node.children.append(res_factor) elif (Parser.tokens.actual.token_type == "MINUS"): node = UnOp(Parser.tokens.actual.value) Parser.tokens.selectNext() res_factor = Parser.parseFactor() node.children.append(res_factor) elif (Parser.tokens.actual.token_type == "NOT"): node = UnOp(Parser.tokens.actual.value) Parser.tokens.selectNext() res_factor = Parser.parseFactor() node.children.append(res_factor) elif (Parser.tokens.actual.token_type == "APAR"): Parser.tokens.selectNext() res = Parser.parseRelexpr() if (Parser.tokens.actual.token_type == "FPAR"): Parser.tokens.selectNext() return res else: raise ValueError('Parenteses nao foi fechado') elif (Parser.tokens.actual.token_type == "READLINE"): node = Readline(Parser.tokens.actual.value) Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "APAR"): Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "FPAR"): Parser.tokens.selectNext() return node else: raise ValueError('Parenteses nao foi fechado') else: raise ValueError('Parenteses nao foi aberto') elif (Parser.tokens.actual.token_type == "NOME"): value = Parser.tokens.actual.value Parser.tokens.selectNext() if (Parser.tokens.actual.token_type == "APAR"): node = FuncCall(value) Parser.tokens.selectNext() while (True): node.children.append(Parser.parseRelexpr()) if (Parser.tokens.actual.token_type == "VIRGULA"): Parser.tokens.selectNext() elif (Parser.tokens.actual.token_type == "FPAR"): Parser.tokens.selectNext() return node else: raise ValueError("Esperado uma virgula ou parentesis") else: identifier = Identifier() identifier.value = value return identifier else: raise ValueError('Erro') return node
def get_idea_rules(): literals = MappingRule(name="literals", mapping={ "cos": Text("\"") + Key("space"), "num": Text("%(n)d"), }, extras=[ IntegerRef("n", 1, 1000000), Dictation("text"), ]) capitalization = MappingRule(name="capitalization", mapping={ "var <identifier>": Identifier("%(identifier)s"), "camel <identifier>": CamelCase("%(identifier)s"), "speak <identifier>": Text("%(identifier)s"), }, extras=[ Dictation("identifier"), ]) class_rules = MappingRule( name="clas_rules", mapping={ "new": Text("new "), "pum [<identifier>]": Text("public void ") + Identifier("%(identifier)s() { \n"), "puma [<identifier>]": Text("public abstract void ") + Identifier("%(identifier)s() { \n"), "pum static [<identifier>]": Text("public static void ") + Identifier("%(identifier)s() { \n"), "pim [<identifier>]": Text("private void ") + Identifier("%(identifier)s() { \n"), "pima [<identifier>]": Text("private abstract void ") + Identifier("%(identifier)s() { \n"), "pim static [<identifier>]": Text("private void ") + Identifier("%(identifier)s() { \n"), "pom [<identifier>]": Text("protected void ") + Identifier("%(identifier)s() { \n"), "poma [<identifier>]": Text("protected abstract void ") + Identifier("%(identifier)s() { \n"), "pom static [<identifier>]": Text("protected static void ") + Identifier("%(identifier)s() { \n"), "pufu [<class_name>] [var <identifier>]": Text("public ") + CamelCase("%(class_name)s") + Text(" ") + Identifier("%(identifier)s() { \n"), "pifi [<class_name>] [var <identifier>]": Text("private ") + CamelCase("%(class_name)s") + Text(" ") + Identifier("%(identifier)s() { \n"), "pofo [<class_name>] [var <identifier>]": Text("protected ") + CamelCase("%(class_name)s") + Text(" ") + Identifier("%(identifier)s() { \n"), "test [<identifier>]": Key("c-n, enter") + Text("test"), "override": Key("c-n") + Key("down:6") + Key("enter"), "return": Text("return"), "static": Text("static"), "abstract": Text("abstract"), }, extras=[ Dictation("identifier"), Dictation("class_name"), ]) binary_operators = MappingRule(name="binary_operators", mapping={ "star": Key("asterisk"), "sum | plus": Key("plus"), "min": Key("minus"), "and": Text("&&"), "or": Text("||"), }, extras=[ Dictation("identifier"), ]) types = MappingRule(name="types", mapping={ "flag | bool | boolean": Text("boolean "), "long [<identifier>]": Text("long ") + Identifier("%(identifier)s"), "int [<identifier>]": Text("int ") + Identifier("%(identifier)s"), "double [<identifier>]": Text("double ") + Identifier("%(identifier)s"), "float [<identifier>]": Text("float ") + Identifier("%(identifier)s"), "string [<identifier>]": Text("String ") + Identifier("%(identifier)s"), "Integer [<identifier>]": Text("Integer ") + Identifier("%(identifier)s"), "class float [<identifier>]": Text("float ") + Identifier("%(identifier)s"), "class double [<identifier>]": Text("double ") + Identifier("%(identifier)s"), "list": Text("List<"), "collection | col": Text("Collection<"), "hash": Text("HashMap<"), "set": Text("HashSet<"), }, extras=[ Dictation("identifier"), ]) editing_chars = MappingRule(name="editing_chars", mapping={ "slap": Key("enter"), "tab": Key("tab"), "pa": Key("space"), }, extras=[ Dictation("text"), ]) symbols = MappingRule(name="symbols", mapping={ "this": Text("this"), "shasha": Text("//"), "cha": Text("/"), "comments [<text>]": Text("/**") + Key("enter") + Text("%(text)s \n"), "doh | dot": Key("dot"), "del": Key("del"), "se | semicolon": Text(";"), "koh | colon": Key("colon"), "ma": Key("comma"), "rak": Text("{"), "kar": Text("}"), "opa": Text("("), "apo": Text(")"), "brak": Text("["), "krak": Text("]"), }, extras=[ Dictation("text"), ]) ide_basic_commands = MappingRule(name="ide_basic", mapping={ "what | mimi": Key("c-space"), "reformat": Key("a-f8") + Key("enter"), "make class [<text>]": Key("a-f") + Key("a-insert") + Key("enter") + CamelCase("%(text)s"), "rename": Key("s-f6"), }, extras=[ Dictation("text"), ]) return [ binary_operators, types, symbols, ide_basic_commands, editing_chars, capitalization, class_rules, literals ]
def test_parse(self): """ Smoke test for the execute method """ iden = Identifier("%(identifier)s ") iden.execute({"identifier": "transformation count"})