Skip to content

Multiple Issues in Brian TextMate Grammar #15

Description

@anshiq

Overview

There are Several bugs and gaps I have found in the current Brian TextMate grammar file that affect syntax highlighting correctness.


Issues I have Found

1. Typo — Silent rule failure in equations_lhs

Location: equations_lhs → patterns

// Current (broken)
"inclide": "#after_colon"

// Should be
"include": "#after_colon"

The after_colon rule never executes inside equations_lhs due to this typo. Units, flags, and anything after : on the LHS are silently unmatched.


2. Weak differential equation parsing

Location: variable_definition

The current regex d[a-zA-Z_][a-zA-Z0-9_]*/dt is too loose — it does not use word boundaries, meaning it can partially match inside longer identifiers. For example, a variable like update/dt could produce a false match on the d in update.

Suggested fix: Use \bd[a-zA-Z_][a-zA-Z0-9_]*\/dt\b with explicit word boundaries (If I am correct).


3. Missing common Brian2/math builtin functions

( I found on docs )
Location: functions repository entry

The current grammar only matches exp and exprel. The following commonly used Brian2 and math functions are not highlighted at all:

Category Missing functions
Trigonometric sin, cos, tan, sinh, cosh, tanh
Inverse trig arcsin, arccos, arctan, arcsinh, arccosh, arctanh
Logarithmic log, log10, log1p, expm1
Array/utility arange, linspace, where, clip, dot, diagonal, trace, ravel, ptp, ones_like

4. Typo in scope name — mata instead of meta

Location: functions repository entry

// Current (broken)
"name": "mata.function-call.brian"

// Should be
"name": "meta.function-call.brian"

This typo means function tokens receive an invalid scope name, which prevents any theme from styling them correctly.


5. Pattern ordering issues

Location: operators patterns

The * operator is matched before **, and *= before **=. In TextMate grammars, the first matching pattern wins, so ** gets tokenized as two separate * tokens instead of a single exponentiation operator.

Fix: ** and **= must appear before * and *= in the pattern list.


I would like to prepare a pr to fix these issues. And also I am exploring code, will raise another issue If I found one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions