egametang/ET · error · Exception

condition token error at {this.index}: {c}

Error message

condition token error at {this.index}: {c}

What it means

Thrown by ConditionExprLexer.ReadOperator in its default case when the current character is not one of the recognized operator/punctuation chars (>, <, =, !, &, |, (, ), :, ,). Any other glyph the lexer cannot tokenize aborts tokenization with the offending index and character.

Source

Thrown at Packages/cn.etetet.conditionexpr/Scripts/Model/Share/ConditionExprLexer.cs:117

                    return;
                case '(':
                    this.tokens.Add(new ConditionToken(ConditionTokenType.LeftParen, "(", 0));
                    ++this.index;
                    return;
                case ')':
                    this.tokens.Add(new ConditionToken(ConditionTokenType.RightParen, ")", 0));
                    ++this.index;
                    return;
                case ':':
                    this.tokens.Add(new ConditionToken(ConditionTokenType.Colon, ":", 0));
                    ++this.index;
                    return;
                case ',':
                    this.tokens.Add(new ConditionToken(ConditionTokenType.Comma, ",", 0));
                    ++this.index;
                    return;
                default:
                    throw new Exception($"condition token error at {this.index}: {c}");
            }
        }

        private void AddIfNext(char next, ConditionTokenType matchType, ConditionTokenType singleType)
        {
            char c = this.expr[this.index];
            if (this.index + 1 < this.expr.Length && this.expr[this.index + 1] == next)
            {
                this.tokens.Add(new ConditionToken(matchType, $"{c}{next}", 0));
                this.index += 2;
                return;
            }

            this.tokens.Add(new ConditionToken(singleType, c.ToString(), 0));
            ++this.index;
        }

        private void ExpectNext(char next, ConditionTokenType tokenType)

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Remove or replace the unsupported character in the condition expression.
  2. Check for full-width/CJK punctuation and replace with ASCII equivalents.
  3. Remove trailing semicolons or stray symbols copied from documents.
  4. Validate expression strings with the lexer at config-import time to surface the bad index/char early.

Example fix

// before (expression cell)
//   HP >= 50;
// after
//   HP >= 50
Defensive patterns

Strategy: validation

Validate before calling

// At config import, tokenize every expression and surface lexer errors with index/char:
try { new ConditionExprLexer(expr).Tokenize(); }
catch (Exception e) { Log.Error($"bad expr '{expr}': {e.Message}"); }

Type guard

// Reject expressions containing characters outside the allowed set before runtime.
static readonly HashSet<char> Allowed = new("><=!&|():,");
static bool HasOnlyAllowedChars(string expr, out int badIdx, out char badChar)

Prevention

When it happens

Trigger: A condition expression contains an unsupported character such as @, #, $, %, ;, +, -, *, /, [, ], or a non-ASCII symbol. For example 'HP >= 50;' (trailing semicolon) or 'A & B' using a single ampersand where '&&' is required (single & is handled, but stray symbols are not).

Common situations: Copy-paste from a rich-text/Excel source that inserted special characters; a trailing semicolon or stray whitespace-like glyph; an attempt to use arithmetic (+, -, *, /) which the grammar does not support; a full-width (CJK) punctuation character.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/8ace598b56008874. Report an issue: GitHub.