Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumeration an Type declarations #43

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions syntaxes/metamodelica.tmGrammar.yaml
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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