From ec01106b0c15923ca5736ec5cb8d0af4a54c7910 Mon Sep 17 00:00:00 2001 From: Catherine Date: Thu, 23 Feb 2023 23:59:10 +0000 Subject: [PATCH 1/4] Add support for tags. --- wast.sublime-syntax | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/wast.sublime-syntax b/wast.sublime-syntax index b693a14..f4785b9 100644 --- a/wast.sublime-syntax +++ b/wast.sublime-syntax @@ -545,7 +545,7 @@ contexts: pop: true - match: '.' scope: invalid.illegal.wast - - - match: '(\(){{WHITES}}*(func|global|memory|table){{IDTERM}}' + - - match: '(\(){{WHITES}}*(func|global|memory|table|tag){{IDTERM}}' captures: 1: punctuation.definition.exportdesc.begin.wast 2: storage.modifier.wast @@ -632,12 +632,19 @@ contexts: captures: 1: entity.name.type.wast pop: true + modulefield_tag: + - match: '(\(){{WHITES}}*(tag){{IDTERM}}' + captures: + 1: punctuation.definition.tag.begin.wast + 2: storage.type.constant.wast storage.type.tag.wast + push: [ tag_end, tag_type, tag_import, abbreviated_export, tag_name ] modulefields_IMPORT_START: - include: modulefield_data - include: modulefield_element - include: modulefield_export - include: modulefield_import - include: modulefield_type + - include: modulefield_tag - match: '{{STARTS}}' captures: 1: punctuation.definition.start.begin.wast @@ -651,6 +658,7 @@ contexts: - include: modulefield_export - include: modulefield_import - include: modulefield_type + - include: modulefield_tag - match: '(?=.)' set: modulefields_REST modulefields_REST: @@ -662,6 +670,7 @@ contexts: - include: modulefield_memory - include: modulefield_table - include: modulefield_type + - include: modulefield_tag - match: '(?=.)' pop: true modulefields_START: @@ -831,6 +840,31 @@ contexts: captures: 1: entity.name.table.wast pop: true + tag_end: + - meta_scope: meta.s-expression.tag.wast + - match: '\)' + scope: punctuation.definition.tag.end.wast + pop: true + - match: '.' + scope: invalid.illegal.wast + pop: true + tag_import: + - match: '(\(){{WHITES}}*(import){{IDTERM}}' + captures: + 1: punctuation.definition.import.begin.wast + 2: keyword.other.import.wast + set: [ import_end, import_names ] + - match: '(?=.)' + pop: true + tag_name: + - match: '({{IDNAME}})|' + captures: + 1: entity.name.tag.wast + pop: true + tag_type: + - include: param + - match: '(?=.)' + pop: true typeuse: - match: (?=.) set: From ef3877ac4f3c15f86aea3eb485e35012e1cdc788 Mon Sep 17 00:00:00 2001 From: Catherine Date: Fri, 24 Feb 2023 00:09:30 +0000 Subject: [PATCH 2/4] Add support for throw and rethrow instructions. --- wast.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wast.sublime-syntax b/wast.sublime-syntax index f4785b9..4232d45 100644 --- a/wast.sublime-syntax +++ b/wast.sublime-syntax @@ -15,7 +15,7 @@ variables: FLOATO: 'f32\.reinterpret/i32|f64\.(?:promote/f32|reinterpret/i64)' FLOATP: '[+-]?(?:inf|nan(?::0x{{HEXNUM}})?|{{HEXFLT}}|{{DECFLT}}){{IDTERM}}' FLOW_1: '(?:nop|return|unreachable){{IDTERM}}' - FLOW_2: 'br(?:_if)?{{IDTERM}}' + FLOW_2: '(?:br(?:_if)?|throw|rethrow){{IDTERM}}' FLOW_3: 'br_table{{IDTERM}}' HEXFLT: '0x{{HEXNUM}}(?=[Pp.])(\.{{HEXFRC}})?(?:[Pp][+-]?{{DECNUM}})?' HEXFRC: (?:{{HEXNUM}})? From 7149e5d629b23143b59a2655fab5c9ef54d9bd5e Mon Sep 17 00:00:00 2001 From: Catherine Date: Fri, 24 Feb 2023 00:09:53 +0000 Subject: [PATCH 3/4] Add support for plain try, catch, catch_all, delegate instructions. --- wast.sublime-syntax | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/wast.sublime-syntax b/wast.sublime-syntax index 4232d45..31d006e 100644 --- a/wast.sublime-syntax +++ b/wast.sublime-syntax @@ -272,6 +272,9 @@ contexts: - match: 'if{{IDTERM}}' scope: keyword.control.conditional.wast push: [ label, if_else_end, else, instructions, resulttype, label ] + - match: 'try{{IDTERM}}' + scope: keyword.control.flow.wast + push: [ label, try_catch_delegate, instructions, resulttype, label ] - include: instructions_plain - include: instructions_folded instructions_folded: @@ -865,6 +868,26 @@ contexts: - include: param - match: '(?=.)' pop: true + try_catch_delegate: + - meta_scope: meta.block.wast + - match: 'delegate{{IDTERM}}' + scope: keyword.control.flow.wast + set: [ reference ] + - match: '(?=.)' + set: [ try_catch ] + try_catch: + - meta_scope: meta.block.wast + - match: 'catch{{IDTERM}}' + scope: keyword.control.flow.wast + push: [ instructions, reference ] + - match: 'catch_all{{IDTERM}}' + scope: keyword.control.flow.wast + push: [ instructions ] + - match: 'end{{IDTERM}}' + scope: keyword.control.flow.wast + pop: true + - match: '.' + scope: invalid.illegal.wast typeuse: - match: (?=.) set: From 5504835244cec86f0f258f6e608255dcc7b7566d Mon Sep 17 00:00:00 2001 From: Catherine Date: Fri, 24 Feb 2023 00:20:14 +0000 Subject: [PATCH 4/4] Add support for folded try, catch, catch_all, delegate instructions. --- wast.sublime-syntax | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/wast.sublime-syntax b/wast.sublime-syntax index 31d006e..f24f7c7 100644 --- a/wast.sublime-syntax +++ b/wast.sublime-syntax @@ -344,6 +344,58 @@ contexts: - instructions_folded - resulttype - label + - match: '(\(){{WHITES}}*(try){{IDTERM}}' + captures: + 1: punctuation.definition.block.begin.wast + 2: keyword.control.flow.wast + push: + - - meta_scope: meta.s-expression.instruction.wast + - match: '\)' + scope: punctuation.definition.block.end.wast + pop: true + - match: '(\(){{WHITES}}*(do){{IDTERM}}' + captures: + 1: punctuation.definition.block.begin.wast + 2: keyword.control.flow.wast + push: + - - meta_scope: meta.s-expression.instruction.wast + - match: '\)' + scope: punctuation.definition.block.end.wast + pop: true + - instructions + - match: '(\(){{WHITES}}*(delegate){{IDTERM}}' + captures: + 1: punctuation.definition.block.begin.wast + 2: keyword.control.flow.wast + push: + - - meta_scope: meta.s-expression.instruction.wast + - match: '\)' + scope: punctuation.definition.block.end.wast + pop: true + - reference + - match: '(\(){{WHITES}}*(catch){{IDTERM}}' + captures: + 1: punctuation.definition.block.begin.wast + 2: keyword.control.flow.wast + push: + - - meta_scope: meta.s-expression.instruction.wast + - match: '\)' + scope: punctuation.definition.block.end.wast + pop: true + - instructions + - reference + - match: '(\(){{WHITES}}*(catch_all){{IDTERM}}' + captures: + 1: punctuation.definition.block.begin.wast + 2: keyword.control.flow.wast + push: + - - meta_scope: meta.s-expression.instruction.wast + - match: '\)' + scope: punctuation.definition.block.end.wast + pop: true + - instructions + - resulttype + - label # The lookahead here is a hack for if-then to avoid more copypasta contexts - match: '\((?!{{WHITES}}*then{{IDTERM}})' scope: punctuation.definition.instruction.begin.wast