From e62eaba6e62908f4b39d0faef0b7f6b5e0c38548 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 26 Jan 2025 12:28:38 +0100 Subject: [PATCH] Improved visibility of token groups --- src/token/Kind.go | 136 ++++++++++++++++++++++----------------------- src/token/Token.go | 10 ++-- 2 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/token/Kind.go b/src/token/Kind.go index e0c23f8..737ef55 100644 --- a/src/token/Kind.go +++ b/src/token/Kind.go @@ -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 // - Add // + - Sub // - - Mul // * - Div // / - Mod // % - And // & - Or // | - Xor // ^ - Shl // << - Shr // >> - LogicalAnd // && - LogicalOr // || - _comparisons // - Equal // == - NotEqual // != - Less // < - Greater // > - LessEqual // <= - GreaterEqual // >= - _comparisonsEnd // - Define // := - Period // . - Call // x() - Array // [x] - Separator // , - _unary // - Not // ! (unary) - Negate // - (unary) - _unaryEnd // - _assignments // - Assign // = - AddAssign // += - SubAssign // -= - MulAssign // *= - DivAssign // /= - ModAssign // %= - AndAssign // &= - OrAssign // |= - XorAssign // ^= - ShlAssign // <<= - ShrAssign // >>= - _assignmentsEnd // - _operatorsEnd // - _keywords // - Assert // assert - Else // else - If // if - Import // import - Loop // loop - Return // return - Switch // switch - _keywordsEnd // + 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___ // + Add // + + Sub // - + Mul // * + Div // / + Mod // % + And // & + Or // | + Xor // ^ + Shl // << + Shr // >> + LogicalAnd // && + LogicalOr // || + Define // := + Period // . + Call // x() + Array // [x] + Separator // , + ___ASSIGNMENTS___ // + Assign // = + AddAssign // += + SubAssign // -= + MulAssign // *= + DivAssign // /= + ModAssign // %= + AndAssign // &= + OrAssign // |= + XorAssign // ^= + ShlAssign // <<= + ShrAssign // >>= + ___END_ASSIGNMENTS___ // + ___COMPARISONS___ // + Equal // == + NotEqual // != + Less // < + Greater // > + LessEqual // <= + GreaterEqual // >= + ___END_COMPARISONS___ // + ___UNARY___ // + Not // ! (unary) + Negate // - (unary) + ___END_UNARY___ // + ___END_OPERATORS___ // + ___KEYWORDS___ // + Assert // assert + Else // else + If // if + Import // import + Loop // loop + Return // return + Switch // switch + ___END_KEYWORDS___ // ) diff --git a/src/token/Token.go b/src/token/Token.go index 0476cbd..69e7e83 100644 --- a/src/token/Token.go +++ b/src/token/Token.go @@ -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.