Improved instruction parser

This commit is contained in:
Eduard Urbach 2024-06-15 14:46:44 +02:00
parent a4ecaf0622
commit 78cde0d0bd
Signed by: eduard
GPG key ID: 49226B848C78F6C8
7 changed files with 114 additions and 54 deletions

View file

@ -1,5 +1,7 @@
package token
import "fmt"
// Token represents a single element in a source file.
// The characters that make up an identifier are grouped into a single token.
// This makes parsing easier and allows us to do better syntax checks.
@ -9,6 +11,11 @@ type Token struct {
Bytes []byte
}
// String creates a human readable representation for debugging purposes.
func (t Token) String() string {
return fmt.Sprintf("%s %s", t.Kind, t.Text())
}
// Text returns the token text.
func (t Token) Text() string {
return string(t.Bytes)