Implemented block instruction parsing
This commit is contained in:
@ -3,4 +3,5 @@ package token
|
||||
// Keywords defines the keywords used in the language.
|
||||
var Keywords = map[string]bool{
|
||||
"return": true,
|
||||
"loop": true,
|
||||
}
|
||||
|
@ -7,6 +7,28 @@ import (
|
||||
// List is a slice of tokens.
|
||||
type List []Token
|
||||
|
||||
// IndexKind returns the position of a token kind within a token list.
|
||||
func (list List) IndexKind(kind Kind) int {
|
||||
for i, token := range list {
|
||||
if token.Kind == kind {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
// LastIndexKind returns the position of the last token kind within a token list.
|
||||
func (list List) LastIndexKind(kind Kind) int {
|
||||
for i := len(list) - 1; i >= 0; i-- {
|
||||
if list[i].Kind == kind {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
// String implements string serialization.
|
||||
func (list List) String() string {
|
||||
builder := bytes.Buffer{}
|
||||
|
@ -11,8 +11,8 @@ type Token struct {
|
||||
Bytes []byte
|
||||
}
|
||||
|
||||
// After returns the position after the token.
|
||||
func (t *Token) After() int {
|
||||
// End returns the position after the token.
|
||||
func (t *Token) End() int {
|
||||
return t.Position + len(t.Bytes)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user