tlexer.nim 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. discard """
  2. disabled: true
  3. """
  4. # We start with a comment
  5. # This is the same comment
  6. # This is a new one!
  7. import
  8. lexbase, os, strutils
  9. type
  10. TMyRec {.final.} = object
  11. x, y: int # coordinates
  12. c: char # a character
  13. a: int32 # an integer
  14. PMyRec = ref TMyRec # a reference to `TMyRec`
  15. proc splitText(txt: string): seq[string] # splits a text into several lines
  16. # the comment continues here
  17. # this is not easy to parse!
  18. proc anotherSplit(txt: string): seq[string] =
  19. # the comment should belong to `anotherSplit`!
  20. # another problem: comments are statements!
  21. const
  22. x = 0B0_10001110100_0000101001000111101011101111111011000101001101001001'f64 # x ~~ 1.72826e35
  23. myNan = 0B01111111100000101100000000001000'f32 # NAN
  24. y = """
  25. a rather long text.
  26. Over many
  27. lines.
  28. """
  29. s = "\xff"
  30. a = {0..234}
  31. b = {0..high(int)}
  32. v = 0'i32
  33. z = 6767566'f32
  34. # small test program for lexbase
  35. proc main*(infile: string, a, b: int, someverylongnamewithtype = 0,
  36. anotherlongthingie = 3) =
  37. var
  38. myInt: int = 0
  39. s: seq[string]
  40. # this should be an error!
  41. if initBaseLexer(L, infile, 30): nil
  42. else:
  43. writeLine(stdout, "could not open: " & infile)
  44. writeLine(stdout, "Success!")
  45. call(3, # we use 3
  46. 12, # we use 12
  47. 43) # we use 43
  48. main(ParamStr(1), 9, 0)