Skip to content

Commit

Permalink
Simplify regex (#44)
Browse files Browse the repository at this point in the history
* Simplify regex
  - Fixes exponential grow of possible matches crashing long lines
* Improve enumeration highlighting
  • Loading branch information
AnHeuermann authored Mar 15, 2024
1 parent 5c0bea2 commit 5625931
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
4 changes: 2 additions & 2 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.1",
"version": "1.3.2",
"publisher": "AnHeuermann",
"license": "See LICENSE.txt",
"engines": {
Expand Down
8 changes: 4 additions & 4 deletions syntaxes/metamodelica.tmGrammar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ patterns:
name: keyword.operator.arithmetic
- match: \=|\:\=
name: keyword.operator.assignment
- match: \b(algorithm|equation|protected|public|end|external|in)\b
- match: \b(algorithm|equation|protected|public|end|external|in|encapsulated)\b
name: keyword
- match: \b(matchcontinue|match|local|case|try|end matchcontinue|end match|end try)\b
name: keyword.control
Expand All @@ -85,7 +85,7 @@ patterns:
name: support.type

# Class Type
- begin: \b(record|type|package|function|uniontype)\s+(\w+)\s*((?<!\\)"([^"]*|\\")*(?<!\\)")?
- begin: \b(record|type|package|function|uniontype)\s+(\w+)\s*("([^"]|\\")*(?<!\\)")?
beginCaptures:
1:
name: keyword
Expand Down Expand Up @@ -132,10 +132,10 @@ repository:

enumeration:
patterns:
- match: \b(\w+)\b\s*((?<!\\)"([^"]*|\\")*(?<!\\)")?
- match: \b(\w+)\s*("([^"]|\\")*(?<!\\)")?
captures:
1:
name: entity.name.type
name: variable.other.enummember
2:
name: comment.line
- include: "source.modelica"
Expand Down
6 changes: 3 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 All @@ -69,7 +69,7 @@ patterns:
- include: "source.modelica"

# Function calls
- match: \b([\w|\.]+)\b\(
- match: \b(?<!\.)(\w|\w+[\.\w+]*\w)s*\(
name: entity.name.function

# Annotations
Expand Down Expand Up @@ -102,7 +102,7 @@ repository:
patterns:
- match: \b(Evaluate|version|versionDate|dateModified|HideResult|singleInstance|mustBeConnected|mayOnlyConnectOnce|Inline|LateInline)\b
name: keyword
- begin: \b(experiment)\b\s*\(
- begin: \b(experiment)\s*\(
beginCaptures:
- name: keyword
end: \)
Expand Down
22 changes: 18 additions & 4 deletions test/metamodelica/Enumeration.test.mo
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,29 @@ type FavouriteMinionFood = enumeration(
// ^ source.metamodelica keyword.operator.assignment
// ^^^^^^^^^^^ source.metamodelica storage.type.enumeration
BANANA "A banana",
//^^^^^^ source.metamodelica entity.name.type
//^^^^^^ source.metamodelica variable.other.enummember
// ^^^^^^^^^^ source.metamodelica comment.line
APPLE "An apple",
//^^^^^ source.metamodelica entity.name.type
//^^^^^ source.metamodelica variable.other.enummember
// ^^^^^^^^^^ source.metamodelica comment.line
GELATO "Ice-cream from the italian \"gelato\"",
//^^^^^^ source.metamodelica entity.name.type
//^^^^^^ source.metamodelica variable.other.enummember
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.metamodelica comment.line
PAPAYA "Wikipedia tells me the fruit is a berry. I don't agree."
//^^^^^^ source.metamodelica entity.name.type
//^^^^^^ source.metamodelica variable.other.enummember
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.metamodelica comment.line
);

type FavouriteMinionFood = enumeration(BANANA "A banana", APPLE "An apple", GELATO "Ice-cream from the italian \"gelato\"", PAPAYA "Wikipedia tells me the fruit is a berry. I don't agree.");
//<--- source.metamodelica storage.type
// ^^^^^^^^^^^^^^^^^^^ source.metamodelica entity.name.type
// ^ source.metamodelica keyword.operator.assignment
// ^^^^^^^^^^^ source.metamodelica storage.type.enumeration
// ^^^^^^ source.metamodelica variable.other.enummember
// ^^^^^^^^^^ source.metamodelica comment.line
// ^^^^^ source.metamodelica variable.other.enummember
// ^^^^^^^^^^ source.metamodelica comment.line
// ^^^^^^ source.metamodelica variable.other.enummember
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.metamodelica comment.line
// ^^^^^^ source.metamodelica variable.other.enummember
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.metamodelica comment.line
10 changes: 10 additions & 0 deletions test/metamodelica/FunctionDoc.test.mo
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ public function foo
// ^^^^^^^^^^^^^^^^^^^^^^^ source.metamodelica storage.type
// [...]
end foo;

function bar"I'm a comment"
// ^^^^^^^^^^^^^^^ source.metamodelica comment.line
end bar;

function f "Does a thing, but must be shorter than this string.
author: Author name TUD-2015-04"
input BackendDAE.Equation eq;
//^^^^^ source.metamodelica keyword.control
end f;

0 comments on commit 5625931

Please sign in to comment.