lexer.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # test the lexer
  2. try:
  3. eval
  4. exec
  5. except NameError:
  6. print("SKIP")
  7. raise SystemExit
  8. # __debug__ is a special symbol
  9. print(type(__debug__))
  10. # short input
  11. exec("")
  12. exec("\n")
  13. exec("\n\n")
  14. exec("\r")
  15. exec("\r\r")
  16. exec("\t")
  17. exec("\r\n")
  18. exec("\nprint(1)")
  19. exec("\rprint(2)")
  20. exec("\r\nprint(3)")
  21. exec("\n5")
  22. exec("\r6")
  23. exec("\r\n7")
  24. print(eval("1"))
  25. print(eval("12"))
  26. print(eval("123"))
  27. print(eval("1\n"))
  28. print(eval("12\n"))
  29. print(eval("123\n"))
  30. print(eval("1\r"))
  31. print(eval("12\r"))
  32. print(eval("123\r"))
  33. # line continuation
  34. print(eval("'123' \\\r '456'"))
  35. print(eval("'123' \\\n '456'"))
  36. print(eval("'123' \\\r\n '456'"))
  37. print(eval("'123'\\\r'456'"))
  38. print(eval("'123'\\\n'456'"))
  39. print(eval("'123'\\\r\n'456'"))
  40. # backslash used to escape a line-break in a string
  41. print('a\
  42. b')
  43. # lots of indentation
  44. def a(x):
  45. if x:
  46. if x:
  47. if x:
  48. if x:
  49. if x:
  50. if x:
  51. if x:
  52. if x:
  53. if x:
  54. if x:
  55. if x:
  56. if x:
  57. if x:
  58. if x:
  59. if x:
  60. print(x)
  61. a(1)
  62. # badly formed hex escape sequences
  63. try:
  64. exec(r"'\x0'")
  65. except SyntaxError:
  66. print("SyntaxError")
  67. try:
  68. exec(r"b'\x0'")
  69. except SyntaxError:
  70. print("SyntaxError")
  71. try:
  72. exec(r"'\u000'")
  73. except SyntaxError:
  74. print("SyntaxError")
  75. try:
  76. exec(r"'\U0000000'")
  77. except SyntaxError:
  78. print("SyntaxError")