Beispiel #1
0
 def test_literal(self):
     '''
     Simple literal should compile directly.
     '''
     token = Token(Literal('abc'))
     token.compile()
     assert token.regexp == 'abc', repr(token.regexp)
Beispiel #2
0
 def test_real(self):
     '''
     A real is more complex, but still compiles.
     '''
     token = Token(Real(exponent='Ee'))
     token.compile()
     assert token.regexp == \
         '(?:[\\+\\-])?(?:(?:[0-9](?:[0-9])*)?\\.[0-9](?:[0-9])*|[0-9](?:[0-9])*(?:\\.)?)(?:[Ee](?:[\\+\\-])?[0-9](?:[0-9])*)?', \
         repr(token.regexp)
Beispiel #3
0
 def test_impossible(self):
     '''
     Cannot compile arbitrary functions.
     '''
     try:
         token = Token(Real() > (lambda x: x))
         token.compile()
         assert False, 'Expected error'
     except LexerError:
         pass