mirror of https://github.com/witer33/nhtp.git
Create cursor.nim
This commit is contained in:
parent
3c74721e31
commit
b8864a58b1
|
@ -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]
|
Loading…
Reference in New Issue