Exemple #1
0
 def testParams(self):
     style['printWidth'] = 1000
     # function applyStyle(lexems: Lexem[], pos: number, isVertical: boolean, style: Styles): {value: string, pos: number} {}
     lexems = [
         ('function', 'keyword'),
         Lex.space,
         ('applyStyle', 'funcName'),
         Lex.paramsBegin,
         ('lexems', 'varName'),
         Lex.colon,
         ('Lexem', 'typeName'),
         Lex.arrayBegin,
         Lex.arrayEnd,
         Lex.paramDiv,
         ('pos', 'varName'),
         Lex.colon,
         Lex.typeName('number'),
         Lex.paramDiv,
         Lex.varName('isVertical'),
         Lex.colon,
         Lex.typeName('boolean'),
         Lex.paramDiv,
         Lex.varName('style'),
         Lex.colon,
         Lex.typeName('Styles'),
         Lex.paramsEnd,
         Lex.colon,
         Lex.objBegin,
         Lex.fieldName('value'),
         Lex.colon,
         Lex.typeName('string'),
         Lex.itemDiv,
         Lex.fieldName('pos'),
         Lex.colon,
         Lex.typeName('number'),
         Lex.objEnd,
         Lex.bodyBegin,
         Lex.bodyEnd,
     ]
     outRows = []
     formatLexems(outRows, lexems, 0, 0, style)
     # for row in outRows:
     # 	print('<<<%s>>>' % row.replace(' ', '_'))
     self.assertEqual(outRows, [
         "function applyStyle(lexems: Lexem[], pos: number, isVertical: boolean, style: Styles): {value: string, pos: number} {",
         "}"
     ])
Exemple #2
0
def exportVar(var, lexems, rules):
    if var.type == 'field':
        lexems.append(Lex.fieldName(var.getName()))
    else:
        lexems.append(Lex.varName(var.getName()))
    # Возможна ситуация, когда тип не указывается при объявлении. Если он следует из выражения
    txType = var.getTypeTaxon()
    if 'hiddenType' not in var.attrs:
        lexems.append(Lex.colon)
        txType.exportLexems(lexems, rules)

    txValue = var.getValueTaxon()
    if txValue:
        lexems.append(Lex.binop('='))
        txValue.exportLexems(lexems, rules)
Exemple #3
0
 def exportLexems(self, lexems, style):
     self.getLeft().exportLexems(lexems, style)
     lexems += [Lex.dot, Lex.fieldName(self.memberName)]