diff --git a/syntaxes/metamodelica.tmGrammar.yaml b/syntaxes/metamodelica.tmGrammar.yaml index fb10b27..69ba3b0 100644 --- a/syntaxes/metamodelica.tmGrammar.yaml +++ b/syntaxes/metamodelica.tmGrammar.yaml @@ -3,7 +3,27 @@ fileTypes: name: MetaModelica patterns: + # Comments + - begin: /\* + end: \*/ + name: comment.block + - match: (//).*$\n? + name: comment.line + + # Constants + - match: \b(true|false)\b + name: constant.language + - match: \b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)\b + name: constant.numeric + # Storage + - match: \b(Real|Integer|Boolean|String|enumeration|type)\b + name: storage.type + ## Variability Prefix + - match: \b(parameter|constant)\b + name: storage.modifier + - match: \b(replaceable|redeclare|import)\b + name: storage.modifier - begin: \b(list<|Option<|tuple<)\b end: '>' name: storage.type @@ -17,8 +37,75 @@ patterns: name: string.quoted.double # Keywords + - match: \b(for|if|when|while|then|loop|end if|end when|end for|end while|else|elsewhen|break|return|each|elseif|input|output)\b + name: keyword.control + - match: \b(and|or|not)\b + name: keyword.control + - match: <|<\=|>|>\=|\=\=|<> + name: keyword.operator.comparison + - match: \+|\-|\.\+|\.\-|\*|\.\*|/|\./|\^ + name: keyword.operator.arithmetic + - match: \=|\:\= + name: keyword.operator.assignment + - match: \b(algorithm|equation|protected|public|end|external|in)\b + name: keyword - match: \b(matchcontinue|match|local|case|try|end matchcontinue|end match|end try)\b name: keyword.control - - include: source.modelica + # Support + - match: \b(acos|asin|atan|atan2|cos|cosh|exp|log|log10|sin|sinh|tan|tanh|abs|sign|sqrt|max|min|product|sum)\b + name: support.function.mathematical + - match: \b(scalar|vector|matrix|identity|diagonal|zeros|ones|fill|linspace|transpose|outerProduct|symmetric|cross|skew)\b + name: support.function.array + - match: \b(ceil|div|fill|floor|integer|max|min|mod|rem|pre|noEvent|change|edge|initial|terminal|reinit|sample|smooth|terminate)\b + name: support.function.event + - match: \b(connect|der|inStream|actualStream|semiLinear|spatialDistribution|getInstanceName|homotopy|delay|assert|ndims|size|cardinality|isPresent)\b + name: support.function.special + - match: \b(extends|partial|within)\b + name: support.type + + # Class Type + - begin: \b(record|type|package|function|uniontype)\s+(\w+)\s*((? x; +//^^^^^ source.metamodelica keyword.control +// ^^^^^^^^^^ source.metamodelica storage.type + output list y = {}; +//^^^^^^ source.metamodelica keyword.control +// ^^^^^^^^^^^^^ storage.type +// ^ source.metamodelica keyword.operator.assignment +algorithm +//<-- source.metamodelica keyword + _ := match x +// ^^ source.metamodelica keyword.operator.assignment +// ^^^^^ keyword.control + local +// ^^^^^ keyword.control + Real yi; +// ^^^^ source.metamodelica storage.type + case {} algorithm +// ^^^^ keyword.control +// ^^^^^^^^^ source.metamodelica keyword + Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed."}); +// ^^^^^^^^^^^^^^^^ source.metamodelica entity.name.function +// ^^^^^^^^^^^^^^^ source.metamodelica support.function.special +// ^^^^^^^^^^ source.metamodelica string.quoted.double + then (); +// ^^^^ source.metamodelica keyword.control + else algorithm +// ^^^^ source.metamodelica keyword.control +// ^^^^^^^^^ source.metamodelica keyword + for xi in x loop +// ^^^ source.metamodelica keyword.control +// ^^ source.metamodelica keyword +// ^^^^ source.metamodelica keyword.control + y := xi::y; +// ^^ source.metamodelica keyword.operator.assignment + end for; +// ^^^^^^^ source.metamodelica keyword.control + then (); +// ^^^^ source.metamodelica keyword.control + end match; +//^^^ source.metamodelica keyword +// ^^^^ source.metamodelica keyword.control +end myMetaModelicaFunction; +//<--- source.metamodelica keyword +// ^^^^^^^^^^^^^^^^^^^^^^ source.metamodelica entity.name.type diff --git a/test/modelica/Class.test.mo b/test/modelica/Class.test.mo index 9b6bf9a..afb887f 100644 --- a/test/modelica/Class.test.mo +++ b/test/modelica/Class.test.mo @@ -1,8 +1,8 @@ // SYNTAX TEST "source.modelica" "Class" model MyModel -//<---keyword -// ^^^^^^^ entity.name.type +//<--- source.modelica keyword +// ^^^^^^^ source.modelica entity.name.type end MyModel; -//<---keyword -// ^^^^^^^ entity.name.type +//<--- source.modelica keyword +// ^^^^^^^ source.modelica entity.name.type diff --git a/test/modelica/Comments.test.mo b/test/modelica/Comments.test.mo index 07eb1cd..0cf3578 100644 --- a/test/modelica/Comments.test.mo +++ b/test/modelica/Comments.test.mo @@ -1,27 +1,30 @@ // SYNTAX TEST "source.modelica" "Comments" model M "Documentation" -// ^^^^^^^^^^^^^^^ comment.line +// ^^^^^^^^^^^^^^^ source.modelica comment.line Real x "Variable \"x\""; -// ^^^^^^^^^^^^ comment.line +// ^^^^^^^^^^^^^^^^ source.modelica comment.line Real y = 1.0 "Variable y"; -// ^^^^^^^^^^^^ comment.line +// ^^^^^^^^^^^^ source.modelica comment.line String z1 = "hello" "Variable z1"; -// ^^^^^^^^^^^^^ comment.line +// ^^^^^^^^^^^^^ source.modelica comment.line String z2 = "hello"; -// ^^^^^^^ string.quoted.double +// ^^^^^^^ source.modelica string.quoted.double Foo foo(x=1) "Variable foo"; -// ^^^^^^^^^^^^^^ comment.line +// ^^^ source.modelica entity.name.function +// ^^^^^^^^^^^^^^ source.modelica comment.line Real a = foo("hello") "Function foo"; -// ^^^^^^^ string.quoted.double -// ^^^^^^^^^^^^^^ comment.line +// ^^^ source.modelica entity.name.function +// ^^^^^^^ source.modelica string.quoted.double +// ^^^^^^^^^^^^^^ source.modelica comment.line Real b = bar("hello"); -// ^^^^^^^ string.quoted.double +// ^^^ source.modelica entity.name.function +// ^^^^^^^ source.modelica string.quoted.double String v = "a" + "b" "Variable v"; -// ^^^ string.quoted.double -// ^^^ string.quoted.double -// ^^^^^^^^^^^^ comment.line +// ^^^ source.modelica string.quoted.double +// ^^^ source.modelica string.quoted.double +// ^^^^^^^^^^^^ source.modelica comment.line String w = "a" + "b"; -// ^^^ string.quoted.double -// ^^^ string.quoted.double +// ^^^ source.modelica string.quoted.double +// ^^^ source.modelica string.quoted.double end M; diff --git a/test/susan/codegen.test.tpl b/test/susan/codegen.test.tpl new file mode 100644 index 0000000..ad5100a --- /dev/null +++ b/test/susan/codegen.test.tpl @@ -0,0 +1,32 @@ +// SYNTAX TEST "source.susan" "Example someTemplateFunction" + +template someTemplateFunction(Text message, Context context, builtin.SourceInfo info) +//<--- source.susan keyword +// ^^^^^^^^^^^^^^^^^^^^^ source.susan entity.name.function +::= +//<-- source.susan keyword.control + match context +//^^^^^ source.susan keyword.control + case FUNCTION_CONTEXT(__) then +//^^^^ source.susan keyword.control +// ^^^^^^^^^^^^^^^^ source.susan entity.name.function +// ^^^^ source.susan keyword.control + << + void foo() { + FILE_INFO info = {<%infoArgs(info)%>}; + printf("<%message%>\"\n"); + } + >> +// ^^ source.susan string.interpolated keyword + else +//^^^^ source.susan keyword.control + << + void foo() { + printf("Unknown context\n"); + printf("<%message%>\n"); + } + >> +// ^^ source.susan string.interpolated keyword +end someTemplateFunction; +//<-- source.susan keyword +// ^^^^^^^^^^^^^^^^^^^^ source.susan entity.name.function