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
parent e80465dacf
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
result
if all("mystring", {'a'..'z'}.contains) and any("myohmy", 'y'.`==`):
if all("mystring", {'a'..'z'}.contains) and any("myohmy", 'y'.`==`):
echo "works"
else:
else:
echo "does not work"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -90,7 +90,7 @@ proc serveFile(client: Socket, filename: string) =
# ------------------ CGI execution -------------------------------------------
proc executeCgi(server: var TServer, client: Socket, path, query: string,
proc executeCgi(server: var TServer, client: Socket, path, query: string,
meth: TRequestMethod) =
var env = newStringTable(modeCaseInsensitive)
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)
var process = startProcess(command=path, env=env)
var job: TJob
job.process = process
job.client = client
server.job.add(job)
if meth == reqPost:
# get from client and post to CGI program:
var buf = alloc(contentLength)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,4 +1,4 @@
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,
" is the maximum!"
" is the maximum!"