Skip to content

Commit

Permalink
Ported over ListReader, improved SourceReader (e.g. getLocation() for…
Browse files Browse the repository at this point in the history
… tokens)
  • Loading branch information
fasterthanlime committed Sep 30, 2009
1 parent 3086ed8 commit 365fdc7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .gitignore
@@ -1,3 +1,2 @@
ooc_tmp
rock
./TestSuite
ooc_tmp
59 changes: 59 additions & 0 deletions source/frontend/ListReader.ooc
@@ -0,0 +1,59 @@
import structs/List

ListReader: class <T> {

list: List<T>
index, length, mark : SizeT

init: func (=list) {
index = 0
length = list size()
mark = 0
}

hasNext: func -> Bool {
index < length
}

read: func -> T {
val := list get(index)
index += 1
return val
}

peek: func -> T {
val := list get(index)
return val
}

prev: func -> T {
if(index < 1) return list[index]
return list[index - 1]
}

mark: func -> SizeT {
mark = index
return mark
}

reset: func {
index = mark
}

seek: func (.index) {
this index = index
}

rewind: func {
index -= 1
}

skip: func {
index += 1
}

skip: func ~withOffset (offset: SizeT) {
index += offset
}

}
2 changes: 2 additions & 0 deletions source/frontend/SourceReader.ooc
@@ -1,7 +1,9 @@
// ooc imports
import io/[Reader, FileReader, File]
import structs/[Array, ArrayList, List]
import text/StringBuffer

// rock imports
import FileLocation, Locatable

SourceReader: class extends Reader {
Expand Down

0 comments on commit 365fdc7

Please sign in to comment.