tarc3.nim 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. discard """
  2. cmd: '''nim c --gc:arc $file'''
  3. """
  4. when defined(cpp):
  5. {.passC: "-std=gnu++2a".}
  6. type
  7. TokenKind* = enum
  8. tkColon
  9. tkComma
  10. tkString
  11. tkNumber
  12. tkInt64
  13. tkIdent
  14. Token* = object
  15. case kind*: TokenKind
  16. of tkString: strVal*: string
  17. of tkNumber: numVal*: float
  18. of tkInt64: int64Val*: int64
  19. of tkIdent: ident*: string
  20. else: discard
  21. pos*: Natural
  22. Token2* = object
  23. case kind*: TokenKind
  24. of tkString: strVal*: string
  25. of tkNumber: numVal*: float
  26. of tkInt64, tkColon..tkComma:
  27. str1*: array[2, string]
  28. float: float
  29. else: discard
  30. pos*: Natural
  31. Token3* = object
  32. case kind*: TokenKind
  33. of tkNumber: numVal*: float
  34. of tkInt64, tkComma..tkString: ff: seq[float]
  35. else: str1*: string
  36. Token4* = object
  37. case kind*: TokenKind
  38. of tkNumber: numVal*: float
  39. of tkInt64, tkComma..tkString: ff: seq[float]
  40. else: str1*: string
  41. case kind2*: TokenKind
  42. of tkNumber:
  43. numVal2*: float
  44. intSeqVal3*: seq[int]
  45. of tkInt64, tkComma..tkString:
  46. case kind3*: TokenKind
  47. of tkNumber: numVal3*: float
  48. of tkInt64, tkComma..tkString:
  49. ff3: seq[float]
  50. ff5: string
  51. else:
  52. str3*: string
  53. mysrq: seq[int]
  54. else:
  55. case kind4*: TokenKind
  56. of tkNumber: numVal4*: float
  57. of tkInt64, tkComma..tkString: ff4: seq[float]
  58. else: str4*: string
  59. BaseLexer* = object of RootObj
  60. input*: string
  61. pos*: Natural
  62. Json5Lexer* = object of BaseLexer
  63. JsonLexer* = object of BaseLexer
  64. allowComments*: bool
  65. allowSpecialFloats*: bool
  66. Lexer* = Json5Lexer | JsonLexer
  67. Parser[T: Lexer] = object
  68. l: T
  69. tok: Token
  70. tok2: Token2
  71. tok3: Token3
  72. tok4: Token4
  73. allowTrailingComma: bool
  74. allowIdentifierObjectKey: bool
  75. proc initJson5Lexer*(input: string): Json5Lexer =
  76. result.input = input
  77. proc parseJson5*(input: string) =
  78. var p = Parser[Json5Lexer](
  79. l: initJson5Lexer(input),
  80. allowTrailingComma: true,
  81. allowIdentifierObjectKey: true
  82. )
  83. let x = "string"
  84. parseJson5(x)