Skip to content

About

Check TorqueScript compiles under the Tribes 2 engine's own lexer and parser tables

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

tscheck: TorqueScript compile check for Tribes 2

tscheck tells you whether TorqueScript will compile in Tribes 2, and on which line the engine will report the error if it won't. It does not approximate the language. It runs the engine's own lexer DFA and LALR parser tables, extracted from Tribes2.exe, so its verdict is the engine's verdict. It needs nothing but Python 3.10+: no game install, no Wine, no dependencies. It runs anywhere, including GitHub's Linux runners.

$ tscheck scripts/
scripts/warden/ui.cs:212: error: Syntax error: unexpected variable '%row'
scripts/autoexec/broken.cs:1: error: Syntax error: unexpected illegal token '\xef' (the file starts with a UTF-8 byte-order mark, which the engine cannot read; save it without BOM)
tscheck: 14 file(s) checked, 2 failed (2 error(s), 0 warning(s))

The line numbers are the ones Tribes 2 prints (<file> Line: N - Syntax error.), including its quirks: a file with CR-only line endings reports everything as line 1, exactly as the engine does.

Use it in a repository

GitHub Actions

# .github/workflows/torquescript.yml
name: TorqueScript
on: [push, pull_request]
jobs:
  compile:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: Tribes2-Community/torquescript-check@v1
        with:
          paths: src          # default "."
          # exclude: "vendor/*"
          # extensions: ".cs .gui .mis"
          # vl2: "true"       # also check scripts inside .vl2 archives
          # strict: "true"    # warnings fail the build too

Errors appear as annotations on the offending lines of the pull request.

pre-commit

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/Tribes2-Community/torquescript-check
    rev: v0.1.0
    hooks:
      - id: tscheck

Command line

pip install git+https://github.com/Tribes2-Community/torquescript-check
tscheck [paths...] [--ext .cs] [--exclude 'glob'] [--vl2] [--strict] [--format text|github|json]

Or without installing: python -m tscheck ... from a checkout. Exit status is 1 when any file fails, or when a path does not exist.

By default it checks .cs, .gui and .mis files under the given paths (the current directory if none), skipping .git, node_modules and virtualenvs.

What it reports

Errors (the engine will not compile the file):

  • Syntax errors, at the engine's line. The engine stops at the first one, so there is at most one per file.
  • Parser stack overflow: nesting too deep for the engine's 350-entry stack. The limits are 344 nested parentheses, and 56 nested if blocks inside a function.
  • Tokens of 4096 bytes or more: a string, a // comment line, a name, or even a run of whitespace. The engine does not just reject these: it exits with CMDlex: Token buffer overflow.

Warnings (it compiles, but not as written):

  • A NUL byte: the engine stops reading the file there and ignores the rest.
  • A byte that matches no lexer rule: the engine silently drops it.
  • An invalid escape (\x without two hex digits, \c followed by anything but 0–9, r, p, o): the engine treats the string as the end of the file. This almost always also produces an error.
  • CR-only line endings, which make every error line 1.

Tribes 2 is not TGE or Torque3D

These parse in later Torque engines but fail in Tribes 2. Each was confirmed against the real engine:

construct
/* block comments */ only // exists
do { } while (...) no do keyword
for (;;), for (%i = 0; %i < n;) all three clauses are required
{ ... } as a statement on its own no bare blocks; braces only after if, while, etc.
.5, 5. write 0.5, 5.0 (1.5e3 and 0xAB are fine)
++%i; only postfix %i++
new ScriptObject; needs parentheses: new ScriptObject()
new X(Name : Parent), datablock X(Name : Parent) use datablock X(Name) : Parent
%obj.datablock = 1;, a field named new or function in an object body keywords are not field names (datablock = ... inside a new {} body is the one exception)
UTF-8 BOM at the start of a file the engine sees it as illegal characters
a string spanning lines unterminated string

These do work, and surprise people the other way: case 1 or 2:, $a:b as a global name, !%x = f() (meaning !(%x = f())), %a[1,2], 'tagged strings', switch$.

How it works, and how it is verified

tools/extract_tables.py reads the tables out of Tribes2.exe (md5 188cbf910fa40e56b7c9382113e15cc9, shared by stock 25034, TribesNext and QOL installs) into tscheck/data/tribes2.json. tscheck/engine.py drives them the way the engine's yylex and yyparse do. docs/tables.md records every address and layout.

tools/oracle.py asks the real engine: it copies Tribes2.exe into a private sandbox, runs it dedicated with a console_start.cs that calls compile() on each file, and reads the verdicts from console.log. tools/difftest.py runs both over a corpus plus generated mutants and reports any disagreement. On 1002 real scripts and 4008 mutants, and on 679 edge-case files and 2037 mutants, they agree on every verdict and every error line. tests/ holds a golden subset with the engine's recorded verdicts, so this repository's CI runs without the engine:

python -m unittest discover -s tests
python tools/difftest.py --engine C:/Dynamix/Tribes2/GameData --mutants 4 <dirs or .vl2s>

Scope

Syntax only, which is exactly what compile()/exec() decide. tscheck does not know about undefined functions, wrong argument counts, or runtime errors, because the engine does not check those at compile time either.

License

MIT. See LICENSE.

About

Check TorqueScript compiles under the Tribes 2 engine's own lexer and parser tables

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages