Create cursor.nim

This commit is contained in:
witer33 2020-11-02 19:01:33 +01:00 committed by GitHub
parent 3c74721e31
commit b8864a58b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

21
src/cursor.nim Normal file
View File

@ -0,0 +1,21 @@
import types
type Cursor* = ref object of RootObj
data*: seq[Token]
index: int
method go_to*(this: Cursor, index: int) {.base.} =
this.index = index
method get_index*(this: Cursor): int {.base.} =
return this.index
method next*(this: Cursor): Token {.base.} =
if this.index < len(this.data):
inc this.index
return this.data[this.index - 1]
iterator iter*(this: Cursor): Token =
while this.index < len(this.data):
inc this.index
yield this.data[this.index - 1]