exhaustive.nim 25 KB

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