From e160ea6820d3c25d0f08db4956471a63e5c76da2 Mon Sep 17 00:00:00 2001 From: Rob Lorch Date: Wed, 24 Jul 2024 12:07:56 -0400 Subject: [PATCH 1/2] Syntax highlighting for polymorphism (and remove unnecessary yaml file ) --- syntaxes/lustre.tmLanguage.json | 21 +- syntaxes/lustre.tmLanguage.yaml | 619 -------------------------------- 2 files changed, 20 insertions(+), 620 deletions(-) delete mode 100644 syntaxes/lustre.tmLanguage.yaml diff --git a/syntaxes/lustre.tmLanguage.json b/syntaxes/lustre.tmLanguage.json index 0fbd7b1..45486a2 100644 --- a/syntaxes/lustre.tmLanguage.json +++ b/syntaxes/lustre.tmLanguage.json @@ -546,6 +546,18 @@ "name": "entity.name.function.lustre", "match": "\\w+" }, + { + "begin": "<<", + "end": ">>", + "patterns": [ + { + "include": "#type" + }, + { + "include": "#comment" + } + ] + }, { "begin": "\\(", "end": "\\)", @@ -727,10 +739,17 @@ }, { "comment": "Node / function call", - "begin": "(\\w+)\\s*\\(", + "begin": "(\\w+)\\s*(<<[^>]+>>)?\\s*\\(", "beginCaptures": { "1": { "name": "entity.name.function" + }, + "2": { + "patterns": [ + { + "include": "#type" + } + ] } }, "end": "\\)", diff --git a/syntaxes/lustre.tmLanguage.yaml b/syntaxes/lustre.tmLanguage.yaml deleted file mode 100644 index 2b46286..0000000 --- a/syntaxes/lustre.tmLanguage.yaml +++ /dev/null @@ -1,619 +0,0 @@ -# [PackageDev] target_format: plist, ext: tmLanguage - -# Oniguruma Regular Expressions: -# https://sonoisa.github.io/ogrekit/About_(English)_files/RE.txt - -# Sublime tuto: -# http://sublimetext.info/docs/en/extensibility/syntaxdefs.html - -# Prolog example: -# https://github.com/alnkpa/sublimeprolog/blob/master/support/Prolog.YAML-tmLanguage ---- -name: Lustre -scopeName: source.lus -fileTypes: [lus] -uuid: 23a435f9-1904-4b91-99ee-7609e0e45879 - -patterns: -- include: '#include' -- include: '#typeDecl' -- include: '#const' -- include: '#contract' -- include: '#importedComponent' -- include: '#component' -- include: '#blockContract' -- include: '#comment' - - -repository: - - # Invalid. - - invalid: - name: invalid.lustre - match: '[.]' - - - # Annotations. - - modeRef: - begin: '::' - end: '(\w+)(?!\w*\s*:)' - endCaptures: - '1': {name: entity.name.tag.lustre} - patterns: - - name: support.function.lustre - match: '(\w+)' - - blockVar: - begin: '(var|const)\s+(\w+)' - beginCaptures: - '1': {name: storage.modifier.lustre} - '2': {name: variable.other.lustre} - end: ';' - patterns: - - include: '#modeRef' - - name: keyword.operator.lustre - match: '=' - - begin: ':' - end: '=' - endCaptures: - '0': {name: keyword.operator.lustre} - patterns: - - include: '#type' - - include: '#expression' - - blockStmt: - begin: '(require|ensure)' - beginCaptures: - '1': {name: keyword.other.lustre} - end: ';' - patterns: - - include: '#expression' - - include: '#modeRef' - - blockMode: - begin: '\b(mode)\b\s*(\w+)' - beginCaptures: - '1': {name: keyword.other.lustre} - '2': {name: entity.name.tag.lustre} - end: ';' - patterns: - - include: '#comment' - - comment: Actual contract - begin: '\(' - end: '\)' - patterns: - - include: '#comment' - - include: '#modeRef' - - include: '#blockStmt' - - blockAssGua: - begin: '\b(assume|guarantee)\b' - beginCaptures: - '0': {name: keyword.other.lustre} - end: ';' - patterns: - - include: '#expression' - - include: '#modeRef' - - blockImport: - begin: '(import)\s+([a-zA-Z][a-zA-Z_\-\.]*)' - beginCaptures: - '1': {name: keyword.other.lustre} - '2': {name: entity.name.function.lustre} - end: ';' - patterns: - - name: keyword.other.lustre - match: 'returns' - - include: '#expression' - - include: '#modeRef' - - contract: - begin: '(?=contract)' - end: '(?<=tel)' - patterns: - - include: '#componentDecl' - - include: '#comment' - - begin: '\b(let)\b' - end: '\b(tel)\b' - captures: - '1': {name: keyword.other.lustre} - patterns: - - include: '#contractBody' - - blockContract: - patterns: - - begin: '(\(\*)(@contract)' - beginCaptures: - '1': {name: comment.block.lustre} - '2': {name: keyword.other.lustre} - end: '(\*\))' - endCaptures: - '1': {name: comment.block.lustre} - patterns: - - include: '#contractBody' - - begin: '(/\*)(@contract)' - beginCaptures: - '1': {name: comment.lustre} - '2': {name: keyword.lustre} - end: '(\*/)' - endCaptures: - '1': {name: comment.lustre} - patterns: - - include: '#contractBody' - - contractBody: - patterns: - - include: '#blockVar' - - include: '#blockMode' - - include: '#blockStmt' - - include: '#blockAssGua' - - include: '#blockImport' - - include: '#comment' - - lustrecOrKind2: - patterns: - - begin: '(--)((%|!)\w+)\s*(:)?' - beginCaptures: - '1': {name: comment.line.double-dash.lustre} - '2': {name: keyword.other.lustre} - end: ';' - patterns: - - include: '#expression' - - begin: '(\(\*)((%|!)\w+)\s*(:)?' - beginCaptures: - '1': {name: comment.block.lustre} - '2': {name: keyword.other.lustre} - end: '(\*\))' - endCaptures: - '1': {name: comment.block.lustre} - patterns: - - include: '#expression' - - begin: '(/\*)((%|!)\w+)\s*(:)?' - beginCaptures: - '1': {name: comment.block.lustre} - '2': {name: keyword.other.lustre} - end: '(\*/)' - endCaptures: - '1': {name: comment.block.lustre} - patterns: - - include: '#expression' - - internAnnotation: - comment: Annotations inside bodies. - patterns: - - include: '#lustrecOrKind2' - - - # Comments. - - comment: - patterns: - - name: comment.lustre - match: '--.*' - - name: comment.lustre - begin: '\(\*' - end: '\*\)' - - name: comment.lustre - begin: '/\*' - end: '\*/' - - # Helpers for nodes and expressions. - - type: - patterns: - - comment: Arrays with literal sizes. - match: '(\w+)\s*(\^)\s*([1-9]\d*)' - captures: - '1': {name: support.type.lustre} - '2': {name: keyword.operator.lustre} - '3': {name: constant.numeric.lustre} - - comment: Arrays with constant sizes. - name: temp - match: '(\w+)\s*(\^)\s*(\w+)' - captures: - '1': {name: support.type.lustre} - '2': {name: keyword.operator.lustre} - '3': {name: variable.other.lustre} - - comment: Primitive types. - name: support.type.lustre - match: '\b(bool|int|real)\b' - - comment: Subranges. - begin: '\b(subrange)\s*\[' - beginCaptures: - '1': {name: support.type.lustre} - end: '\]' - patterns: - - include: '#intCst' - - name: variable.other.lustre # TODO: consider replacing name with const. - match: '\w+' - - comment: Tuples. - begin: '\[' - end: '\]' - patterns: - - include: '#type' - - comment: User-defined type. - name: support.type.lustre - match: '\w+' - - importedComponent: - begin: '(?=(node|function)\s*\bimported\b)' - end: '(?<=;|\))' - patterns: - - include: '#componentDecl' - - include: '#blockContract' - - include: '#comment' - - component: - begin: '(?=node|function)' - end: '(?<=tel)' - patterns: - - include: '#componentDecl' - - include: '#blockContract' - - include: '#comment' - - include: '#var' - - include: '#body' - - include: '#const' - - componentDecl: - comment: More precisely, a node, a contract, or a function prefix. - begin: '\b(contract|node|function)\b' - end: ';|(?=\(\*@contract|const|var|let)' - beginCaptures: - '1': {name: keyword.other.lustre} - patterns: - - match: '\b(imported|returns)\b' - captures: - '1': {name: keyword.other.lustre} - - name: entity.name.function.lustre - match: '\w+' - - begin: '\(' - end: '\)' - patterns: - - comment: Input/output name. - begin: '(?<=;|\(|,)' - end: ',|(?=:|\))' - patterns: - - match: '\b(const)\b' - captures: - '1': {name: storage.modifier.lustre} - - name: variable.parameter.lustre - match: '\w+' - - include: "#comment" - - comment: Type for an input/output. - begin: ':' - end: ';|(?=\))' - patterns: - - include: '#type' - - include: '#comment' - - include: '#comment' - - include: '#comment' - - - # Constants - - intCst: - match: '\b(\d+|0x\h+)\b' - captures: - '1': {name: constant.numeric.lustre} - - floatCst: - match: '\b(\d*\.\d*((E|e)(\-|\+)\d+)?|0x\h*\.\h*(p(\-|\+)\d+)?)\b' - captures: - '1': {name: constant.numeric.lustre} - - boolCst: - match: '\b(true|false)\b' - captures: - '1': {name: constant.language.lustre} - - stringCst: - name: string.quoted.double.lustre - match: '\"[^\"]*\"' - - cst: - patterns: - - include: '#floatCst' - - include: '#intCst' - - include: '#boolCst' - - include: '#stringCst' - - - # Include - - include: - begin: '\b(include)\b' - end: '\".*\"' - beginCaptures: - '1': {name: keyword.other.lustre} - endCaptures: - '0': {name: string.quoted.double} - - - # Expressions. - - expression: - patterns: - - include: '#cst' - - include: '#comment' - - comment: Keywords - name: keyword.control.lustre - match: '\b(if|then|else|not|and|xor|or|pre|fby|div|mod|lsh|rsh|reachable|provided|assuming|invariant|from|within|at|any|param)\b' - - comment: Merge - begin: '(merge)\s*\(' - beginCaptures: - '1': {name: keyword.other.lustre} - end: '\)' - patterns: - - begin: '\(\s*(activate)\s+(\w+)\s+(every)' - beginCaptures: - '1': {name: keyword.other.lustre} - '2': {name: variable.other.lustre} - '3': {name: keyword.other.lustre} - end: '\)\s*\((\w+)\s*(,\s*(\w+))*\s*\)' # TODO: improve highlighting of this - endCaptures: - '1': {name: variable.other.lustre} - patterns: - - include: '#expression' - - name: constant.language.source.lustre - match: 'when' - - include: '#expression' - - comment: -> keyword (no \b delimiter) - name: keyword.operator.lustre - match: '->' - - comment: Operators - name: keyword.operator.lustre - match: '<>|=|>=|>|<=|<|\+|\-|\*|/|%|&&|\|\||!' - - comment: Machine integers - name: support.type.lustre - match: '\b(int8|int16|int32|int64|uint8|uint16|uint32|uint64)' - - comment: Node / function call - begin: '(\w+)\s*\(' - beginCaptures: - '1': {name: entity.name.function} - end: '\)' - patterns: - - include: '#expression' - - comment: Array - begin: '\[' - end: '\]' - patterns: - - include: '#expression' - - comment: Struct - begin: '((\w+)\s+)?{' - end: '}' - beginCaptures: - '1': {name: support.type.lustre} - patterns: - - begin: '(\w+)\s*(=)' - beginCaptures: - '1': {name: variable.other.lustre} - '2': {name: keyword.operator.lustre} - end: ';|(?=})' - patterns: - - include: '#expression' - - include: '#expression' - - comment: Idents - name: variable.other.lustre - match: '\b\w+\b' - - - # Equations - - equation: - patterns: - - comment: Assertion or check. - begin: '\b(assert|check)\b' - beginCaptures: - '1': {name: keyword.other.lustre} - end: ';' - patterns: - - include: '#expression' - - comment: Regular ident lhs. - begin: '(\w+)\s*=' - beginCaptures: - '1': {name: variable.other.lustre} - end: ';' - patterns: - - include: '#expression' - - comment: Tuple equation. - begin: '\(?(\w+)' - end: ';' - beginCaptures: - '1': {name: variable.other.lustre} - patterns: - - comment: Rest of tuples. - begin: ',' - end: ',|\)|(?==)' - patterns: - - name: variable.other.lustre - match: '\w+' - - include: '#expression' - - # If blocks - - ifBlock: - begin: "\\b(if)\\b" - end: "\\b(fi)\\b" - beginCaptures: - '1': - name: keyword.other.lustre - endCaptures: - '1': - name: keyword.other.lustre - patterns: - - begin: "(?<=(if|elsif))" - end: "(?=then)" - patterns: - - include: "#expression" - - include: "#comment" - - begin: "\\b(then)\\b" - end: "\\b(elsif|else)\\b|(?=fi)" - beginCaptures: - '1': - name: keyword.other.lustre - endCaptures: - '1': - name: keyword.other.lustre - patterns: - - include: "#ifBlock" - - include: "#equation" - - include: "#comment" - - begin: "(?<=else)" - end: "(?=fi)" - patterns: - - include: "#ifBlock" - - include: "#equation" - - include: "#comment" - - include: "#comment" - - # Frame blocks - - frameBlock: - begin: "\\b(frame)\\b" - end: "\\b(tel)\\b" - beginCaptures: - '1': - name: keyword.other.lustre - endCaptures: - '1': - name: keyword.other.lustre - patterns: - - begin: "(?<=frame)" - end: "\\b(let)\\b" - endCaptures: - '1': - name: keyword.other.lustre - patterns: - - begin: "\\(" - end: "\\)" - - include: "#equation" - - include: "#comment" - - begin: "(?<=let)" - end: "(?=tel)" - patterns: - - include: "#ifBlock" - - include: "#equation" - - include: "#comment" - - - # Local variables - - var: - begin: '\b(var)\b' - beginCaptures: - '1': {name: keyword.other.lustre} - end: '(?=const|let|var)' - patterns: - - name: variable.other.lustre - match: '\w+' - - begin: ':' - end: ';' - patterns: - - include: '#type' - - include: '#comment' - - include: '#comment' - - - # Body - - body: - begin: '\b(let)\b' - beginCaptures: - '1': {name: keyword.other.lustre} - end: '\b(tel)\b' - endCaptures: - '1': {name: keyword.other.lustre} - patterns: - - include: '#internAnnotation' - - include: '#comment' - - include: '#equation' - - include: '#ifBlock' - - include: '#frameBlock' - - # Type declaration - - structField: - begin: '(\w+)\s*:' - beginCaptures: - '1': {name: variable.other.lustre} - end: ';|(?=})' - patterns: - - include: '#type' - - typeDeclRhs: - patterns: - - enum: - begin: '\b(enum)\b' - end: '(?=;)' - beginCaptures: - '1': {name: keyword.other.lustre} - patterns: - - begin: '{' - end: '}' - patterns: - - name: entity.name.tag.lustre - match: \w+ - - include: '#comment' - - comment: Struct (syntax 1). - begin: '\b(struct)\b' - end: '(?=;)' - beginCaptures: - '1': {name: keyword.other.lustre} - patterns: - - begin: '{' - end: '}' - patterns: - - include: '#structField' - - include: '#comment' - - comment: Struct (syntax 2). - begin: '{' - end: '}' - patterns: - - include: '#structField' - - include: '#comment' - - typeDecl: - begin: '\b(type)\b' - beginCaptures: - '1': {name: keyword.other.lustre} - end: ';' - patterns: - - name: support.type.lustre - match: '\w+' - - begin: '=' - end: '(?=;)' - beginCaptures: - '1': {name: keyword.operator.lustre} - patterns: - - include: '#typeDeclRhs' - - include: '#type' - - include: '#comment' - - include: '#comment' - - - # Const declaration - - const: - begin: '\b(const)\b' - end: '(?=const|contract|function|node|let|type|var)' - beginCaptures: - '1': {name: keyword.other.lustre} - patterns: - - name: variable.other.lustre - match: '\w+' - - begin: ':' - end: '(?=;|=)' - patterns: - - include: '#type' - - include: '#comment' - - begin: '=' - end: ';' - beginCaptures: - '0': {name: keyword.operator.lustre} - patterns: - - include: '#expression' - - include: '#comment' - - include: '#comment' -... From 439fe1d46c62b64f33e78510320e95ca941fddeb Mon Sep 17 00:00:00 2001 From: Rob Lorch Date: Wed, 31 Jul 2024 10:54:28 -0400 Subject: [PATCH 2/2] Support type args in type decls and user types --- syntaxes/lustre.tmLanguage.json | 41 +++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/syntaxes/lustre.tmLanguage.json b/syntaxes/lustre.tmLanguage.json index 45486a2..1c997a2 100644 --- a/syntaxes/lustre.tmLanguage.json +++ b/syntaxes/lustre.tmLanguage.json @@ -480,8 +480,19 @@ }, { "comment": "User-defined type.", - "name": "support.type.lustre", - "match": "\\w+" + "match": "(\\w+)\\s*(<<[^>]+>>)?", + "captures": { + "1" : { + "name": "support.type.lustre" + }, + "2" : { + "patterns": [ + { + "include": "#type" + } + ] + } + } } ] }, @@ -547,16 +558,7 @@ "match": "\\w+" }, { - "begin": "<<", - "end": ">>", - "patterns": [ - { - "include": "#type" - }, - { - "include": "#comment" - } - ] + "include": "#typeArgs" }, { "begin": "\\(", @@ -1068,6 +1070,18 @@ } ] }, + "typeArgs": { + "begin": "<<", + "end": ">>", + "patterns": [ + { + "include": "#type" + }, + { + "include": "#comment" + } + ] + }, "typeDeclRhs": { "patterns": [ { @@ -1147,6 +1161,9 @@ "name": "support.type.lustre", "match": "\\w+" }, + { + "include": "#typeArgs" + }, { "begin": "=", "end": "(?=;)",