mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-08 14:03:23 +00:00
Adds skMethod example to idetools api test.
This commit is contained in:
@@ -21,3 +21,23 @@ type
|
||||
|
||||
proc adder(a, b: int): int =
|
||||
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.
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user