exhaustive.nim 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. discard """
  2. outputsub: '''ObjectAssignmentError'''
  3. exitcode: "1"
  4. """
  5. import verylongnamehere, verylongnamehere,
  6. verylongnamehereverylongnamehereverylong, namehere, verylongnamehere
  7. proc `[]=`() = discard "index setter"
  8. proc `putter=`() = discard cast[pointer](cast[int](buffer) + size)
  9. (not false)
  10. let expr = if true: "true" else: "false"
  11. var body = newNimNode(nnkIfExpr).add(
  12. newNimNode(nnkElifBranch).add(
  13. infix(newDotExpr(ident("a"), ident("kind")), "==", newDotExpr(ident("b"),
  14. ident("kind"))),
  15. condition
  16. ),
  17. newNimNode(nnkElse).add(newStmtList(newNimNode(nnkReturnStmt).add(ident(
  18. "false"))))
  19. )
  20. # comment
  21. var x = 1
  22. type
  23. GeneralTokenizer* = object of RootObj ## comment here
  24. kind*: TokenClass ## and here
  25. start*, length*: int ## you know how it goes...
  26. buf: cstring
  27. pos: int # other comment here.
  28. state: TokenClass
  29. var x*: string
  30. var y: seq[string] #[ yay inline comments. So nice I have to care bout these. ]#
  31. echo "#", x, "##", y, "#" & "string" & $test
  32. echo (tup, here)
  33. echo(argA, argB)
  34. import macros
  35. ## A documentation comment here.
  36. ## That spans multiple lines.
  37. ## And is not to be touched.
  38. const numbers = [4u8, 5'u16, 89898_00]
  39. macro m(n): untyped =
  40. result = foo"string literal"
  41. {.push m.}
  42. proc p() = echo "p", 1+4 * 5, if true: 5 else: 6
  43. proc q(param: var ref ptr string) =
  44. p()
  45. if true:
  46. echo a and b or not c and not -d
  47. {.pop.}
  48. q()
  49. when false:
  50. # bug #4766
  51. type
  52. Plain = ref object
  53. discard
  54. Wrapped[T] = object
  55. value: T
  56. converter toWrapped[T](value: T): Wrapped[T] =
  57. Wrapped[T](value: value)
  58. let result = Plain()
  59. discard $result
  60. when false:
  61. # bug #3670
  62. template someTempl(someConst: bool) =
  63. when someConst:
  64. var a: int
  65. if true:
  66. when not someConst:
  67. var a: int
  68. a = 5
  69. someTempl(true)
  70. #
  71. #
  72. # The Nim Compiler
  73. # (c) Copyright 2018 Andreas Rumpf
  74. #
  75. # See the file "copying.txt", included in this
  76. # distribution, for details about the copyright.
  77. #
  78. ## Layouter for nimpretty. Still primitive but useful.
  79. import idents, lexer, lineinfos, llstream, options, msgs, strutils
  80. from os import changeFileExt
  81. const
  82. MaxLineLen = 80
  83. LineCommentColumn = 30
  84. type
  85. SplitKind = enum
  86. splitComma, splitParLe, splitAnd, splitOr, splitIn, splitBinary
  87. Emitter* = object
  88. f: PLLStream
  89. config: ConfigRef
  90. fid: FileIndex
  91. lastTok: TTokType
  92. inquote {.pragmaHereWrongCurlyEnd.}: bool
  93. col, lastLineNumber, lineSpan, indentLevel: int
  94. content: string
  95. fixedUntil: int # marks where we must not go in the content
  96. altSplitPos: array[SplitKind, int] # alternative split positions
  97. proc openEmitter*[T, S](em: var Emitter; config: ConfigRef;
  98. fileIdx: FileIndex) {.pragmaHereWrongCurlyEnd.} =
  99. let outfile = changeFileExt(config.toFullPath(fileIdx), ".pretty.nim")
  100. em.f = llStreamOpen(outfile, fmWrite)
  101. em.config = config
  102. em.fid = fileIdx
  103. em.lastTok = tkInvalid
  104. em.inquote = false
  105. em.col = 0
  106. em.content = newStringOfCap(16_000)
  107. if em.f == nil:
  108. rawMessage(config, errGenerated, "cannot open file: " & outfile)
  109. proc closeEmitter*(em: var Emitter) {.inline.} =
  110. em.f.llStreamWrite em.content
  111. llStreamClose(em.f)
  112. proc countNewlines(s: string): int =
  113. result = 0
  114. for i in 0..<s.len:
  115. if s[i+1] == '\L': inc result
  116. proc calcCol(em: var Emitter; s: string) =
  117. var i = s.len-1
  118. em.col = 0
  119. while i >= 0 and s[i] != '\L':
  120. dec i
  121. inc em.col
  122. template wr(x) =
  123. em.content.add x
  124. inc em.col, x.len
  125. template goodCol(col): bool = col in 40..MaxLineLen
  126. const splitters = {tkComma, tkSemicolon, tkParLe, tkParDotLe,
  127. tkBracketLe, tkBracketLeColon, tkCurlyDotLe,
  128. tkCurlyLe}
  129. template rememberSplit(kind) =
  130. if goodCol(em.col):
  131. em.altSplitPos[kind] = em.content.len
  132. proc softLinebreak(em: var Emitter; lit: string) =
  133. # XXX Use an algorithm that is outlined here:
  134. # https://llvm.org/devmtg/2013-04/jasper-slides.pdf
  135. # +2 because we blindly assume a comma or ' &' might follow
  136. if not em.inquote and em.col+lit.len+2 >= MaxLineLen:
  137. if em.lastTok in splitters:
  138. wr("\L")
  139. em.col = 0
  140. for i in 1..em.indentLevel+2: wr(" ")
  141. else:
  142. # search backwards for a good split position:
  143. for a in em.altSplitPos:
  144. if a > em.fixedUntil:
  145. let ws = "\L" & repeat(' ', em.indentLevel+2)
  146. em.col = em.content.len - a
  147. em.content.insert(ws, a)
  148. break
  149. proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
  150. template endsInWhite(em): bool =
  151. em.content.len > 0 and em.content[em.content.high] in {' ', '\L'}
  152. template endsInAlpha(em): bool =
  153. em.content.len > 0 and em.content[em.content.high] in SymChars+{'_'}
  154. proc emitComment(em: var Emitter; tok: TToken) =
  155. let lit = strip fileSection(em.config, em.fid, tok.commentOffsetA,
  156. tok.commentOffsetB)
  157. em.lineSpan = countNewlines(lit)
  158. if em.lineSpan > 0: calcCol(em, lit)
  159. if not endsInWhite(em):
  160. wr(" ")
  161. if em.lineSpan == 0 and max(em.col, LineCommentColumn) + lit.len <= MaxLineLen:
  162. for i in 1 .. LineCommentColumn - em.col: wr(" ")
  163. wr lit
  164. var preventComment = case tok.tokType
  165. of tokKeywordLow..tokKeywordHigh:
  166. if endsInAlpha(em): wr(" ")
  167. wr(TokTypeToStr[tok.tokType])
  168. case tok.tokType
  169. of tkAnd: rememberSplit(splitAnd)
  170. of tkOr: rememberSplit(splitOr)
  171. of tkIn: rememberSplit(splitIn)
  172. else: 90
  173. else:
  174. "case returns value"
  175. if tok.tokType == tkComment and tok.line == em.lastLineNumber and
  176. tok.indent >= 0:
  177. # we have an inline comment so handle it before the indentation token:
  178. emitComment(em, tok)
  179. preventComment = true
  180. em.fixedUntil = em.content.high
  181. elif tok.indent >= 0:
  182. em.indentLevel = tok.indent
  183. # remove trailing whitespace:
  184. while em.content.len > 0 and em.content[em.content.high] == ' ':
  185. setLen(em.content, em.content.len-1)
  186. wr("\L")
  187. for i in 2..tok.line - em.lastLineNumber: wr("\L")
  188. em.col = 0
  189. for i in 1..tok.indent:
  190. wr(" ")
  191. em.fixedUntil = em.content.high
  192. case tok.tokType
  193. of tokKeywordLow..tokKeywordHigh:
  194. if endsInAlpha(em): wr(" ")
  195. wr(TokTypeToStr[tok.tokType])
  196. case tok.tokType
  197. of tkAnd: rememberSplit(splitAnd)
  198. of tkOr: rememberSplit(splitOr)
  199. of tkIn: rememberSplit(splitIn)
  200. else: discard
  201. of tkColon:
  202. wr(TokTypeToStr[tok.tokType])
  203. wr(" ")
  204. of tkSemicolon,
  205. tkComma:
  206. wr(TokTypeToStr[tok.tokType])
  207. wr(" ")
  208. rememberSplit(splitComma)
  209. of tkParLe, tkParRi, tkBracketLe,
  210. tkBracketRi, tkCurlyLe, tkCurlyRi,
  211. tkBracketDotLe, tkBracketDotRi,
  212. tkCurlyDotLe, tkCurlyDotRi,
  213. tkParDotLe, tkParDotRi,
  214. tkColonColon, tkDot, tkBracketLeColon:
  215. wr(TokTypeToStr[tok.tokType])
  216. if tok.tokType in splitters:
  217. rememberSplit(splitParLe)
  218. of tkEquals:
  219. if not em.endsInWhite: wr(" ")
  220. wr(TokTypeToStr[tok.tokType])
  221. wr(" ")
  222. of tkOpr, tkDotDot:
  223. if not em.endsInWhite: wr(" ")
  224. wr(tok.ident.s)
  225. template isUnary(tok): bool =
  226. tok.strongSpaceB == 0 and tok.strongSpaceA > 0
  227. if not isUnary(tok) or em.lastTok in {tkOpr, tkDotDot}:
  228. wr(" ")
  229. rememberSplit(splitBinary)
  230. of tkAccent:
  231. wr(TokTypeToStr[tok.tokType])
  232. em.inquote = not em.inquote
  233. of tkComment:
  234. if not preventComment:
  235. emitComment(em, tok)
  236. of tkIntLit..tkStrLit, tkRStrLit, tkTripleStrLit, tkGStrLit, tkGTripleStrLit, tkCharLit:
  237. let lit = fileSection(em.config, em.fid, tok.offsetA, tok.offsetB)
  238. softLinebreak(em, lit)
  239. if endsInAlpha(em) and tok.tokType notin {tkGStrLit, tkGTripleStrLit}: wr(" ")
  240. em.lineSpan = countNewlines(lit)
  241. if em.lineSpan > 0: calcCol(em, lit)
  242. wr lit
  243. of tkEof: discard
  244. else:
  245. let lit = if tok.ident != nil: tok.ident.s else: tok.literal
  246. softLinebreak(em, lit)
  247. if endsInAlpha(em): wr(" ")
  248. wr lit
  249. em.lastTok = tok.tokType
  250. em.lastLineNumber = tok.line + em.lineSpan
  251. em.lineSpan = 0
  252. proc starWasExportMarker*(em: var Emitter) =
  253. if em.content.endsWith(" * "):
  254. setLen(em.content, em.content.len-3)
  255. em.content.add("*")
  256. dec em.col, 2
  257. type
  258. Thing = ref object
  259. grade: string
  260. # this name is great
  261. name: string
  262. proc f() =
  263. var c: char
  264. var str: string
  265. if c == '\\':
  266. # escape char
  267. str &= c
  268. proc getKeyAndData(cursor: int; op: int):
  269. tuple[key, data: string; success: bool] {.noInit.} =
  270. var keyVal: string
  271. var dataVal: string
  272. #!nimpretty off
  273. when stuff:
  274. echo "so nice"
  275. echo "more"
  276. else:
  277. echo "misaligned"
  278. #!nimpretty on
  279. const test = r"C:\Users\-\Desktop\test.txt"
  280. proc abcdef*[T: not (tuple|object|string|cstring|char|ref|ptr|array|seq|distinct)]() =
  281. # bug #9504
  282. type T2 = a.type
  283. discard
  284. proc fun() =
  285. #[
  286. this one here
  287. ]#
  288. discard
  289. proc fun2() =
  290. ##[
  291. foobar
  292. ]##
  293. discard
  294. #[
  295. foobar
  296. ]#
  297. proc fun3() =
  298. discard
  299. ##[
  300. foobar
  301. ]##
  302. # bug #9673
  303. discard `*`(1, 2)
  304. proc fun4() =
  305. var a = "asdf"
  306. var i = 0
  307. while i < a.len and i < a.len:
  308. return
  309. # bug #10295
  310. import osproc
  311. let res = execProcess(
  312. "echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates")
  313. let res = execProcess("echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates")
  314. # bug #10177
  315. proc foo*() =
  316. discard
  317. proc foo*[T]() =
  318. discard
  319. # bug #10159
  320. proc fun() =
  321. discard
  322. proc main() =
  323. echo "foo"; echo "bar";
  324. discard
  325. main()
  326. type
  327. TCallingConvention* = enum
  328. ccDefault, # proc has no explicit calling convention
  329. ccStdCall, # procedure is stdcall
  330. ccCDecl, # cdecl
  331. ccSafeCall, # safecall
  332. ccSysCall, # system call
  333. ccInline, # proc should be inlined
  334. ccNoInline, # proc should not be inlined
  335. ccFastCall, # fastcall (pass parameters in registers)
  336. ccClosure, # proc has a closure
  337. ccNoConvention # needed for generating proper C procs sometimes
  338. proc isValid1*[A](s: HashSet[A]): bool {.deprecated:
  339. "Deprecated since v0.20; sets are initialized by default".} =
  340. ## Returns `true` if the set has been initialized (with `initHashSet proc
  341. ## <#initHashSet,int>`_ or `init proc <#init,HashSet[A],int>`_).
  342. result = s.data.len > 0
  343. # bug #11468
  344. assert $type(a) == "Option[system.int]"
  345. foo(a, $type(b), c)
  346. foo(type(b), c) # this is ok
  347. proc `<`*[A](s, t: A): bool = discard
  348. proc `==`*[A](s, t: HashSet[A]): bool = discard
  349. proc `<=`*[A](s, t: HashSet[A]): bool = discard
  350. # these are ok:
  351. proc `$`*[A](s: HashSet[A]): string = discard
  352. proc `*`*[A](s1, s2: HashSet[A]): HashSet[A] {.inline.} = discard
  353. proc `-+-`*[A](s1, s2: HashSet[A]): HashSet[A] {.inline.} = discard
  354. # bug #11470
  355. # bug #11467
  356. type
  357. FirstEnum = enum ## doc comment here
  358. first, ## this is first
  359. second, ## second doc
  360. third, ## third one
  361. fourth ## the last one
  362. type
  363. SecondEnum = enum ## doc comment here
  364. first, ## this is first
  365. second, ## second doc
  366. third, ## third one
  367. fourth, ## the last one
  368. type
  369. ThirdEnum = enum ## doc comment here
  370. first ## this is first
  371. second ## second doc
  372. third ## third one
  373. fourth ## the last one
  374. type
  375. HttpMethod* = enum ## the requested HttpMethod
  376. HttpHead, ## Asks for the response identical to the one that would
  377. ## correspond to a GET request, but without the response
  378. ## body.
  379. HttpGet, ## Retrieves the specified resource.
  380. HttpPost, ## Submits data to be processed to the identified
  381. ## resource. The data is included in the body of the
  382. ## request.
  383. HttpPut, ## Uploads a representation of the specified resource.
  384. HttpDelete, ## Deletes the specified resource.
  385. HttpTrace, ## Echoes back the received request, so that a client
  386. ## can see what intermediate servers are adding or
  387. ## changing in the request.
  388. HttpOptions, ## Returns the HTTP methods that the server supports
  389. ## for specified address.
  390. HttpConnect, ## Converts the request connection to a transparent
  391. ## TCP/IP tunnel, usually used for proxies.
  392. HttpPatch ## Applies partial modifications to a resource.
  393. type
  394. HtmlTag* = enum ## list of all supported HTML tags; order will always be
  395. ## alphabetically
  396. tagUnknown, ## unknown HTML element
  397. tagA, ## the HTML ``a`` element
  398. tagAbbr, ## the deprecated HTML ``abbr`` element
  399. tagAcronym, ## the HTML ``acronym`` element
  400. tagAddress, ## the HTML ``address`` element
  401. tagApplet, ## the deprecated HTML ``applet`` element
  402. tagArea, ## the HTML ``area`` element
  403. tagArticle, ## the HTML ``article`` element
  404. tagAside, ## the HTML ``aside`` element
  405. tagAudio, ## the HTML ``audio`` element
  406. tagB, ## the HTML ``b`` element
  407. tagBase, ## the HTML ``base`` element
  408. tagBdi, ## the HTML ``bdi`` element
  409. tagBdo, ## the deprecated HTML ``dbo`` element
  410. tagBasefont, ## the deprecated HTML ``basefont`` element
  411. tagBig, ## the HTML ``big`` element
  412. tagBlockquote, ## the HTML ``blockquote`` element
  413. tagBody, ## the HTML ``body`` element
  414. tagBr, ## the HTML ``br`` element
  415. tagButton, ## the HTML ``button`` element
  416. tagCanvas, ## the HTML ``canvas`` element
  417. tagCaption, ## the HTML ``caption`` element
  418. tagCenter, ## the deprecated HTML ``center`` element
  419. tagCite, ## the HTML ``cite`` element
  420. tagCode, ## the HTML ``code`` element
  421. tagCol, ## the HTML ``col`` element
  422. tagColgroup, ## the HTML ``colgroup`` element
  423. tagCommand, ## the HTML ``command`` element
  424. tagDatalist, ## the HTML ``datalist`` element
  425. tagDd, ## the HTML ``dd`` element
  426. tagDel, ## the HTML ``del`` element
  427. tagDetails, ## the HTML ``details`` element
  428. tagDfn, ## the HTML ``dfn`` element
  429. tagDialog, ## the HTML ``dialog`` element
  430. tagDiv, ## the HTML ``div`` element
  431. tagDir, ## the deprecated HTLM ``dir`` element
  432. tagDl, ## the HTML ``dl`` element
  433. tagDt, ## the HTML ``dt`` element
  434. tagEm, ## the HTML ``em`` element
  435. tagEmbed, ## the HTML ``embed`` element
  436. tagFieldset, ## the HTML ``fieldset`` element
  437. tagFigcaption, ## the HTML ``figcaption`` element
  438. tagFigure, ## the HTML ``figure`` element
  439. tagFont, ## the deprecated HTML ``font`` element
  440. tagFooter, ## the HTML ``footer`` element
  441. tagForm, ## the HTML ``form`` element
  442. tagFrame, ## the HTML ``frame`` element
  443. tagFrameset, ## the deprecated HTML ``frameset`` element
  444. tagH1, ## the HTML ``h1`` element
  445. tagH2, ## the HTML ``h2`` element
  446. tagH3, ## the HTML ``h3`` element
  447. tagH4, ## the HTML ``h4`` element
  448. tagH5, ## the HTML ``h5`` element
  449. tagH6, ## the HTML ``h6`` element
  450. tagHead, ## the HTML ``head`` element
  451. tagHeader, ## the HTML ``header`` element
  452. tagHgroup, ## the HTML ``hgroup`` element
  453. tagHtml, ## the HTML ``html`` element
  454. tagHr, ## the HTML ``hr`` element
  455. tagI, ## the HTML ``i`` element
  456. tagIframe, ## the deprecated HTML ``iframe`` element
  457. tagImg, ## the HTML ``img`` element
  458. tagInput, ## the HTML ``input`` element
  459. tagIns, ## the HTML ``ins`` element
  460. tagIsindex, ## the deprecated HTML ``isindex`` element
  461. tagKbd, ## the HTML ``kbd`` element
  462. tagKeygen, ## the HTML ``keygen`` element
  463. tagLabel, ## the HTML ``label`` element
  464. tagLegend, ## the HTML ``legend`` element
  465. tagLi, ## the HTML ``li`` element
  466. tagLink, ## the HTML ``link`` element
  467. tagMap, ## the HTML ``map`` element
  468. tagMark, ## the HTML ``mark`` element
  469. tagMenu, ## the deprecated HTML ``menu`` element
  470. tagMeta, ## the HTML ``meta`` element
  471. tagMeter, ## the HTML ``meter`` element
  472. tagNav, ## the HTML ``nav`` element
  473. tagNobr, ## the deprecated HTML ``nobr`` element
  474. tagNoframes, ## the deprecated HTML ``noframes`` element
  475. tagNoscript, ## the HTML ``noscript`` element
  476. tagObject, ## the HTML ``object`` element
  477. tagOl, ## the HTML ``ol`` element
  478. tagOptgroup, ## the HTML ``optgroup`` element
  479. tagOption, ## the HTML ``option`` element
  480. tagOutput, ## the HTML ``output`` element
  481. tagP, ## the HTML ``p`` element
  482. tagParam, ## the HTML ``param`` element
  483. tagPre, ## the HTML ``pre`` element
  484. tagProgress, ## the HTML ``progress`` element
  485. tagQ, ## the HTML ``q`` element
  486. tagRp, ## the HTML ``rp`` element
  487. tagRt, ## the HTML ``rt`` element
  488. tagRuby, ## the HTML ``ruby`` element
  489. tagS, ## the deprecated HTML ``s`` element
  490. tagSamp, ## the HTML ``samp`` element
  491. tagScript, ## the HTML ``script`` element
  492. tagSection, ## the HTML ``section`` element
  493. tagSelect, ## the HTML ``select`` element
  494. tagSmall, ## the HTML ``small`` element
  495. tagSource, ## the HTML ``source`` element
  496. tagSpan, ## the HTML ``span`` element
  497. tagStrike, ## the deprecated HTML ``strike`` element
  498. tagStrong, ## the HTML ``strong`` element
  499. tagStyle, ## the HTML ``style`` element
  500. tagSub, ## the HTML ``sub`` element
  501. tagSummary, ## the HTML ``summary`` element
  502. tagSup, ## the HTML ``sup`` element
  503. tagTable, ## the HTML ``table`` element
  504. tagTbody, ## the HTML ``tbody`` element
  505. tagTd, ## the HTML ``td`` element
  506. tagTextarea, ## the HTML ``textarea`` element
  507. tagTfoot, ## the HTML ``tfoot`` element
  508. tagTh, ## the HTML ``th`` element
  509. tagThead, ## the HTML ``thead`` element
  510. tagTime, ## the HTML ``time`` element
  511. tagTitle, ## the HTML ``title`` element
  512. tagTr, ## the HTML ``tr`` element
  513. tagTrack, ## the HTML ``track`` element
  514. tagTt, ## the HTML ``tt`` element
  515. tagU, ## the deprecated HTML ``u`` element
  516. tagUl, ## the HTML ``ul`` element
  517. tagVar, ## the HTML ``var`` element
  518. tagVideo, ## the HTML ``video`` element
  519. tagWbr ## the HTML ``wbr`` element
  520. # bug #11469
  521. const lookup: array[32, uint8] = [0'u8, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15,
  522. 16, 17, 25, 17, 4, 8, 31, 27, 13, 23]
  523. veryLongVariableName.createVar("future" & $node[1][0].toStrLit, node[1],
  524. futureValue1, futureValue2, node)
  525. veryLongVariableName.createVar("future" & $node[1][0].toStrLit, node[1], futureValue1,
  526. futureValue2, node)
  527. type
  528. CmdLineKind* = enum ## The detected command line token.
  529. cmdEnd, ## End of command line reached
  530. cmdArgument, ## An argument such as a filename
  531. cmdLongOption, ## A long option such as --option
  532. cmdShortOption ## A short option such as -c
  533. OptParser* = object of RootObj ## \
  534. ## Implementation of the command line parser. Here is even more text yad.
  535. ##
  536. ## To initialize it, use the
  537. ## `initOptParser proc<#initOptParser,string,set[char],seq[string]>`_.
  538. pos*: int
  539. inShortState: bool
  540. allowWhitespaceAfterColon: bool
  541. shortNoVal: set[char]
  542. longNoVal: seq[string]
  543. cmds: seq[string]
  544. idx: int
  545. kind*: CmdLineKind ## The detected command line token
  546. key*, val*: TaintedString ## Key and value pair; the key is the option
  547. ## or the argument, and the value is not "" if
  548. ## the option was given a value
  549. OptParserDifferently* = object of RootObj ## Implementation of the command line parser.
  550. ##
  551. ## To initialize it, use the
  552. ## `initOptParser proc<#initOptParser,string,set[char],seq[string]>`_.
  553. pos*: int
  554. inShortState: bool
  555. allowWhitespaceAfterColon: bool
  556. shortNoVal: set[char]
  557. longNoVal: seq[string]
  558. cmds: seq[string]
  559. idx: int
  560. kind*: CmdLineKind ## The detected command line token
  561. key*, val*: TaintedString ## Key and value pair; the key is the option
  562. ## or the argument, and the value is not "" if
  563. ## the option was given a value