Adds skMethod example to idetools api test.
This commit is contained in:
parent
281424dded
commit
c7a4412f8a
2 changed files with 23 additions and 0 deletions
|
|
@ -21,3 +21,23 @@ type
|
||||||
|
|
||||||
proc adder(a, b: int): int =
|
proc adder(a, b: int): int =
|
||||||
result = a + b
|
result = a + b
|
||||||
|
|
||||||
|
type
|
||||||
|
PExpr = ref object of TObject ## abstract base class for an expression
|
||||||
|
PLiteral = ref object of PExpr
|
||||||
|
x: int
|
||||||
|
PPlusExpr = ref object of PExpr
|
||||||
|
a, b: PExpr
|
||||||
|
|
||||||
|
# watch out: 'eval' relies on dynamic binding
|
||||||
|
method eval(e: PExpr): int =
|
||||||
|
# override this base method
|
||||||
|
quit "to override!"
|
||||||
|
|
||||||
|
method eval(e: PLiteral): int = e.x
|
||||||
|
method eval(e: PPlusExpr): int = eval(e.a) + eval(e.b)
|
||||||
|
|
||||||
|
proc newLit(x: int): PLiteral = PLiteral(x: x)
|
||||||
|
proc newPlus(a, b: PExpr): PPlusExpr = PPlusExpr(a: a, b: b)
|
||||||
|
|
||||||
|
echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4)))
|
||||||
|
|
|
||||||
|
|
@ -39,3 +39,6 @@ def\tskResult\tidetools_api.adder.result\tint
|
||||||
|
|
||||||
# ProcRun mode will fail the next line, because the type is returned empty.
|
# ProcRun mode will fail the next line, because the type is returned empty.
|
||||||
def\tskField\tidetools_api.TPerson.name\tbad_string\t
|
def\tskField\tidetools_api.TPerson.name\tbad_string\t
|
||||||
|
|
||||||
|
> idetools --track:idetools_api.nim,43,7 --def
|
||||||
|
def\tskMethod\tidetools_api.eval\tproc \(PPlusExpr\): int\t
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue