json.lex.sml 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. structure JSONLexer = struct
  2. datatype yystart_state =
  3. S | INITIAL
  4. structure UserDeclarations =
  5. struct
  6. structure T = JSONTokens
  7. type lex_result = T.token
  8. fun eof () = T.EOF
  9. fun int s = T.INT(valOf(IntInf.fromString s))
  10. fun float s = T.FLOAT(valOf(LargeReal.fromString s))
  11. (* support for incremental construction of strings *)
  12. val sbuf : string list ref = ref []
  13. fun addStr s = sbuf := s :: !sbuf
  14. fun addUChr lit = let
  15. (* trim the "\u" prefix *)
  16. val digits = Substring.triml 2 (Substring.full lit)
  17. val SOME(w, _) = Word.scan StringCvt.HEX Substring.getc digits
  18. in
  19. addStr(UTF8.encode w)
  20. end
  21. fun finishString () = (T.STRING(String.concat(List.rev(!sbuf))) before sbuf := [])
  22. end
  23. local
  24. datatype yymatch
  25. = yyNO_MATCH
  26. | yyMATCH of ULexBuffer.stream * action * yymatch
  27. withtype action = ULexBuffer.stream * yymatch -> UserDeclarations.lex_result
  28. val yytable : ((UTF8.wchar * UTF8.wchar * int) list * int list) Vector.vector =
  29. Vector.fromList []
  30. fun yystreamify' p input = ULexBuffer.mkStream (p, input)
  31. fun yystreamifyReader' p readFn strm = let
  32. val s = ref strm
  33. fun iter(strm, n, accum) =
  34. if n > 1024 then (String.implode (rev accum), strm)
  35. else (case readFn strm
  36. of NONE => (String.implode (rev accum), strm)
  37. | SOME(c, strm') => iter (strm', n+1, c::accum))
  38. fun input() = let
  39. val (data, strm) = iter(!s, 0, [])
  40. in
  41. s := strm;
  42. data
  43. end
  44. in
  45. yystreamify' p input
  46. end
  47. fun yystreamifyInstream' p strm = yystreamify' p (fn ()=>TextIO.input strm)
  48. fun innerLex
  49. (yystrm_, yyss_, yysm) = let
  50. (* current start state *)
  51. val yyss = ref yyss_
  52. fun YYBEGIN ss = (yyss := ss)
  53. (* current input stream *)
  54. val yystrm = ref yystrm_
  55. fun yysetStrm strm = yystrm := strm
  56. fun yygetPos() = ULexBuffer.getpos (!yystrm)
  57. fun yystreamify input = yystreamify' (yygetPos()) input
  58. fun yystreamifyReader readFn strm = yystreamifyReader' (yygetPos()) readFn strm
  59. fun yystreamifyInstream strm = yystreamifyInstream' (yygetPos()) strm
  60. (* start position of token -- can be updated via skip() *)
  61. val yystartPos = ref (yygetPos())
  62. (* get one char of input *)
  63. fun yygetc strm = (case UTF8.getu ULexBuffer.getc strm
  64. of (SOME (0w10, s')) =>
  65. (AntlrStreamPos.markNewLine yysm (ULexBuffer.getpos strm);
  66. SOME (0w10, s'))
  67. | x => x)
  68. fun yygetList getc strm = let
  69. val get1 = UTF8.getu getc
  70. fun iter (strm, accum) =
  71. (case get1 strm
  72. of NONE => rev accum
  73. | SOME (w, strm') => iter (strm', w::accum)
  74. (* end case *))
  75. in
  76. iter (strm, [])
  77. end
  78. (* create yytext *)
  79. fun yymksubstr(strm) = ULexBuffer.subtract (strm, !yystrm)
  80. fun yymktext(strm) = Substring.string (yymksubstr strm)
  81. fun yymkunicode(strm) = yygetList Substring.getc (yymksubstr strm)
  82. open UserDeclarations
  83. fun lex () = let
  84. fun yystuck (yyNO_MATCH) = raise Fail "lexer reached a stuck state"
  85. | yystuck (yyMATCH (strm, action, old)) =
  86. action (strm, old)
  87. val yypos = yygetPos()
  88. fun yygetlineNo strm = AntlrStreamPos.lineNo yysm (ULexBuffer.getpos strm)
  89. fun yygetcolNo strm = AntlrStreamPos.colNo yysm (ULexBuffer.getpos strm)
  90. fun yyactsToMatches (strm, [], oldMatches) = oldMatches
  91. | yyactsToMatches (strm, act::acts, oldMatches) =
  92. yyMATCH (strm, act, yyactsToMatches (strm, acts, oldMatches))
  93. fun yygo actTable =
  94. (fn (~1, _, oldMatches) => yystuck oldMatches
  95. | (curState, strm, oldMatches) => let
  96. val (transitions, finals') = Vector.sub (yytable, curState)
  97. val finals = map (fn i => Vector.sub (actTable, i)) finals'
  98. fun tryfinal() =
  99. yystuck (yyactsToMatches (strm, finals, oldMatches))
  100. fun find (c, []) = NONE
  101. | find (c, (c1, c2, s)::ts) =
  102. if c1 <= c andalso c <= c2 then SOME s
  103. else find (c, ts)
  104. in case yygetc strm
  105. of SOME(c, strm') =>
  106. (case find (c, transitions)
  107. of NONE => tryfinal()
  108. | SOME n =>
  109. yygo actTable
  110. (n, strm',
  111. yyactsToMatches (strm, finals, oldMatches)))
  112. | NONE => tryfinal()
  113. end)
  114. val yylastwasnref = ref (ULexBuffer.lastWasNL (!yystrm))
  115. fun continue() = let val yylastwasn = !yylastwasnref in
  116. let
  117. fun yyAction0 (strm, lastMatch : yymatch) = (yystrm := strm; skip() )
  118. fun yyAction1 (strm, lastMatch : yymatch) = (yystrm := strm; T.LCB )
  119. fun yyAction2 (strm, lastMatch : yymatch) = (yystrm := strm; T.RCB )
  120. fun yyAction3 (strm, lastMatch : yymatch) = (yystrm := strm; T.LB )
  121. fun yyAction4 (strm, lastMatch : yymatch) = (yystrm := strm; T.RB )
  122. fun yyAction5 (strm, lastMatch : yymatch) = (yystrm := strm; T.COMMA )
  123. fun yyAction6 (strm, lastMatch : yymatch) = (yystrm := strm; T.COLON )
  124. fun yyAction7 (strm, lastMatch : yymatch) = (yystrm := strm; T.KW_null )
  125. fun yyAction8 (strm, lastMatch : yymatch) = (yystrm := strm; T.KW_true )
  126. fun yyAction9 (strm, lastMatch : yymatch) = (yystrm := strm; T.KW_false )
  127. fun yyAction10 (strm, lastMatch : yymatch) = let
  128. val yytext = yymktext(strm)
  129. in
  130. yystrm := strm; T.INT(valOf(IntInf.fromString yytext))
  131. end
  132. fun yyAction11 (strm, lastMatch : yymatch) = let
  133. val yytext = yymktext(strm)
  134. in
  135. yystrm := strm; float yytext
  136. end
  137. fun yyAction12 (strm, lastMatch : yymatch) = let
  138. val yytext = yymktext(strm)
  139. in
  140. yystrm := strm; float yytext
  141. end
  142. fun yyAction13 (strm, lastMatch : yymatch) = let
  143. val yytext = yymktext(strm)
  144. in
  145. yystrm := strm; float yytext
  146. end
  147. fun yyAction14 (strm, lastMatch : yymatch) = (yystrm := strm;
  148. YYBEGIN S; continue() )
  149. fun yyAction15 (strm, lastMatch : yymatch) = (yystrm := strm;
  150. addStr "\\"; continue() )
  151. fun yyAction16 (strm, lastMatch : yymatch) = (yystrm := strm;
  152. addStr "\""; continue() )
  153. fun yyAction17 (strm, lastMatch : yymatch) = (yystrm := strm;
  154. addStr "/"; continue() )
  155. fun yyAction18 (strm, lastMatch : yymatch) = (yystrm := strm;
  156. addStr "\b"; continue() )
  157. fun yyAction19 (strm, lastMatch : yymatch) = (yystrm := strm;
  158. addStr "\f"; continue() )
  159. fun yyAction20 (strm, lastMatch : yymatch) = (yystrm := strm;
  160. addStr "\n"; continue() )
  161. fun yyAction21 (strm, lastMatch : yymatch) = (yystrm := strm;
  162. addStr "\r"; continue() )
  163. fun yyAction22 (strm, lastMatch : yymatch) = (yystrm := strm;
  164. addStr "\t"; continue() )
  165. fun yyAction23 (strm, lastMatch : yymatch) = let
  166. val yytext = yymktext(strm)
  167. in
  168. yystrm := strm; addUChr yytext; continue()
  169. end
  170. fun yyAction24 (strm, lastMatch : yymatch) = let
  171. val yytext = yymktext(strm)
  172. in
  173. yystrm := strm; addStr yytext; continue()
  174. end
  175. fun yyAction25 (strm, lastMatch : yymatch) = (yystrm := strm;
  176. YYBEGIN INITIAL; finishString() )
  177. fun yyAction26 (strm, lastMatch : yymatch) = (yystrm := strm; skip() )
  178. fun yyAction27 (strm, lastMatch : yymatch) = (yystrm := strm; skip() )
  179. fun yyQ33 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  180. of NONE => yyAction2(strm, yyNO_MATCH)
  181. | SOME(inp, strm') => yyAction2(strm, yyNO_MATCH)
  182. (* end case *))
  183. fun yyQ32 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  184. of NONE => yyAction1(strm, yyNO_MATCH)
  185. | SOME(inp, strm') => yyAction1(strm, yyNO_MATCH)
  186. (* end case *))
  187. fun yyQ36 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  188. of NONE => yyAction8(strm, yyNO_MATCH)
  189. | SOME(inp, strm') => yyAction8(strm, yyNO_MATCH)
  190. (* end case *))
  191. fun yyQ35 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  192. of NONE => yystuck(lastMatch)
  193. | SOME(inp, strm') =>
  194. if inp = 0wx65
  195. then yyQ36(strm', lastMatch)
  196. else yystuck(lastMatch)
  197. (* end case *))
  198. fun yyQ34 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  199. of NONE => yystuck(lastMatch)
  200. | SOME(inp, strm') =>
  201. if inp = 0wx75
  202. then yyQ35(strm', lastMatch)
  203. else yystuck(lastMatch)
  204. (* end case *))
  205. fun yyQ31 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  206. of NONE => yyAction27(strm, yyNO_MATCH)
  207. | SOME(inp, strm') =>
  208. if inp = 0wx72
  209. then yyQ34(strm', yyMATCH(strm, yyAction27, yyNO_MATCH))
  210. else yyAction27(strm, yyNO_MATCH)
  211. (* end case *))
  212. fun yyQ39 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  213. of NONE => yyAction7(strm, yyNO_MATCH)
  214. | SOME(inp, strm') => yyAction7(strm, yyNO_MATCH)
  215. (* end case *))
  216. fun yyQ38 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  217. of NONE => yystuck(lastMatch)
  218. | SOME(inp, strm') =>
  219. if inp = 0wx6C
  220. then yyQ39(strm', lastMatch)
  221. else yystuck(lastMatch)
  222. (* end case *))
  223. fun yyQ37 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  224. of NONE => yystuck(lastMatch)
  225. | SOME(inp, strm') =>
  226. if inp = 0wx6C
  227. then yyQ38(strm', lastMatch)
  228. else yystuck(lastMatch)
  229. (* end case *))
  230. fun yyQ30 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  231. of NONE => yyAction27(strm, yyNO_MATCH)
  232. | SOME(inp, strm') =>
  233. if inp = 0wx75
  234. then yyQ37(strm', yyMATCH(strm, yyAction27, yyNO_MATCH))
  235. else yyAction27(strm, yyNO_MATCH)
  236. (* end case *))
  237. fun yyQ43 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  238. of NONE => yyAction9(strm, yyNO_MATCH)
  239. | SOME(inp, strm') => yyAction9(strm, yyNO_MATCH)
  240. (* end case *))
  241. fun yyQ42 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  242. of NONE => yystuck(lastMatch)
  243. | SOME(inp, strm') =>
  244. if inp = 0wx65
  245. then yyQ43(strm', lastMatch)
  246. else yystuck(lastMatch)
  247. (* end case *))
  248. fun yyQ41 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  249. of NONE => yystuck(lastMatch)
  250. | SOME(inp, strm') =>
  251. if inp = 0wx73
  252. then yyQ42(strm', lastMatch)
  253. else yystuck(lastMatch)
  254. (* end case *))
  255. fun yyQ40 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  256. of NONE => yystuck(lastMatch)
  257. | SOME(inp, strm') =>
  258. if inp = 0wx6C
  259. then yyQ41(strm', lastMatch)
  260. else yystuck(lastMatch)
  261. (* end case *))
  262. fun yyQ29 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  263. of NONE => yyAction27(strm, yyNO_MATCH)
  264. | SOME(inp, strm') =>
  265. if inp = 0wx61
  266. then yyQ40(strm', yyMATCH(strm, yyAction27, yyNO_MATCH))
  267. else yyAction27(strm, yyNO_MATCH)
  268. (* end case *))
  269. fun yyQ28 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  270. of NONE => yyAction4(strm, yyNO_MATCH)
  271. | SOME(inp, strm') => yyAction4(strm, yyNO_MATCH)
  272. (* end case *))
  273. fun yyQ27 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  274. of NONE => yyAction3(strm, yyNO_MATCH)
  275. | SOME(inp, strm') => yyAction3(strm, yyNO_MATCH)
  276. (* end case *))
  277. fun yyQ26 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  278. of NONE => yyAction6(strm, yyNO_MATCH)
  279. | SOME(inp, strm') => yyAction6(strm, yyNO_MATCH)
  280. (* end case *))
  281. fun yyQ48 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  282. of NONE => yyAction12(strm, yyNO_MATCH)
  283. | SOME(inp, strm') =>
  284. if inp = 0wx30
  285. then yyQ48(strm', yyMATCH(strm, yyAction12, yyNO_MATCH))
  286. else if inp < 0wx30
  287. then yyAction12(strm, yyNO_MATCH)
  288. else if inp <= 0wx39
  289. then yyQ48(strm', yyMATCH(strm, yyAction12, yyNO_MATCH))
  290. else yyAction12(strm, yyNO_MATCH)
  291. (* end case *))
  292. fun yyQ47 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  293. of NONE => yystuck(lastMatch)
  294. | SOME(inp, strm') =>
  295. if inp = 0wx30
  296. then yyQ48(strm', lastMatch)
  297. else if inp < 0wx30
  298. then yystuck(lastMatch)
  299. else if inp <= 0wx39
  300. then yyQ48(strm', lastMatch)
  301. else yystuck(lastMatch)
  302. (* end case *))
  303. fun yyQ46 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  304. of NONE => yystuck(lastMatch)
  305. | SOME(inp, strm') =>
  306. if inp = 0wx2D
  307. then yyQ47(strm', lastMatch)
  308. else if inp < 0wx2D
  309. then if inp = 0wx2B
  310. then yyQ47(strm', lastMatch)
  311. else yystuck(lastMatch)
  312. else if inp = 0wx30
  313. then yyQ48(strm', lastMatch)
  314. else if inp < 0wx30
  315. then yystuck(lastMatch)
  316. else if inp <= 0wx39
  317. then yyQ48(strm', lastMatch)
  318. else yystuck(lastMatch)
  319. (* end case *))
  320. fun yyQ52 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  321. of NONE => yyAction13(strm, yyNO_MATCH)
  322. | SOME(inp, strm') =>
  323. if inp = 0wx30
  324. then yyQ52(strm', yyMATCH(strm, yyAction13, yyNO_MATCH))
  325. else if inp < 0wx30
  326. then yyAction13(strm, yyNO_MATCH)
  327. else if inp <= 0wx39
  328. then yyQ52(strm', yyMATCH(strm, yyAction13, yyNO_MATCH))
  329. else yyAction13(strm, yyNO_MATCH)
  330. (* end case *))
  331. fun yyQ51 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  332. of NONE => yystuck(lastMatch)
  333. | SOME(inp, strm') =>
  334. if inp = 0wx30
  335. then yyQ52(strm', lastMatch)
  336. else if inp < 0wx30
  337. then yystuck(lastMatch)
  338. else if inp <= 0wx39
  339. then yyQ52(strm', lastMatch)
  340. else yystuck(lastMatch)
  341. (* end case *))
  342. fun yyQ50 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  343. of NONE => yystuck(lastMatch)
  344. | SOME(inp, strm') =>
  345. if inp = 0wx2D
  346. then yyQ51(strm', lastMatch)
  347. else if inp < 0wx2D
  348. then if inp = 0wx2B
  349. then yyQ51(strm', lastMatch)
  350. else yystuck(lastMatch)
  351. else if inp = 0wx30
  352. then yyQ52(strm', lastMatch)
  353. else if inp < 0wx30
  354. then yystuck(lastMatch)
  355. else if inp <= 0wx39
  356. then yyQ52(strm', lastMatch)
  357. else yystuck(lastMatch)
  358. (* end case *))
  359. fun yyQ49 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  360. of NONE => yyAction11(strm, yyNO_MATCH)
  361. | SOME(inp, strm') =>
  362. if inp = 0wx45
  363. then yyQ50(strm', yyMATCH(strm, yyAction11, yyNO_MATCH))
  364. else if inp < 0wx45
  365. then if inp = 0wx30
  366. then yyQ49(strm', yyMATCH(strm, yyAction11, yyNO_MATCH))
  367. else if inp < 0wx30
  368. then yyAction11(strm, yyNO_MATCH)
  369. else if inp <= 0wx39
  370. then yyQ49(strm', yyMATCH(strm, yyAction11, yyNO_MATCH))
  371. else yyAction11(strm, yyNO_MATCH)
  372. else if inp = 0wx65
  373. then yyQ50(strm', yyMATCH(strm, yyAction11, yyNO_MATCH))
  374. else yyAction11(strm, yyNO_MATCH)
  375. (* end case *))
  376. fun yyQ44 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  377. of NONE => yystuck(lastMatch)
  378. | SOME(inp, strm') =>
  379. if inp = 0wx30
  380. then yyQ49(strm', lastMatch)
  381. else if inp < 0wx30
  382. then yystuck(lastMatch)
  383. else if inp <= 0wx39
  384. then yyQ49(strm', lastMatch)
  385. else yystuck(lastMatch)
  386. (* end case *))
  387. fun yyQ45 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  388. of NONE => yyAction10(strm, yyNO_MATCH)
  389. | SOME(inp, strm') =>
  390. if inp = 0wx3A
  391. then yyAction10(strm, yyNO_MATCH)
  392. else if inp < 0wx3A
  393. then if inp = 0wx2F
  394. then yyAction10(strm, yyNO_MATCH)
  395. else if inp < 0wx2F
  396. then if inp = 0wx2E
  397. then yyQ44(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  398. else yyAction10(strm, yyNO_MATCH)
  399. else yyQ45(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  400. else if inp = 0wx46
  401. then yyAction10(strm, yyNO_MATCH)
  402. else if inp < 0wx46
  403. then if inp = 0wx45
  404. then yyQ46(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  405. else yyAction10(strm, yyNO_MATCH)
  406. else if inp = 0wx65
  407. then yyQ46(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  408. else yyAction10(strm, yyNO_MATCH)
  409. (* end case *))
  410. fun yyQ25 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  411. of NONE => yyAction10(strm, yyNO_MATCH)
  412. | SOME(inp, strm') =>
  413. if inp = 0wx3A
  414. then yyAction10(strm, yyNO_MATCH)
  415. else if inp < 0wx3A
  416. then if inp = 0wx2F
  417. then yyAction10(strm, yyNO_MATCH)
  418. else if inp < 0wx2F
  419. then if inp = 0wx2E
  420. then yyQ44(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  421. else yyAction10(strm, yyNO_MATCH)
  422. else yyQ45(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  423. else if inp = 0wx46
  424. then yyAction10(strm, yyNO_MATCH)
  425. else if inp < 0wx46
  426. then if inp = 0wx45
  427. then yyQ46(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  428. else yyAction10(strm, yyNO_MATCH)
  429. else if inp = 0wx65
  430. then yyQ46(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  431. else yyAction10(strm, yyNO_MATCH)
  432. (* end case *))
  433. fun yyQ24 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  434. of NONE => yyAction10(strm, yyNO_MATCH)
  435. | SOME(inp, strm') =>
  436. if inp = 0wx45
  437. then yyQ46(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  438. else if inp < 0wx45
  439. then if inp = 0wx2E
  440. then yyQ44(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  441. else yyAction10(strm, yyNO_MATCH)
  442. else if inp = 0wx65
  443. then yyQ46(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  444. else yyAction10(strm, yyNO_MATCH)
  445. (* end case *))
  446. fun yyQ57 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  447. of NONE => yystuck(lastMatch)
  448. | SOME(inp, strm') =>
  449. if inp = 0wx2A
  450. then yyQ57(strm', lastMatch)
  451. else yyQ56(strm', lastMatch)
  452. (* end case *))
  453. and yyQ56 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  454. of NONE => yystuck(lastMatch)
  455. | SOME(inp, strm') =>
  456. if inp = 0wx2A
  457. then yyQ57(strm', lastMatch)
  458. else yyQ56(strm', lastMatch)
  459. (* end case *))
  460. fun yyQ55 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  461. of NONE => yyAction26(strm, yyNO_MATCH)
  462. | SOME(inp, strm') =>
  463. if inp = 0wx2A
  464. then yyQ57(strm', yyMATCH(strm, yyAction26, yyNO_MATCH))
  465. else yyQ56(strm', yyMATCH(strm, yyAction26, yyNO_MATCH))
  466. (* end case *))
  467. fun yyQ53 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  468. of NONE => yystuck(lastMatch)
  469. | SOME(inp, strm') =>
  470. if inp = 0wx2A
  471. then yyQ54(strm', lastMatch)
  472. else yyQ53(strm', lastMatch)
  473. (* end case *))
  474. and yyQ54 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  475. of NONE => yystuck(lastMatch)
  476. | SOME(inp, strm') =>
  477. if inp = 0wx2B
  478. then yyQ53(strm', lastMatch)
  479. else if inp < 0wx2B
  480. then if inp = 0wx2A
  481. then yyQ54(strm', lastMatch)
  482. else yyQ53(strm', lastMatch)
  483. else if inp = 0wx2F
  484. then yyQ55(strm', lastMatch)
  485. else yyQ53(strm', lastMatch)
  486. (* end case *))
  487. fun yyQ23 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  488. of NONE => yyAction27(strm, yyNO_MATCH)
  489. | SOME(inp, strm') =>
  490. if inp = 0wx2A
  491. then yyQ53(strm', yyMATCH(strm, yyAction27, yyNO_MATCH))
  492. else yyAction27(strm, yyNO_MATCH)
  493. (* end case *))
  494. fun yyQ59 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  495. of NONE => yyAction10(strm, yyNO_MATCH)
  496. | SOME(inp, strm') =>
  497. if inp = 0wx3A
  498. then yyAction10(strm, yyNO_MATCH)
  499. else if inp < 0wx3A
  500. then if inp = 0wx2F
  501. then yyAction10(strm, yyNO_MATCH)
  502. else if inp < 0wx2F
  503. then if inp = 0wx2E
  504. then yyQ44(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  505. else yyAction10(strm, yyNO_MATCH)
  506. else yyQ45(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  507. else if inp = 0wx46
  508. then yyAction10(strm, yyNO_MATCH)
  509. else if inp < 0wx46
  510. then if inp = 0wx45
  511. then yyQ46(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  512. else yyAction10(strm, yyNO_MATCH)
  513. else if inp = 0wx65
  514. then yyQ46(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  515. else yyAction10(strm, yyNO_MATCH)
  516. (* end case *))
  517. fun yyQ58 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  518. of NONE => yyAction10(strm, yyNO_MATCH)
  519. | SOME(inp, strm') =>
  520. if inp = 0wx45
  521. then yyQ46(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  522. else if inp < 0wx45
  523. then if inp = 0wx2E
  524. then yyQ44(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  525. else yyAction10(strm, yyNO_MATCH)
  526. else if inp = 0wx65
  527. then yyQ46(strm', yyMATCH(strm, yyAction10, yyNO_MATCH))
  528. else yyAction10(strm, yyNO_MATCH)
  529. (* end case *))
  530. fun yyQ22 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  531. of NONE => yyAction27(strm, yyNO_MATCH)
  532. | SOME(inp, strm') =>
  533. if inp = 0wx31
  534. then yyQ59(strm', yyMATCH(strm, yyAction27, yyNO_MATCH))
  535. else if inp < 0wx31
  536. then if inp = 0wx30
  537. then yyQ58(strm', yyMATCH(strm, yyAction27, yyNO_MATCH))
  538. else yyAction27(strm, yyNO_MATCH)
  539. else if inp <= 0wx39
  540. then yyQ59(strm', yyMATCH(strm, yyAction27, yyNO_MATCH))
  541. else yyAction27(strm, yyNO_MATCH)
  542. (* end case *))
  543. fun yyQ21 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  544. of NONE => yyAction5(strm, yyNO_MATCH)
  545. | SOME(inp, strm') => yyAction5(strm, yyNO_MATCH)
  546. (* end case *))
  547. fun yyQ20 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  548. of NONE => yyAction14(strm, yyNO_MATCH)
  549. | SOME(inp, strm') => yyAction14(strm, yyNO_MATCH)
  550. (* end case *))
  551. fun yyQ60 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  552. of NONE => yyAction0(strm, yyNO_MATCH)
  553. | SOME(inp, strm') =>
  554. if inp = 0wxD
  555. then yyQ60(strm', yyMATCH(strm, yyAction0, yyNO_MATCH))
  556. else if inp < 0wxD
  557. then if inp = 0wx9
  558. then yyQ60(strm', yyMATCH(strm, yyAction0, yyNO_MATCH))
  559. else if inp < 0wx9
  560. then yyAction0(strm, yyNO_MATCH)
  561. else if inp <= 0wxA
  562. then yyQ60(strm', yyMATCH(strm, yyAction0, yyNO_MATCH))
  563. else yyAction0(strm, yyNO_MATCH)
  564. else if inp = 0wx20
  565. then yyQ60(strm', yyMATCH(strm, yyAction0, yyNO_MATCH))
  566. else yyAction0(strm, yyNO_MATCH)
  567. (* end case *))
  568. fun yyQ19 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  569. of NONE => yyAction0(strm, yyNO_MATCH)
  570. | SOME(inp, strm') =>
  571. if inp = 0wxD
  572. then yyQ60(strm', yyMATCH(strm, yyAction0, yyNO_MATCH))
  573. else if inp < 0wxD
  574. then if inp = 0wx9
  575. then yyQ60(strm', yyMATCH(strm, yyAction0, yyNO_MATCH))
  576. else if inp < 0wx9
  577. then yyAction0(strm, yyNO_MATCH)
  578. else if inp <= 0wxA
  579. then yyQ60(strm', yyMATCH(strm, yyAction0, yyNO_MATCH))
  580. else yyAction0(strm, yyNO_MATCH)
  581. else if inp = 0wx20
  582. then yyQ60(strm', yyMATCH(strm, yyAction0, yyNO_MATCH))
  583. else yyAction0(strm, yyNO_MATCH)
  584. (* end case *))
  585. fun yyQ18 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  586. of NONE => yyAction27(strm, yyNO_MATCH)
  587. | SOME(inp, strm') => yyAction27(strm, yyNO_MATCH)
  588. (* end case *))
  589. fun yyQ1 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  590. of NONE =>
  591. if ULexBuffer.eof(!(yystrm))
  592. then let
  593. val yycolno = ref(yygetcolNo(!(yystrm)))
  594. val yylineno = ref(yygetlineNo(!(yystrm)))
  595. in
  596. (case (!(yyss))
  597. of _ => (UserDeclarations.eof())
  598. (* end case *))
  599. end
  600. else yystuck(lastMatch)
  601. | SOME(inp, strm') =>
  602. if inp = 0wx3A
  603. then yyQ26(strm', lastMatch)
  604. else if inp < 0wx3A
  605. then if inp = 0wx22
  606. then yyQ20(strm', lastMatch)
  607. else if inp < 0wx22
  608. then if inp = 0wxD
  609. then yyQ19(strm', lastMatch)
  610. else if inp < 0wxD
  611. then if inp = 0wx9
  612. then yyQ19(strm', lastMatch)
  613. else if inp < 0wx9
  614. then yyQ18(strm', lastMatch)
  615. else if inp <= 0wxA
  616. then yyQ19(strm', lastMatch)
  617. else yyQ18(strm', lastMatch)
  618. else if inp = 0wx20
  619. then yyQ19(strm', lastMatch)
  620. else yyQ18(strm', lastMatch)
  621. else if inp = 0wx2E
  622. then yyQ18(strm', lastMatch)
  623. else if inp < 0wx2E
  624. then if inp = 0wx2C
  625. then yyQ21(strm', lastMatch)
  626. else if inp = 0wx2D
  627. then yyQ22(strm', lastMatch)
  628. else yyQ18(strm', lastMatch)
  629. else if inp = 0wx30
  630. then yyQ24(strm', lastMatch)
  631. else if inp = 0wx2F
  632. then yyQ23(strm', lastMatch)
  633. else yyQ25(strm', lastMatch)
  634. else if inp = 0wx6E
  635. then yyQ30(strm', lastMatch)
  636. else if inp < 0wx6E
  637. then if inp = 0wx5D
  638. then yyQ28(strm', lastMatch)
  639. else if inp < 0wx5D
  640. then if inp = 0wx5B
  641. then yyQ27(strm', lastMatch)
  642. else yyQ18(strm', lastMatch)
  643. else if inp = 0wx66
  644. then yyQ29(strm', lastMatch)
  645. else yyQ18(strm', lastMatch)
  646. else if inp = 0wx7B
  647. then yyQ32(strm', lastMatch)
  648. else if inp < 0wx7B
  649. then if inp = 0wx74
  650. then yyQ31(strm', lastMatch)
  651. else yyQ18(strm', lastMatch)
  652. else if inp = 0wx7D
  653. then yyQ33(strm', lastMatch)
  654. else yyQ18(strm', lastMatch)
  655. (* end case *))
  656. fun yyQ17 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  657. of NONE => yyAction23(strm, yyNO_MATCH)
  658. | SOME(inp, strm') => yyAction23(strm, yyNO_MATCH)
  659. (* end case *))
  660. fun yyQ16 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  661. of NONE => yystuck(lastMatch)
  662. | SOME(inp, strm') =>
  663. if inp = 0wx41
  664. then yyQ17(strm', lastMatch)
  665. else if inp < 0wx41
  666. then if inp = 0wx30
  667. then yyQ17(strm', lastMatch)
  668. else if inp < 0wx30
  669. then yystuck(lastMatch)
  670. else if inp <= 0wx39
  671. then yyQ17(strm', lastMatch)
  672. else yystuck(lastMatch)
  673. else if inp = 0wx61
  674. then yyQ17(strm', lastMatch)
  675. else if inp < 0wx61
  676. then if inp <= 0wx46
  677. then yyQ17(strm', lastMatch)
  678. else yystuck(lastMatch)
  679. else if inp <= 0wx66
  680. then yyQ17(strm', lastMatch)
  681. else yystuck(lastMatch)
  682. (* end case *))
  683. fun yyQ15 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  684. of NONE => yystuck(lastMatch)
  685. | SOME(inp, strm') =>
  686. if inp = 0wx41
  687. then yyQ16(strm', lastMatch)
  688. else if inp < 0wx41
  689. then if inp = 0wx30
  690. then yyQ16(strm', lastMatch)
  691. else if inp < 0wx30
  692. then yystuck(lastMatch)
  693. else if inp <= 0wx39
  694. then yyQ16(strm', lastMatch)
  695. else yystuck(lastMatch)
  696. else if inp = 0wx61
  697. then yyQ16(strm', lastMatch)
  698. else if inp < 0wx61
  699. then if inp <= 0wx46
  700. then yyQ16(strm', lastMatch)
  701. else yystuck(lastMatch)
  702. else if inp <= 0wx66
  703. then yyQ16(strm', lastMatch)
  704. else yystuck(lastMatch)
  705. (* end case *))
  706. fun yyQ14 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  707. of NONE => yystuck(lastMatch)
  708. | SOME(inp, strm') =>
  709. if inp = 0wx41
  710. then yyQ15(strm', lastMatch)
  711. else if inp < 0wx41
  712. then if inp = 0wx30
  713. then yyQ15(strm', lastMatch)
  714. else if inp < 0wx30
  715. then yystuck(lastMatch)
  716. else if inp <= 0wx39
  717. then yyQ15(strm', lastMatch)
  718. else yystuck(lastMatch)
  719. else if inp = 0wx61
  720. then yyQ15(strm', lastMatch)
  721. else if inp < 0wx61
  722. then if inp <= 0wx46
  723. then yyQ15(strm', lastMatch)
  724. else yystuck(lastMatch)
  725. else if inp <= 0wx66
  726. then yyQ15(strm', lastMatch)
  727. else yystuck(lastMatch)
  728. (* end case *))
  729. fun yyQ13 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  730. of NONE => yystuck(lastMatch)
  731. | SOME(inp, strm') =>
  732. if inp = 0wx41
  733. then yyQ14(strm', lastMatch)
  734. else if inp < 0wx41
  735. then if inp = 0wx30
  736. then yyQ14(strm', lastMatch)
  737. else if inp < 0wx30
  738. then yystuck(lastMatch)
  739. else if inp <= 0wx39
  740. then yyQ14(strm', lastMatch)
  741. else yystuck(lastMatch)
  742. else if inp = 0wx61
  743. then yyQ14(strm', lastMatch)
  744. else if inp < 0wx61
  745. then if inp <= 0wx46
  746. then yyQ14(strm', lastMatch)
  747. else yystuck(lastMatch)
  748. else if inp <= 0wx66
  749. then yyQ14(strm', lastMatch)
  750. else yystuck(lastMatch)
  751. (* end case *))
  752. fun yyQ12 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  753. of NONE => yyAction22(strm, yyNO_MATCH)
  754. | SOME(inp, strm') => yyAction22(strm, yyNO_MATCH)
  755. (* end case *))
  756. fun yyQ11 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  757. of NONE => yyAction21(strm, yyNO_MATCH)
  758. | SOME(inp, strm') => yyAction21(strm, yyNO_MATCH)
  759. (* end case *))
  760. fun yyQ10 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  761. of NONE => yyAction20(strm, yyNO_MATCH)
  762. | SOME(inp, strm') => yyAction20(strm, yyNO_MATCH)
  763. (* end case *))
  764. fun yyQ9 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  765. of NONE => yyAction19(strm, yyNO_MATCH)
  766. | SOME(inp, strm') => yyAction19(strm, yyNO_MATCH)
  767. (* end case *))
  768. fun yyQ8 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  769. of NONE => yyAction18(strm, yyNO_MATCH)
  770. | SOME(inp, strm') => yyAction18(strm, yyNO_MATCH)
  771. (* end case *))
  772. fun yyQ7 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  773. of NONE => yyAction15(strm, yyNO_MATCH)
  774. | SOME(inp, strm') => yyAction15(strm, yyNO_MATCH)
  775. (* end case *))
  776. fun yyQ6 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  777. of NONE => yyAction17(strm, yyNO_MATCH)
  778. | SOME(inp, strm') => yyAction17(strm, yyNO_MATCH)
  779. (* end case *))
  780. fun yyQ5 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  781. of NONE => yyAction16(strm, yyNO_MATCH)
  782. | SOME(inp, strm') => yyAction16(strm, yyNO_MATCH)
  783. (* end case *))
  784. fun yyQ4 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  785. of NONE => yystuck(lastMatch)
  786. | SOME(inp, strm') =>
  787. if inp = 0wx66
  788. then yyQ9(strm', lastMatch)
  789. else if inp < 0wx66
  790. then if inp = 0wx30
  791. then yystuck(lastMatch)
  792. else if inp < 0wx30
  793. then if inp = 0wx23
  794. then yystuck(lastMatch)
  795. else if inp < 0wx23
  796. then if inp = 0wx22
  797. then yyQ5(strm', lastMatch)
  798. else yystuck(lastMatch)
  799. else if inp = 0wx2F
  800. then yyQ6(strm', lastMatch)
  801. else yystuck(lastMatch)
  802. else if inp = 0wx5D
  803. then yystuck(lastMatch)
  804. else if inp < 0wx5D
  805. then if inp = 0wx5C
  806. then yyQ7(strm', lastMatch)
  807. else yystuck(lastMatch)
  808. else if inp = 0wx62
  809. then yyQ8(strm', lastMatch)
  810. else yystuck(lastMatch)
  811. else if inp = 0wx73
  812. then yystuck(lastMatch)
  813. else if inp < 0wx73
  814. then if inp = 0wx6F
  815. then yystuck(lastMatch)
  816. else if inp < 0wx6F
  817. then if inp = 0wx6E
  818. then yyQ10(strm', lastMatch)
  819. else yystuck(lastMatch)
  820. else if inp = 0wx72
  821. then yyQ11(strm', lastMatch)
  822. else yystuck(lastMatch)
  823. else if inp = 0wx75
  824. then yyQ13(strm', lastMatch)
  825. else if inp = 0wx74
  826. then yyQ12(strm', lastMatch)
  827. else yystuck(lastMatch)
  828. (* end case *))
  829. fun yyQ3 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  830. of NONE => yyAction25(strm, yyNO_MATCH)
  831. | SOME(inp, strm') => yyAction25(strm, yyNO_MATCH)
  832. (* end case *))
  833. fun yyQ2 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  834. of NONE => yyAction24(strm, yyNO_MATCH)
  835. | SOME(inp, strm') =>
  836. if inp = 0wx23
  837. then yyQ2(strm', yyMATCH(strm, yyAction24, yyNO_MATCH))
  838. else if inp < 0wx23
  839. then if inp = 0wx22
  840. then yyAction24(strm, yyNO_MATCH)
  841. else yyQ2(strm', yyMATCH(strm, yyAction24, yyNO_MATCH))
  842. else if inp = 0wx5C
  843. then yyAction24(strm, yyNO_MATCH)
  844. else yyQ2(strm', yyMATCH(strm, yyAction24, yyNO_MATCH))
  845. (* end case *))
  846. fun yyQ0 (strm, lastMatch : yymatch) = (case (yygetc(strm))
  847. of NONE =>
  848. if ULexBuffer.eof(!(yystrm))
  849. then let
  850. val yycolno = ref(yygetcolNo(!(yystrm)))
  851. val yylineno = ref(yygetlineNo(!(yystrm)))
  852. in
  853. (case (!(yyss))
  854. of _ => (UserDeclarations.eof())
  855. (* end case *))
  856. end
  857. else yystuck(lastMatch)
  858. | SOME(inp, strm') =>
  859. if inp = 0wx23
  860. then yyQ2(strm', lastMatch)
  861. else if inp < 0wx23
  862. then if inp = 0wx22
  863. then yyQ3(strm', lastMatch)
  864. else yyQ2(strm', lastMatch)
  865. else if inp = 0wx5C
  866. then yyQ4(strm', lastMatch)
  867. else yyQ2(strm', lastMatch)
  868. (* end case *))
  869. in
  870. (case (!(yyss))
  871. of S => yyQ0(!(yystrm), yyNO_MATCH)
  872. | INITIAL => yyQ1(!(yystrm), yyNO_MATCH)
  873. (* end case *))
  874. end
  875. end
  876. and skip() = (yystartPos := yygetPos();
  877. yylastwasnref := ULexBuffer.lastWasNL (!yystrm);
  878. continue())
  879. in (continue(), (!yystartPos, yygetPos()), !yystrm, !yyss) end
  880. in
  881. lex()
  882. end
  883. in
  884. type pos = AntlrStreamPos.pos
  885. type span = AntlrStreamPos.span
  886. type tok = UserDeclarations.lex_result
  887. datatype prestrm = STRM of ULexBuffer.stream *
  888. (yystart_state * tok * span * prestrm * yystart_state) option ref
  889. type strm = (prestrm * yystart_state)
  890. fun lex sm
  891. (STRM (yystrm, memo), ss) = (case !memo
  892. of NONE => let
  893. val (tok, span, yystrm', ss') = innerLex
  894. (yystrm, ss, sm)
  895. val strm' = STRM (yystrm', ref NONE);
  896. in
  897. memo := SOME (ss, tok, span, strm', ss');
  898. (tok, span, (strm', ss'))
  899. end
  900. | SOME (ss', tok, span, strm', ss'') =>
  901. if ss = ss' then
  902. (tok, span, (strm', ss''))
  903. else (
  904. memo := NONE;
  905. lex sm
  906. (STRM (yystrm, memo), ss))
  907. (* end case *))
  908. fun streamify input = (STRM (yystreamify' 0 input, ref NONE), INITIAL)
  909. fun streamifyReader readFn strm = (STRM (yystreamifyReader' 0 readFn strm, ref NONE),
  910. INITIAL)
  911. fun streamifyInstream strm = (STRM (yystreamifyInstream' 0 strm, ref NONE),
  912. INITIAL)
  913. fun getPos (STRM (strm, _), _) = ULexBuffer.getpos strm
  914. end
  915. end