Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nim language parser and fix makefile #401

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Units/nim-comment_variable.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
TA input.nim /^ TA = object of RootObj$/;" o typeref:object:TA
TB input.nim /^ TB = object of TA$/;" o typeref:object:TB
a input.nim /^ a: ref TA$/;" v
b input.nim /^ b: ref TB$/;" v
f input.nim /^ f: int$/;" f object:TB
15 changes: 15 additions & 0 deletions Units/nim-comment_variable.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import streams, msgpack

type
TA = object of RootObj
TB = object of TA
f: int

var
a: ref TA
b: ref TB

new(b)
a = b

echo stringify(pack(a)) #produces "[ ]", not "[ 0 ]" or '{ "f" : 0 }'
10 changes: 10 additions & 0 deletions Units/nim-concept.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Container input.nim /^ Container[T] = concept c$/;" s
ObjectContainer input.nim /^ ObjectContainer = concept C$/;" s
PDict input.nim /^ PDict[TK, TV] = ref TDict[TK, TV]$/;" t
RNG input.nim /^type RNG* = concept var rng$/;" s
Sortable input.nim /^ Sortable = concept x, y$/;" s
TDict input.nim /^ TDict[TK, TV] = object$/;" o typeref:object:TDict
TObj input.nim /^ TObj = object$/;" o typeref:object:TObj
k input.nim /^ k: TK$/;" f object:TDict
v input.nim /^ v: TV$/;" f object:TDict
x input.nim /^ x: int$/;" f object:TObj
27 changes: 27 additions & 0 deletions Units/nim-concept.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
type
TDict[TK, TV] = object
k: TK
v: TV
PDict[TK, TV] = ref TDict[TK, TV]

type
TObj = object
x: int

Sortable = concept x, y
(x < y) is bool

ObjectContainer = concept C
C.len is Ordinal
for v in items(C):
v.type is tuple|object

type
Container[T] = concept c
c.len is Ordinal
items(c) is iterator
for value in c:
type(value) is T

type RNG* = concept var rng
rng.randomUint32() is uint32
8 changes: 8 additions & 0 deletions Units/nim-constant_generics.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MACMAP input.nim /^ MACMAP = [123,123]$/;" k
STDMAP input.nim /^ STDMAP* = [$/;" k
WINMAP input.nim /^ WINMAP = [123,123]$/;" k
abc input.nim /^proc abc(x,y: tuple[key: int, val: int]) = discard$/;" p
col input.nim /^var col = initOrderedTable[int, int]();$/;" v
pack_type input.nim /^proc pack_type*[T: tuple|object](s: int, val: T) = discard$/;" p
pack_type input.nim /^proc pack_type*[T](y: int, val: ptr T) = discard$/;" p
unpack_ext input.nim /^proc unpack_ext*(s: int): tuple[exttype:uint8, len: int] = discard$/;" p
17 changes: 17 additions & 0 deletions Units/nim-constant_generics.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import algorithm, tables

const
STDMAP* = [
0x2202, 0x2202, 0x123]
MACMAP = [123,123]
WINMAP = [123,123]

var col = initOrderedTable[int, int]();

col.sort(proc(x,y: tuple[key: int, val: int]):int = cmp(x, y) )

proc abc(x,y: tuple[key: int, val: int]) = discard

proc pack_type*[T: tuple|object](s: int, val: T) = discard
proc pack_type*[T](y: int, val: ptr T) = discard
proc unpack_ext*(s: int): tuple[exttype:uint8, len: int] = discard
9 changes: 9 additions & 0 deletions Units/nim-funny_procs.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TMatrix input.nim /^type TMatrix*[N,M: static[int], T] = object$/;" o typeref:object:TMatrix
`1/1` input.nim /^proc `1\/1`() = echo(1 div 1)$/;" p
`1/2` input.nim /^template `1\/2`() = echo(1 div 2)$/;" g
`1/3` input.nim /^var `1\/3` = 1 div 4$/;" v
`1/4` input.nim /^let `1\/4` = 1 div 4$/;" l
`==` input.nim /^proc `==`*(a: distinct TMatrix; b: distinct TMatrix): bool =$/;" p
data input.nim /^ data*: array[0..N*M-1, T]$/;" f object:TMatrix
p input.nim /^proc p(x, y: int): int =$/;" p
x input.nim /^ var x = 7$/;" v
25 changes: 25 additions & 0 deletions Units/nim-funny_procs.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# bug #1055
import unittest
type TMatrix*[N,M: static[int], T] = object
data*: array[0..N*M-1, T]
proc `==`*(a: distinct TMatrix; b: distinct TMatrix): bool =
result = a.data == b.data

proc p(x, y: int): int =
result = x + y

echo p((proc (): int =
var x = 7
return x)(),
(proc (): int = return 4)())

proc `1/1`() = echo(1 div 1)
template `1/2`() = echo(1 div 2)
var `1/3` = 1 div 4
`1/3` = 1 div 3 # oops, 1/3!=1/4
let `1/4` = 1 div 4

`1/1`()
`1/2`()
echo `1/3`
echo `1/4`
12 changes: 12 additions & 0 deletions Units/nim-generics_again.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Binders input.nim /^ Binders: seq[TProperty[T]]$/;" f object:TProperty
EEmitter input.nim /^ EEmitter: TEventEmitter$/;" f object:TProperty
Point2 input.nim /^ Point2[T] = tuple[x, y: T]$/;" u typeref:tuple:Point2
Property input.nim /^ Property*: TProperty[T]$/;" f object:TValueEventArgs
TProperty input.nim /^ TProperty*[T] = object of TObject$/;" o typeref:object:TProperty
TValueEventArgs input.nim /^ TValueEventArgs[T] = object of TEventArgs$/;" o typeref:object:TValueEventArgs
ValueChanged input.nim /^ ValueChanged*: TEventHandler$/;" f object:TProperty
getProc input.nim /^ getProc: proc(property: TProperty[T]): T {.nimcall.}$/;" f object:TProperty
setProc input.nim /^ setProc: proc(property: var TProperty[T], value: T) {.nimcall.}$/;" f object:TProperty
value input.nim /^ value: T$/;" f object:TProperty
x input.nim /^ Point2[T] = tuple[x, y: T]$/;" n tuple:Point2
y input.nim /^ Point2[T] = tuple[x, y: T]$/;" n tuple:Point2
13 changes: 13 additions & 0 deletions Units/nim-generics_again.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type
Point2[T] = tuple[x, y: T]

TProperty*[T] = object of TObject
getProc: proc(property: TProperty[T]): T {.nimcall.}
setProc: proc(property: var TProperty[T], value: T) {.nimcall.}
value: T
ValueChanged*: TEventHandler
Binders: seq[TProperty[T]]
EEmitter: TEventEmitter
# Not a descriptive name but it was that or TPropertyValueChangeEventArgs.
TValueEventArgs[T] = object of TEventArgs
Property*: TProperty[T]
9 changes: 9 additions & 0 deletions Units/nim-generics_tuple.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
a input.nim /^ ttt = tuple[a:string,b:int,c:int,d:float]$/;" n tuple:ttt
b input.nim /^ ttt = tuple[a:string,b:int,c:int,d:float]$/;" n tuple:ttt
c input.nim /^ ttt = tuple[a:string,b:int,c:int,d:float]$/;" n tuple:ttt
d input.nim /^ ttt = tuple[a:string,b:int,c:int,d:float]$/;" n tuple:ttt
ttt input.nim /^ ttt = tuple[a:string,b:int,c:int,d:float]$/;" u typeref:tuple:ttt
unpack_type input.nim /^proc unpack_type*(s: Stream, val: var StringTableRef)$/;" p
unpack_type input.nim /^proc unpack_type*(s: Stream, val: var float32)$/;" p
unpack_type input.nim /^proc unpack_type*[K,V](s: Stream, val: var OrderedTable[K,V])$/;" p
unpack_type input.nim /^proc unpack_type*[K,V](s: Stream, val: var TableRef[K,V])$/;" p
7 changes: 7 additions & 0 deletions Units/nim-generics_tuple.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type
ttt = tuple[a:string,b:int,c:int,d:float]

proc unpack_type*(s: Stream, val: var StringTableRef)
proc unpack_type*(s: Stream, val: var float32)
proc unpack_type*[K,V](s: Stream, val: var OrderedTable[K,V])
proc unpack_type*[K,V](s: Stream, val: var TableRef[K,V])
24 changes: 24 additions & 0 deletions Units/nim-object_field.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Animal input.nim /^ Animal = ref object of RootObj$/;" o typeref:object:Animal
Apple input.nim /^ Apple, Banana, Lemon, Durian, Rambutan$/;" r enum:Fruits
Banana input.nim /^ Apple, Banana, Lemon, Durian, Rambutan$/;" r enum:Fruits
Durian input.nim /^ Apple, Banana, Lemon, Durian, Rambutan$/;" r enum:Fruits
Fruits input.nim /^ Fruits = enum$/;" e typeref:enum:Fruits
Gradient input.nim /^ Gradient* = ref object$/;" o typeref:object:Gradient
ID input.nim /^ ID*, objID*: int$/;" f object:Gradient
Lemon input.nim /^ Apple, Banana, Lemon, Durian, Rambutan$/;" r enum:Fruits
Rambutan input.nim /^ Apple, Banana, Lemon, Durian, Rambutan$/;" r enum:Fruits
Vehicle input.nim /^ Vehicle = object$/;" o typeref:object:Vehicle
a input.nim /^ a*, b*: RGBColor$/;" f object:Gradient
anotherint input.nim /^ anotherint = int$/;" t
axis input.nim /^ axis* : Coord$/;" f object:Gradient
b input.nim /^ a*, b*: RGBColor$/;" f object:Gradient
brand input.nim /^ brand: string$/;" f object:Vehicle
inttoo input.nim /^ inttoo = distinct int$/;" t
isOperator input.nim /^proc isOperator*(tok: TToken, Kilo: var int): bool$/;" p
name input.nim /^ name: string$/;" f object:Animal
objID input.nim /^ ID*, objID*: int$/;" f object:Gradient
parseAll input.nim /^proc parseAll*(p: var TParser, tonne: int): PNode$/;" p
radCoord input.nim /^ radCoord*: CoordRadial$/;" f object:Gradient
speed input.nim /^ speed: int$/;" f object:Animal
speed input.nim /^ wheel, speed: int$/;" f object:Vehicle
wheel input.nim /^ wheel, speed: int$/;" f object:Vehicle
27 changes: 27 additions & 0 deletions Units/nim-object_field.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
type
Fruits = enum
Apple, Banana, Lemon, Durian, Rambutan

Vehicle = object
wheel, speed: int
brand: string

Animal = ref object of RootObj
name: string
speed: int

Gradient* = ref object
ID*, objID*: int
a*, b*: RGBColor
case gradType*: GradientType
of GDT_LINEAR:
axis* : Coord
of GDT_RADIAL:
radCoord*: CoordRadial

anotherint = int
inttoo = distinct int


proc isOperator*(tok: TToken, Kilo: var int): bool
proc parseAll*(p: var TParser, tonne: int): PNode
4 changes: 4 additions & 0 deletions Units/nim-operator_endline.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
filename input.nim /^var filename = addFileExt(paramStr(1), "html")$/;" v
s input.nim /^var s = newFileStream(filename, fmRead)$/;" v
title input.nim /^ var title = ""$/;" v
x input.nim /^var x: XmlParser$/;" v
36 changes: 36 additions & 0 deletions Units/nim-operator_endline.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Example program to show the parsexml module
# This program reads an HTML file and writes its title to stdout.
# Errors and whitespace are ignored.

import os, streams, parsexml, strutils

if paramCount() < 1:
quit("Usage: htmltitle filename[.html]")

var filename = addFileExt(paramStr(1), "html")
var s = newFileStream(filename, fmRead)
if s == nil: quit("cannot open the file " & filename)
var x: XmlParser
open(x, s, filename)
while true:
x.next()
case x.kind
of xmlElementStart:
if cmpIgnoreCase(x.elementName, "title") == 0:
var title = ""
x.next() # skip "<title>"
while x.kind == xmlCharData:
title.add(x.charData)
x.next()
if x.kind == xmlElementEnd and cmpIgnoreCase(x.elementName, "title") == 0:
echo("Title: " & title)
quit(0) # Success!
else:
echo(x.errorMsgExpected("/title"))

of xmlEof: break # end of file reached
else: discard # ignore other events

x.close()
quit("Could not determine title!")

5 changes: 5 additions & 0 deletions Units/nim-proc_tables.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
action1 input.nim /^proc action1(arg: string) = $/;" p
action2 input.nim /^proc action2(arg: string) = $/;" p
action3 input.nim /^proc action3(arg: string) = $/;" p
action4 input.nim /^proc action4(arg: string) = $/;" p
actionTable input.nim /^ actionTable = {$/;" v
27 changes: 27 additions & 0 deletions Units/nim-proc_tables.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
discard """
output: "action 3 arg"
"""

import tables

proc action1(arg: string) =
echo "action 1 ", arg

proc action2(arg: string) =
echo "action 2 ", arg

proc action3(arg: string) =
echo "action 3 ", arg

proc action4(arg: string) =
echo "action 4 ", arg

var
actionTable = {
"A": action1,
"B": action2,
"C": action3,
"D": action4}.toTable

actionTable["C"]("arg")

8 changes: 8 additions & 0 deletions Units/nim-ptr_field.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TClassOfTCustomObject input.nim /^ TClassOfTCustomObject {.pure, inheritable.} = object$/;" o typeref:object:TClassOfTCustomObject
TClassOfTobj input.nim /^ TClassOfTobj = object of TClassOfTCustomObject$/;" o typeref:object:TClassOfTobj
TCustomObject input.nim /^ TCustomObject = ref object {.inheritable.}$/;" o typeref:object:TCustomObject
TObj input.nim /^ TObj = ref object of TCustomObject$/;" o typeref:object:TObj
base input.nim /^ base* : ptr TClassOfTCustomObject$/;" f object:TClassOfTCustomObject
class input.nim /^ class* : ptr TClassOfTCustomObject$/;" f object:TCustomObject
className input.nim /^ className* : string$/;" f object:TClassOfTCustomObject
data input.nim /^ data: int/;" f object:TObj
10 changes: 10 additions & 0 deletions Units/nim-ptr_field.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type
TClassOfTCustomObject {.pure, inheritable.} = object
base* : ptr TClassOfTCustomObject
className* : string
TClassOfTobj = object of TClassOfTCustomObject
nil
TCustomObject = ref object {.inheritable.}
class* : ptr TClassOfTCustomObject
TObj = ref object of TCustomObject
data: int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a newline at the end of file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no problem

4 changes: 4 additions & 0 deletions Units/nim-short_tuple.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TExport input.nim /^ TExport* = enum a, b, c$/;" e typeref:enum:TExport
a input.nim /^ TExport* = enum a, b, c$/;" r enum:TExport
b input.nim /^ TExport* = enum a, b, c$/;" r enum:TExport
c input.nim /^ TExport* = enum a, b, c$/;" r enum:TExport
2 changes: 2 additions & 0 deletions Units/nim-short_tuple.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type
TExport* = enum a, b, c
4 changes: 4 additions & 0 deletions Units/nim-test_pragma.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TColor input.nim /^ TColor {.final, header: irr, importc: "SColor".} = object$/;" o typeref:object:TColor
TDimension2d input.nim /^ TDimension2d {.final, header: irr, importc: "dimension2d".} = object$/;" o typeref:object:TDimension2d
Tvector3df input.nim /^ Tvector3df {.final, header: irr, importc: "vector3df".} = object$/;" o typeref:object:Tvector3df
irr input.nim /^ irr = "<irrlicht\/irrlicht.h>"$/;" k
20 changes: 20 additions & 0 deletions Units/nim-test_pragma.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Horrible example of how to interface with a C++ engine ... ;-)

{.link: "/usr/lib/libIrrlicht.so".}

{.emit: """
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
""".}

const
irr = "<irrlicht/irrlicht.h>"

type
TDimension2d {.final, header: irr, importc: "dimension2d".} = object
Tvector3df {.final, header: irr, importc: "vector3df".} = object
TColor {.final, header: irr, importc: "SColor".} = object
15 changes: 15 additions & 0 deletions Units/nim-tuple_again.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cATup input.nim /^var cATup, cBTup: tuple[x: int, ha: Concrete]$/;" v
cBTup input.nim /^var cATup, cBTup: tuple[x: int, ha: Concrete]$/;" u typeref:tuple:cBTup
cBTup input.nim /^var cATup, cBTup: tuple[x: int, ha: Concrete]$/;" v
check input.nim /^ check = 0$/;" v
count input.nim /^ count: seq[int]$/;" v
fannkuch input.nim /^proc fannkuch (n: int): int =$/;" p
ha input.nim /^var cATup, cBTup: tuple[x: int, ha: Concrete]$/;" n tuple:cBTup
m input.nim /^ m = n-1$/;" v
maxFlips input.nim /^ maxFlips = 0$/;" v
perm input.nim /^ perm: seq[int]$/;" v
perm1 input.nim /^ perm1: seq[int]$/;" v
r input.nim /^ r = n$/;" v
ret input.nim /^var ret: seq[tuple[name: string, a: TAny]] = @[]$/;" v
ugh input.nim /^proc ugh: seq[tuple[x: string, c: int]] =$/;" p
x input.nim /^var cATup, cBTup: tuple[x: int, ha: Concrete]$/;" n tuple:cBTup
22 changes: 22 additions & 0 deletions Units/nim-tuple_again.d/input.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var cATup, cBTup: tuple[x: int, ha: Concrete]

TAny = object
case kind: TAnyKind
of nkInt: intVal: int
of nkFloat: floatVal: float
of nkString: strVal: string

proc ugh: seq[tuple[x: string, c: int]] =
result = @[("abc", 232)]

var ret: seq[tuple[name: string, a: TAny]] = @[]

proc fannkuch (n: int): int =
var
count: seq[int]
maxFlips = 0
m = n-1
r = n
check = 0
perm1: seq[int]
perm: seq[int]
1 change: 1 addition & 0 deletions main/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
LuaParser, \
MakefileParser, \
MatLabParser, \
NimParser, \
ObjcParser, \
OcamlParser, \
PascalParser, \
Expand Down
Loading