Improved visibility of token groups

This commit is contained in:
Eduard Urbach 2025-01-26 12:28:38 +01:00
parent bc8e7e452d
commit e62eaba6e6
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
2 changed files with 73 additions and 73 deletions

View File

@ -4,72 +4,72 @@ package token
type Kind uint8
const (
Invalid Kind = iota // Invalid is an invalid token.
EOF // EOF is the end of file.
NewLine // NewLine is the newline character.
Identifier // Identifier is a series of characters used to identify a variable or function.
Number // Number is a series of numerical characters.
Rune // Rune is a single unicode code point.
String // String is an uninterpreted series of characters in the source code.
Comment // Comment is a comment.
GroupStart // (
GroupEnd // )
BlockStart // {
BlockEnd // }
ArrayStart // [
ArrayEnd // ]
ReturnType // ->
_operators // <operators>
Add // +
Sub // -
Mul // *
Div // /
Mod // %
And // &
Or // |
Xor // ^
Shl // <<
Shr // >>
LogicalAnd // &&
LogicalOr // ||
_comparisons // <comparisons>
Equal // ==
NotEqual // !=
Less // <
Greater // >
LessEqual // <=
GreaterEqual // >=
_comparisonsEnd // </comparisons>
Define // :=
Period // .
Call // x()
Array // [x]
Separator // ,
_unary // <unary>
Not // ! (unary)
Negate // - (unary)
_unaryEnd // </unary>
_assignments // <assignments>
Assign // =
AddAssign // +=
SubAssign // -=
MulAssign // *=
DivAssign // /=
ModAssign // %=
AndAssign // &=
OrAssign // |=
XorAssign // ^=
ShlAssign // <<=
ShrAssign // >>=
_assignmentsEnd // </assignments>
_operatorsEnd // </operators>
_keywords // <keywords>
Assert // assert
Else // else
If // if
Import // import
Loop // loop
Return // return
Switch // switch
_keywordsEnd // </keywords>
Invalid Kind = iota // Invalid is an invalid token.
EOF // EOF is the end of file.
NewLine // NewLine is the newline character.
Identifier // Identifier is a series of characters used to identify a variable or function.
Number // Number is a series of numerical characters.
Rune // Rune is a single unicode code point.
String // String is an uninterpreted series of characters in the source code.
Comment // Comment is a comment.
GroupStart // (
GroupEnd // )
BlockStart // {
BlockEnd // }
ArrayStart // [
ArrayEnd // ]
ReturnType // ->
___OPERATORS___ // <operators>
Add // +
Sub // -
Mul // *
Div // /
Mod // %
And // &
Or // |
Xor // ^
Shl // <<
Shr // >>
LogicalAnd // &&
LogicalOr // ||
Define // :=
Period // .
Call // x()
Array // [x]
Separator // ,
___ASSIGNMENTS___ // <assignments>
Assign // =
AddAssign // +=
SubAssign // -=
MulAssign // *=
DivAssign // /=
ModAssign // %=
AndAssign // &=
OrAssign // |=
XorAssign // ^=
ShlAssign // <<=
ShrAssign // >>=
___END_ASSIGNMENTS___ // </assignments>
___COMPARISONS___ // <comparisons>
Equal // ==
NotEqual // !=
Less // <
Greater // >
LessEqual // <=
GreaterEqual // >=
___END_COMPARISONS___ // </comparisons>
___UNARY___ // <unary>
Not // ! (unary)
Negate // - (unary)
___END_UNARY___ // </unary>
___END_OPERATORS___ // </operators>
___KEYWORDS___ // <keywords>
Assert // assert
Else // else
If // if
Import // import
Loop // loop
Return // return
Switch // switch
___END_KEYWORDS___ // </keywords>
)

View File

@ -25,12 +25,12 @@ func (t Token) End() Position {
// IsAssignment returns true if the token is an assignment operator.
func (t Token) IsAssignment() bool {
return t.Kind > _assignments && t.Kind < _assignmentsEnd
return t.Kind > ___ASSIGNMENTS___ && t.Kind < ___END_ASSIGNMENTS___
}
// IsComparison returns true if the token is a comparison operator.
func (t Token) IsComparison() bool {
return t.Kind > _comparisons && t.Kind < _comparisonsEnd
return t.Kind > ___COMPARISONS___ && t.Kind < ___END_COMPARISONS___
}
// IsExpressionStart returns true if the token starts an expression.
@ -40,7 +40,7 @@ func (t Token) IsExpressionStart() bool {
// IsKeyword returns true if the token is a keyword.
func (t Token) IsKeyword() bool {
return t.Kind > _keywords && t.Kind < _keywordsEnd
return t.Kind > ___KEYWORDS___ && t.Kind < ___END_KEYWORDS___
}
// IsNumeric returns true if the token is a number or rune.
@ -50,12 +50,12 @@ func (t Token) IsNumeric() bool {
// IsOperator returns true if the token is an operator.
func (t Token) IsOperator() bool {
return t.Kind > _operators && t.Kind < _operatorsEnd
return t.Kind > ___OPERATORS___ && t.Kind < ___END_OPERATORS___
}
// IsUnaryOperator returns true if the token is a unary operator.
func (t Token) IsUnaryOperator() bool {
return t.Kind > _unary && t.Kind < _unaryEnd
return t.Kind > ___UNARY___ && t.Kind < ___END_UNARY___
}
// Reset resets the token to default values.