Skip to content

Fix: Add syntax highlighting for model= named arguments in NeuronGroup/Synapses#12

Open
Mohamed-Sobea wants to merge 2 commits into
brian-team:mainfrom
Mohamed-Sobea:fix/issue-11-model-syntax
Open

Fix: Add syntax highlighting for model= named arguments in NeuronGroup/Synapses#12
Mohamed-Sobea wants to merge 2 commits into
brian-team:mainfrom
Mohamed-Sobea:fix/issue-11-model-syntax

Conversation

@Mohamed-Sobea
Copy link
Copy Markdown

This PR implements the first part of the fix for Issue #11 by adding support for named arguments (model=).

I have updated brian.injection.json to correctly trigger the source.brian scope when equations are passed via the keyword argument.

Technical Details:

Handles all four Python string quote types (""", ''', ", ').

Accounts for the spurious whitespace you mentioned (e.g., model = "..." vs model="...").

Uses negative lookbehinds (?<!\) to ensure escaped quotes inside the equations don't accidentally break the highlighting scope.

(Note: I have left a comment on the main issue thread regarding my findings on the positional arguments and the AST approach)

Screenshot of working tests:

image

@mstimberg
Copy link
Copy Markdown
Member

Hi @Mohamed-Sobea, thanks for the PR. I did not yet look at it in detail, but just one small remark:

Uses negative lookbehinds (?<!) to ensure escaped quotes inside the equations don't accidentally break the highlighting scope.

Equations cannot contain any quotes (escaped or not), so I don't think we need to account for this possibility.

@Mohamed-Sobea
Copy link
Copy Markdown
Author

Hi @Mohamed-Sobea, thanks for the PR. I did not yet look at it in detail, but just one small remark:

Uses negative lookbehinds (?<!) to ensure escaped quotes inside the equations don't accidentally break the highlighting scope.

Equations cannot contain any quotes (escaped or not), so I don't think we need to account for this possibility.

Ah that makes sense. I was applying general Python string parsing rules and didn't consider that valid Brian mathematical equations wouldn't contain string literals/quotes in the first place.
I have removed the lookbehinds to keep the Regex cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants