exhaustive.nim 25 KB

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