examples: Trim .nim files trailing whitespace

via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
This commit is contained in:
Adam Strzelecki 2015-09-04 23:05:22 +02:00
commit 5d80548cce
15 changed files with 141 additions and 141 deletions

View file

@ -18,9 +18,9 @@ template any(container, cond: expr): expr {.immediate.} =
break break
result result
if all("mystring", {'a'..'z'}.contains) and any("myohmy", 'y'.`==`): if all("mystring", {'a'..'z'}.contains) and any("myohmy", 'y'.`==`):
echo "works" echo "works"
else: else:
echo "does not work" echo "does not work"

View file

@ -18,13 +18,13 @@ type
TDimension2d {.final, header: irr, importc: "dimension2d".} = object TDimension2d {.final, header: irr, importc: "dimension2d".} = object
Tvector3df {.final, header: irr, importc: "vector3df".} = object Tvector3df {.final, header: irr, importc: "vector3df".} = object
TColor {.final, header: irr, importc: "SColor".} = object TColor {.final, header: irr, importc: "SColor".} = object
TIrrlichtDevice {.final, header: irr, importc: "IrrlichtDevice".} = object TIrrlichtDevice {.final, header: irr, importc: "IrrlichtDevice".} = object
TIVideoDriver {.final, header: irr, importc: "IVideoDriver".} = object TIVideoDriver {.final, header: irr, importc: "IVideoDriver".} = object
TISceneManager {.final, header: irr, importc: "ISceneManager".} = object TISceneManager {.final, header: irr, importc: "ISceneManager".} = object
TIGUIEnvironment {.final, header: irr, importc: "IGUIEnvironment".} = object TIGUIEnvironment {.final, header: irr, importc: "IGUIEnvironment".} = object
TIAnimatedMesh {.final, header: irr, importc: "IAnimatedMesh".} = object TIAnimatedMesh {.final, header: irr, importc: "IAnimatedMesh".} = object
TIAnimatedMeshSceneNode {.final, header: irr, TIAnimatedMeshSceneNode {.final, header: irr,
importc: "IAnimatedMeshSceneNode".} = object importc: "IAnimatedMeshSceneNode".} = object
TITexture {.final, header: irr, importc: "ITexture".} = object TITexture {.final, header: irr, importc: "ITexture".} = object
@ -100,7 +100,7 @@ var node = smgr.addAnimatedMeshSceneNode(mesh)
if node != nil: if node != nil:
#node->setMaterialFlag(EMF_LIGHTING, false) #node->setMaterialFlag(EMF_LIGHTING, false)
#node->setMD2Animation(scene::EMAT_STAND) #node->setMD2Animation(scene::EMAT_STAND)
node.setMaterialTexture(0, node.setMaterialTexture(0,
driver.getTexture( driver.getTexture(
"/home/andreas/download/irrlicht-1.7.2/media/media/sydney.bmp")) "/home/andreas/download/irrlicht-1.7.2/media/media/sydney.bmp"))

View file

@ -1,5 +1,5 @@
# Backend for the different user interfaces. # Backend for the different user interfaces.
proc myAdd*(x, y: int): int {.cdecl, exportc.} = proc myAdd*(x, y: int): int {.cdecl, exportc.} =
result = x + y result = x + y

View file

@ -1,8 +1,8 @@
import import
libcurl libcurl
var hCurl = easy_init() var hCurl = easy_init()
if hCurl != nil: if hCurl != nil:
discard easy_setopt(hCurl, OPT_VERBOSE, true) discard easy_setopt(hCurl, OPT_VERBOSE, true)
discard easy_setopt(hCurl, OPT_URL, "http://nim-lang.org/") discard easy_setopt(hCurl, OPT_URL, "http://nim-lang.org/")
discard easy_perform(hCurl) discard easy_perform(hCurl)

View file

@ -1,6 +1,6 @@
#! stdtmpl | standard #! stdtmpl | standard
#proc generateHTMLPage(title, currentTab, content: string, #proc generateHTMLPage(title, currentTab, content: string,
# tabs: openArray[string]): string = # tabs: openArray[string]): string =
# result = "" # result = ""
<head><title>$title</title></head> <head><title>$title</title></head>
<body> <body>
@ -8,7 +8,7 @@
<ul> <ul>
#for tab in items(tabs): #for tab in items(tabs):
#if currentTab == tab: #if currentTab == tab:
<li><a id="selected" <li><a id="selected"
#else: #else:
<li><a <li><a
#end if #end if

View file

@ -4,11 +4,11 @@
import os, streams, parsexml, strutils import os, streams, parsexml, strutils
proc `=?=` (a, b: string): bool = proc `=?=` (a, b: string): bool =
# little trick: define our own comparator that ignores case # little trick: define our own comparator that ignores case
return cmpIgnoreCase(a, b) == 0 return cmpIgnoreCase(a, b) == 0
if paramCount() < 1: if paramCount() < 1:
quit("Usage: htmlrefs filename[.html]") quit("Usage: htmlrefs filename[.html]")
var links = 0 # count the number of links var links = 0 # count the number of links
@ -21,17 +21,17 @@ next(x) # get first event
block mainLoop: block mainLoop:
while true: while true:
case x.kind case x.kind
of xmlElementOpen: of xmlElementOpen:
# the <a href = "xyz"> tag we are interested in always has an attribute, # the <a href = "xyz"> tag we are interested in always has an attribute,
# thus we search for ``xmlElementOpen`` and not for ``xmlElementStart`` # thus we search for ``xmlElementOpen`` and not for ``xmlElementStart``
if x.elementName =?= "a": if x.elementName =?= "a":
x.next() x.next()
if x.kind == xmlAttribute: if x.kind == xmlAttribute:
if x.attrKey =?= "href": if x.attrKey =?= "href":
var link = x.attrValue var link = x.attrValue
inc(links) inc(links)
# skip until we have an ``xmlElementClose`` event # skip until we have an ``xmlElementClose`` event
while true: while true:
x.next() x.next()
case x.kind case x.kind
of xmlEof: break mainLoop of xmlEof: break mainLoop
@ -40,14 +40,14 @@ block mainLoop:
x.next() # skip ``xmlElementClose`` x.next() # skip ``xmlElementClose``
# now we have the description for the ``a`` element # now we have the description for the ``a`` element
var desc = "" var desc = ""
while x.kind == xmlCharData: while x.kind == xmlCharData:
desc.add(x.charData) desc.add(x.charData)
x.next() x.next()
echo(desc & ": " & link) echo(desc & ": " & link)
else: else:
x.next() x.next()
of xmlEof: break # end of file reached of xmlEof: break # end of file reached
of xmlError: of xmlError:
echo(errorMsg(x)) echo(errorMsg(x))
x.next() x.next()
else: x.next() # skip other events else: x.next() # skip other events

View file

@ -15,11 +15,11 @@ open(x, s, filename)
while true: while true:
x.next() x.next()
case x.kind case x.kind
of xmlElementStart: of xmlElementStart:
if cmpIgnoreCase(x.elementName, "title") == 0: if cmpIgnoreCase(x.elementName, "title") == 0:
var title = "" var title = ""
x.next() # skip "<title>" x.next() # skip "<title>"
while x.kind == xmlCharData: while x.kind == xmlCharData:
title.add(x.charData) title.add(x.charData)
x.next() x.next()
if x.kind == xmlElementEnd and cmpIgnoreCase(x.elementName, "title") == 0: if x.kind == xmlElementEnd and cmpIgnoreCase(x.elementName, "title") == 0:
@ -27,7 +27,7 @@ while true:
quit(0) # Success! quit(0) # Success!
else: else:
echo(x.errorMsgExpected("/title")) echo(x.errorMsgExpected("/title"))
of xmlEof: break # end of file reached of xmlEof: break # end of file reached
else: discard # ignore other events else: discard # ignore other events

View file

@ -90,7 +90,7 @@ proc serveFile(client: Socket, filename: string) =
# ------------------ CGI execution ------------------------------------------- # ------------------ CGI execution -------------------------------------------
proc executeCgi(server: var TServer, client: Socket, path, query: string, proc executeCgi(server: var TServer, client: Socket, path, query: string,
meth: TRequestMethod) = meth: TRequestMethod) =
var env = newStringTable(modeCaseInsensitive) var env = newStringTable(modeCaseInsensitive)
var contentLength = -1 var contentLength = -1
@ -123,12 +123,12 @@ proc executeCgi(server: var TServer, client: Socket, path, query: string,
send(client, "HTTP/1.0 200 OK" & wwwNL) send(client, "HTTP/1.0 200 OK" & wwwNL)
var process = startProcess(command=path, env=env) var process = startProcess(command=path, env=env)
var job: TJob var job: TJob
job.process = process job.process = process
job.client = client job.client = client
server.job.add(job) server.job.add(job)
if meth == reqPost: if meth == reqPost:
# get from client and post to CGI program: # get from client and post to CGI program:
var buf = alloc(contentLength) var buf = alloc(contentLength)

View file

@ -1,6 +1,6 @@
# Test high level features # Test high level features
import strutils import strutils
echo "Give a list of numbers (separated by spaces): " echo "Give a list of numbers (separated by spaces): "
stdin.readLine.split.map(parseInt).max.`$`.echo(" is the maximum!") stdin.readLine.split.map(parseInt).max.`$`.echo(" is the maximum!")

View file

@ -1,7 +1,7 @@
import import
os, parsecfg, strutils, streams os, parsecfg, strutils, streams
var f = newFileStream(paramStr(1), fmRead) var f = newFileStream(paramStr(1), fmRead)
if f != nil: if f != nil:
var p: CfgParser var p: CfgParser
@ -9,7 +9,7 @@ if f != nil:
while true: while true:
var e = next(p) var e = next(p)
case e.kind case e.kind
of cfgEof: of cfgEof:
echo("EOF!") echo("EOF!")
break break
of cfgSectionStart: ## a ``[section]`` has been parsed of cfgSectionStart: ## a ``[section]`` has been parsed

View file

@ -1,52 +1,52 @@
# Test the SDL interface: # Test the SDL interface:
import import
sdl, sdl_image, colors sdl, sdl_image, colors
var var
screen, greeting: PSurface screen, greeting: PSurface
r: TRect r: TRect
event: TEvent event: TEvent
bgColor = colChocolate.int32 bgColor = colChocolate.int32
if init(INIT_VIDEO) != 0: if init(INIT_VIDEO) != 0:
quit "SDL failed to initialize!" quit "SDL failed to initialize!"
screen = setVideoMode(640, 480, 16, SWSURFACE or ANYFORMAT) screen = setVideoMode(640, 480, 16, SWSURFACE or ANYFORMAT)
if screen.isNil: if screen.isNil:
quit($sdl.getError()) quit($sdl.getError())
greeting = imgLoad("tux.png") greeting = imgLoad("tux.png")
if greeting.isNil: if greeting.isNil:
echo "Failed to load tux.png" echo "Failed to load tux.png"
else: else:
## convert the image to alpha and free the old one ## convert the image to alpha and free the old one
var s = greeting.displayFormatAlpha() var s = greeting.displayFormatAlpha()
swap(greeting, s) swap(greeting, s)
s.freeSurface() s.freeSurface()
r.x = 0 r.x = 0
r.y = 0 r.y = 0
block game_loop: block game_loop:
while true: while true:
while pollEvent(addr event) > 0: while pollEvent(addr event) > 0:
case event.kind case event.kind
of QUITEV: of QUITEV:
break game_loop break game_loop
of KEYDOWN: of KEYDOWN:
if evKeyboard(addr event).keysym.sym == K_ESCAPE: if evKeyboard(addr event).keysym.sym == K_ESCAPE:
break game_loop break game_loop
else: else:
discard discard
discard fillRect(screen, nil, bgColor) discard fillRect(screen, nil, bgColor)
discard blitSurface(greeting, nil, screen, addr r) discard blitSurface(greeting, nil, screen, addr r)
discard flip(screen) discard flip(screen)
greeting.freeSurface() greeting.freeSurface()
screen.freeSurface() screen.freeSurface()
sdl.quit() sdl.quit()
## fowl wuz here 10/2012 ## fowl wuz here 10/2012

View file

@ -28,7 +28,7 @@ while readRow(x):
for i in 0..x.row.len-1: header[i] = "Col " & $(i+1) for i in 0..x.row.len-1: header[i] = "Col " & $(i+1)
else: else:
# data line: # data line:
for i in 0..x.row.len-1: for i in 0..x.row.len-1:
push(res[i], parseFloat(x.row[i])) push(res[i], parseFloat(x.row[i]))
x.close() x.close()

View file

@ -1,7 +1,7 @@
template htmlTag(tag: expr) {.immediate.} = template htmlTag(tag: expr) {.immediate.} =
proc tag(): string = "<" & astToStr(tag) & ">" proc tag(): string = "<" & astToStr(tag) & ">"
htmlTag(br) htmlTag(br)
htmlTag(html) htmlTag(html)

View file

@ -1,47 +1,47 @@
import import
unittest, macros unittest, macros
var var
a = 1 a = 1
b = 22 b = 22
c = 1 c = 1
d = 3 d = 3
suite "my suite": suite "my suite":
setup: setup:
echo "suite setup" echo "suite setup"
var testVar = "from setup" var testVar = "from setup"
teardown: teardown:
echo "suite teardown" echo "suite teardown"
test "first suite test": test "first suite test":
testVar = "modified" testVar = "modified"
echo "test var: " & testVar echo "test var: " & testVar
check a > b check a > b
test "second suite test": test "second suite test":
echo "test var: " & testVar echo "test var: " & testVar
proc foo: bool = proc foo: bool =
echo "running foo" echo "running foo"
return true return true
proc err = proc err =
raise newException(EArithmetic, "some exception") raise newException(EArithmetic, "some exception")
test "final test": test "final test":
echo "inside suite-less test" echo "inside suite-less test"
check: check:
a == c a == c
foo() foo()
d > 10 d > 10
test "arithmetic failure": test "arithmetic failure":
expect(EArithmetic): expect(EArithmetic):
err() err()
expect(EArithmetic, ESystem): expect(EArithmetic, ESystem):
discard foo() discard foo()

View file

@ -1,4 +1,4 @@
import strutils import strutils
echo "Give a list of integers (separated by spaces): ", echo "Give a list of integers (separated by spaces): ",
stdin.readLine.split.each(parseInt).max, stdin.readLine.split.each(parseInt).max,
" is the maximum!" " is the maximum!"