-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.go
42 lines (35 loc) · 1.48 KB
/
token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*******************************************************************************
* Copyright (c) 2009-2023 Crater Dog Technologies™. All Rights Reserved. *
*******************************************************************************
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. *
* *
* This code is free software; you can redistribute it and/or modify it under *
* the terms of The MIT License (MIT), as published by the Open Source *
* Initiative. (See http://opensource.org/licenses/MIT) *
*******************************************************************************/
package bali
import (
fmt "fmt"
)
// TOKEN INTERFACE
// This string type is used as a type identifier for each token.
type TokenType string
// TOKEN IMPLEMENTATION
// This type defines the structure and methods for each token returned by the
// scanner.
type Token struct {
Type TokenType
Value string
Line int // The line number of the token in the input string.
Position int // The position in the line of the first rune of the token.
}
// This method returns the canonical string version of this token.
func (v Token) String() string {
var s string
if len(v.Value) > 60 {
s = fmt.Sprintf("%.60q...", v.Value)
} else {
s = fmt.Sprintf("%q", v.Value)
}
return fmt.Sprintf("Token [type: %s, line: %d, position: %d]: %s", v.Type, v.Line, v.Position, s)
}