summary refs log tree commit diff stats
path: root/compiler/plugins/active.nim
blob: 19c320aae72e5c8655c75fa4e8d96897d866396d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#
#
#           The Nim Compiler
#        (c) Copyright 2015 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## Include file that imports all plugins that are active.

import
  ".." / [pluginsupport, idents, ast], locals, itersgen

const
  plugins: array[2, Plugin] = [
    ("stdlib", "system", "iterToProc", iterToProcImpl),
    ("stdlib", "system", "locals", semLocals)
  ]

proc getPlugin*(ic: IdentCache; fn: PSym): Transformation =
  for p in plugins:
    if pluginMatches(ic, p, fn): return p.t
  return nil
old } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
discard """
output: '''
abc
def
definition
prefix
xyz
def
definition
Hi Andreas! How do you feel, Rumpf?

@[0, 2, 1]
@[1, 0, 2]
@[1, 2, 0]
@[2, 0, 1]
@[2, 1, 0]
@[2, 0, 1]
@[1, 2, 0]
@[1, 0, 2]
@[0, 2, 1]
@[0, 1, 2]
055this should be the casehugh@["(", "+", " 1", " 2", ")"]
caught a crash!
caught a crash!
caught a crash!
caught a crash!
caught a crash!
caught a crash!
[5]
[4, 5]
[3, 4, 5]
[2, 3, 4, 5]
[2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]
true
<h1><a href="http://force7.de/nim">Nim</a></h1>
'''
"""

import
  critbits, sets, strutils, tables, random, algorithm, re, ropes, segfaults,
  lists, parsesql, streams, os, htmlgen, xmltree, strtabs


block tcritbits:
  var r: CritBitTree[void]
  r.incl "abc"
  r.incl "xyz"
  r.incl "def"
  r.incl "definition"
  r.incl "prefix"
  doAssert r.contains"def"
  #r.del "def"

  for w in r.items:
    echo w
  for w in r.itemsWithPrefix("de"):
    echo w



block testequivalence:
  doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3,4]), "equivalent or subset")
  doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3]), "equivalent or subset")
  doAssert((not(toSet(@[1,2,3]) <= toSet(@[1,2]))), "equivalent or subset")
  doAssert(toSet(@[1,2,3]) <= toSet(@[1,2,3,4]), "strict subset")
  doAssert((not(toSet(@[1,2,3]) < toSet(@[1,2,3]))), "strict subset")
  doAssert((not(toSet(@[1,2,3]) < toSet(@[1,2]))), "strict subset")
  doAssert((not(toSet(@[1,2,3]) == toSet(@[1,2,3,4]))), "==")
  doAssert(toSet(@[1,2,3]) == toSet(@[1,2,3]), "==")
  doAssert((not(toSet(@[1,2,3]) == toSet(@[1,2]))), "==")



block tformat:
  echo("Hi $1! How do you feel, $2?\n" % ["Andreas", "Rumpf"])



block tnilecho:
  var x = @["1", "", "3"]
  doAssert $x == """@["1", "", "3"]"""



block torderedtable:
  var t = initOrderedTable[int,string]()

  # this tests issue #5917
  var data = newSeq[int]()
  for i in 0..<1000:
    var x = rand(1000)
    if x notin t: data.add(x)
    t[x] = "meh"

  # this checks that keys are re-inserted
  # in order when table is enlarged.
  var i = 0
  for k, v in t:
    doAssert(k == data[i])
    doAssert(v == "meh")
    inc(i)



block tpermutations:
  var v = @[0, 1, 2]
  while v.nextPermutation():
    echo v
  while v.prevPermutation():
    echo v



block treguse:
  proc main(a, b: int) =
    var x = 0
    write(stdout, x)
    if x == 0:
      var y = 55
      write(stdout, y)
      write(stdout, "this should be the case")
      var input = "<no input>"
      if input == "Andreas":
        write(stdout, "wow")
      else:
        write(stdout, "hugh")
    else:
      var z = 66
      write(stdout, z) # "bug!")

  main(45, 1000)



block treloop:
  let str = "(+ 1 2)"
  var tokenRE = re"""[\s,]*(~@|[\[\]{}()'`~^@]|"(?:\\.|[^\\"])*"|;.*|[^\s\[\]{}('"`,;)]*)"""
  echo str.findAll(tokenRE)



block tropes:
  var
    r1 = rope("")
    r2 = rope("123")
  doAssert r1.len == 0
  doAssert r2.len == 3
  doAssert $r1 == ""
  doAssert $r2 == "123"

  r1.add("123")
  r2.add("456")
  doAssert r1.len == 3
  doAssert r2.len == 6
  doAssert $r1 == "123"
  doAssert $r2 == "123456"
  doAssert $r1[1] == "2"
  doAssert $r2[2] == "3"



block tsegfaults:
  proc main =
    try:
      var x: ptr int
      echo x[]
      try:
        raise newException(ValueError, "not a crash")
      except ValueError:
        discard
    except NilAccessError:
      echo "caught a crash!"
  for i in 0..5:
    main()



block tsinglylinkedring:
  var r = initSinglyLinkedRing[int]()
  r.prepend(5)
  echo r
  r.prepend(4)
  echo r
  r.prepend(3)
  echo r
  r.prepend(2)
  echo r
  r.append(6)
  echo r
  r.prepend(1)
  echo r



block tsplit:
  var s = ""
  for w in split("|abc|xy|z", {'|'}):
    s.add("#")
    s.add(w)

  doAssert s == "##abc#xy#z"



block tsplit2:
  var s = ""
  for w in split("|abc|xy|z", {'|'}):
    s.add("#")
    s.add(w)

  try:
    discard "hello".split("")
    echo "false"
  except AssertionError:
    echo "true"



block tsqlparser:
  # Just check that we can parse 'somesql' and render it without crashes.
  var tree = parseSql(newFileStream( parentDir(currentSourcePath) / "somesql.sql"), "somesql")
  discard renderSql(tree)



block txmlgen:
  var nim = "Nim"
  echo h1(a(href="http://force7.de/nim", nim))



block txmltree:
  var x = <>a(href="nim.de", newText("www.nim-test.de"))

  doAssert($x == "<a href=\"nim.de\">www.nim-test.de</a>")
  doAssert(newText("foo").innerText == "foo")
  doAssert(newEntity("bar").innerText == "bar")
  doAssert(newComment("baz").innerText == "")

  let y = newXmlTree("x", [
    newText("foo"),
    newXmlTree("y", [
      newText("bar")
    ])
  ])
  doAssert(y.innerText == "foobar")