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

View File

@ -25,12 +25,12 @@ func (t Token) End() Position {
// IsAssignment returns true if the token is an assignment operator. // IsAssignment returns true if the token is an assignment operator.
func (t Token) IsAssignment() bool { 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. // IsComparison returns true if the token is a comparison operator.
func (t Token) IsComparison() bool { 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. // 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. // IsKeyword returns true if the token is a keyword.
func (t Token) IsKeyword() bool { 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. // 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. // IsOperator returns true if the token is an operator.
func (t Token) IsOperator() bool { 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. // IsUnaryOperator returns true if the token is a unary operator.
func (t Token) IsUnaryOperator() bool { 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. // Reset resets the token to default values.