示例#1
0
 def test_loop(self):
     """test : loop"""
     cases = [
         ('abcde', '((abcde)*)'),
         ('(abcde)', '(((abcde))*)'),
     ]
     for case in cases:
         self.assertEqual(yare.loop(case[0]), case[1])
示例#2
0
文件: cmm_lex.py 项目: hsinhuang/yaly
# Literals
def t_INTCON(t):
    t.value = int(t.value)
    return t
t_INTCON.__doc__ = yare.concat([
    yare.loop_(yare.DIGIT),
])

__STRINGCON__ = ' !#$%&\'()*+,-./0123456789:;<=>?@' + \
    'ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~'
t_STRINGCON = yare.concat([
    '"',
    yare.loop(
        yare.select([
            yare.select(list(__STRINGCON__)),
            yare.concat(['\\', yare.select(['n', '\\', '"'])]),
        ])
    ),
    '"',
])

__CHARCON__ = ' !#$%&()*+,-./0123456789:;<=>?@' + \
    'ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~'
t_CHARCON = yare.concat([
    '\'',
    yare.select([
        yare.select(list(__CHARCON__)),
        yare.concat(['\\', yare.select(['n', '\\', '\'', '0'])]),
    ]),
    '\'',
])
示例#3
0
def t_INTCON(t):
    t.value = int(t.value)
    return t


t_INTCON.__doc__ = yare.concat([
    yare.loop_(yare.DIGIT),
])

__STRINGCON__ = ' !#$%&\'()*+,-./0123456789:;<=>?@' + \
    'ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~'
t_STRINGCON = yare.concat([
    '"',
    yare.loop(
        yare.select([
            yare.select(list(__STRINGCON__)),
            yare.concat(['\\', yare.select(['n', '\\', '"'])]),
        ])),
    '"',
])

__CHARCON__ = ' !#$%&()*+,-./0123456789:;<=>?@' + \
    'ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~'
t_CHARCON = yare.concat([
    '\'',
    yare.select([
        yare.select(list(__CHARCON__)),
        yare.concat(['\\', yare.select(['n', '\\', '\'', '0'])]),
    ]),
    '\'',
])