Skip to content

Commit

Permalink
Enumeration an Type declarations (#43)
Browse files Browse the repository at this point in the history
* Highlight metamodelica enumerations
* Handling type declarations
  • Loading branch information
AnHeuermann authored Mar 15, 2024
1 parent 0355079 commit 5c0bea2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
31 changes: 31 additions & 0 deletions syntaxes/metamodelica.tmGrammar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,28 @@ patterns:
name: constant.numeric

# Storage
## Enumeration
- begin: \b(enumeration)\b\s*\(
beginCaptures:
1:
name: storage.type.enumeration
end: \)\s*;
patterns:
- include: '#enumeration'

## Type declaration
- match: \b(type)\b\s+\b(\w+)\b\s+(=)
captures:
1:
name: storage.type
2:
name: entity.name.type
3:
name: keyword.operator.assignment

- match: \b(Real|Integer|Boolean|String|enumeration|type)\b
name: storage.type

## Variability Prefix
- match: \b(parameter|constant)\b
name: storage.modifier
Expand Down Expand Up @@ -110,4 +130,15 @@ repository:
match: '\\(x\h{2}|[0-2][0-7]{0,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)'
name: constant.character.escape

enumeration:
patterns:
- match: \b(\w+)\b\s*((?<!\\)"([^"]*|\\")*(?<!\\)")?
captures:
1:
name: entity.name.type
2:
name: comment.line
- include: "source.modelica"


scopeName: source.metamodelica
20 changes: 20 additions & 0 deletions test/metamodelica/Enumeration.test.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SYNTAX TEST "source.metamodelica" "Enumeration"

type FavouriteMinionFood = enumeration(
//<--- source.metamodelica storage.type
// ^^^^^^^^^^^^^^^^^^^ source.metamodelica entity.name.type
// ^ source.metamodelica keyword.operator.assignment
// ^^^^^^^^^^^ source.metamodelica storage.type.enumeration
BANANA "A banana",
//^^^^^^ source.metamodelica entity.name.type
// ^^^^^^^^^^ source.metamodelica comment.line
APPLE "An apple",
//^^^^^ source.metamodelica entity.name.type
// ^^^^^^^^^^ source.metamodelica comment.line
GELATO "Ice-cream from the italian \"gelato\"",
//^^^^^^ source.metamodelica entity.name.type
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.metamodelica comment.line
PAPAYA "Wikipedia tells me the fruit is a berry. I don't agree."
//^^^^^^ source.metamodelica entity.name.type
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.metamodelica comment.line
);
6 changes: 3 additions & 3 deletions test/modelica/Comments.test.mo
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ model M "Documentation"
// ^^^^^^^^^^^^^ source.modelica comment.line
String z2 = "hello";
// ^^^^^^^ source.modelica string.quoted.double
Foo foo(x=1) "Variable foo";
// ^^^ source.modelica entity.name.function
// ^^^^^^^^^^^^^^ source.modelica comment.line
Foo f = foo(x=1) "Variable foo";
// ^^^ source.modelica entity.name.function
// ^^^^^^^^^^^^^^ source.modelica comment.line
Real a = foo("hello") "Function foo";
// ^^^ source.modelica entity.name.function
// ^^^^^^^ source.modelica string.quoted.double
Expand Down

0 comments on commit 5c0bea2

Please sign in to comment.