Skip to content

Commit

Permalink
Fix runaway regex in comment string detection (#42)
Browse files Browse the repository at this point in the history
* Fix runaway regex in comment string detection
* Adding tests
* Update version

---------

Co-authored-by: AnHeuermann <[email protected]>
  • Loading branch information
phannebohm and AnHeuermann authored Mar 15, 2024
1 parent 74d508e commit 0355079
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"group": "test",
"presentation": {
"reveal": "always",
"panel": "new",
"panel": "dedicated",
},
"problemMatcher": {
"owner": "vscode-tmgrammar-test",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ for more details on the publishing process.
npm install
```

Translate the `*tmGrammar.yaml` files to `*.tmGrammar.json` JSON files.
Translate the `*.tmGrammar.yaml` files to `*.tmGrammar.json` JSON files.
Start build task (Ctrl+Shift+B)

```bash
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "metamodelica",
"displayName": "MetaModelica",
"description": "MetaModelica, Susan and Modelica language support.",
"version": "1.3.0",
"version": "1.3.1",
"publisher": "AnHeuermann",
"license": "See LICENSE.txt",
"engines": {
Expand Down
6 changes: 4 additions & 2 deletions syntaxes/metamodelica.tmGrammar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ patterns:
- name: keyword
end: \)\s*;

# Strings
- match: (?<![=+]\s*)((?<!\\)"([^"]*|\\")*(?<!\\)")\s*;
# Documentation Strings
- match: (?<![=+]\s*)((?<!\\)"([^"]|\\")*(?<!\\)")\s*;
captures:
1:
name: comment.line

# Strings
- begin: \"
end: \"
name: string.quoted.double
Expand Down
8 changes: 5 additions & 3 deletions syntaxes/modelica.tmGrammar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ patterns:
name: support.type

# Class definitions
- begin: \b(model|class|record|block|package|function)\s+(\w+)\s*((?<!\\)"([^"]*|\\")*(?<!\\)")?
- begin: \b(model|class|record|block|package|function)\s+(\w+)\s*((?<!\\)"([^"]|\\")*(?<!\\)")?
beginCaptures:
1:
name: keyword
Expand Down Expand Up @@ -80,11 +80,13 @@ patterns:
patterns:
- include: '#annotations'

# Strings
- match: (?<![=+]\s*)((?<!\\)"([^"]*|\\")*(?<!\\)")\s*;
# Documentation Strings
- match: (?<![=+]\s*)((?<!\\)"([^"]|\\")*(?<!\\)")\s*;
captures:
1:
name: comment.line

# Strings
- begin: \"
end: \"
name: string.quoted.double
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions test/metamodelica/FunctionDoc.test.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SYNTAX TEST "source.metamodelica" "Function with doc string"

public function foo
"Function does crazy stuff --fmiFlags
and creates an awesome record for stuff.
Author: ItIsI"
input Boolean isAwesome = true;
//^^^^^ source.metamodelica keyword.control
// ^^^^^^^ source.metamodelica storage.type
// ^^^^ source.metamodelica constant.language
output Option<SimCode.Awesome> awesome;
//^^^^^^ source.metamodelica keyword.control
// ^^^^^^^^^^^^^^^^^^^^^^^ source.metamodelica storage.type
// [...]
end foo;
4 changes: 4 additions & 0 deletions test/modelica/Comments.test.mo
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SYNTAX TEST "source.modelica" "Comments"

model M "Documentation"
//<-- source.modelica keyword
// ^ source.modelica entity.name.type
// ^^^^^^^^^^^^^^^ source.modelica comment.line
Real x "Variable \"x\"";
// ^^^^^^^^^^^^^^^^ source.modelica comment.line
Expand Down Expand Up @@ -28,3 +30,5 @@ model M "Documentation"
// ^^^ source.modelica string.quoted.double
// ^^^ source.modelica string.quoted.double
end M;
//<-- source.modelica keyword
// ^ source.modelica entity.name.type
18 changes: 18 additions & 0 deletions test/modelica/Function.test.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SYNTAX TEST "source.modelica" "Function with doc string"

public function foo
"Function does crazy stuff --fmiFlags
and creates an awesome record for stuff.
Author: ItIsI"
input Boolean isAwesome = true;
//^^^^^ source.modelica keyword.control
// ^^^^^^^ source.modelica storage.type
// ^^^^ source.modelica constant.language
output MyRecord awesome;
//^^^^^^ source.modelica keyword.control
// [...]
//<--- source.modelica comment.line
//^^^^^^ source.modelica comment.line
end foo;
//<--- source.modelica keyword
// ^^^ source.modelica entity.name.type

0 comments on commit 0355079

Please sign in to comment.