From 5e1f39b5d6eef1cd355d1d09f2d9d7de6797473e Mon Sep 17 00:00:00 2001 From: John Wikman Date: Wed, 9 Sep 2020 18:43:20 +0200 Subject: [PATCH] Add support for block comments. --- mcore.sublime-syntax | 27 +++++++++++++++++++++++++-- src/mcore/mcore.sublime-syntax-base | 27 +++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/mcore.sublime-syntax b/mcore.sublime-syntax index 6a45c77..1b385ed 100644 --- a/mcore.sublime-syntax +++ b/mcore.sublime-syntax @@ -6,7 +6,7 @@ file_extensions: scope: source.mcore variables: - builtin_ident: '(?:unit|not|and|or|addi|subi|muli|divi|modi|negi|lti|leqi|gti|geqi|eqi|neqi|slli|srli|srai|arity|addf|subf|mulf|divf|negf|ltf|leqf|gtf|geqf|eqf|neqf|char2int|int2char|int2float|string2float|length|concat|nth|cons|snoc|slice|reverse|print|dprint|argv|readFile|writeFile|fileExists|deleteFile|error|floorfi|ceilfi|roundfi|get|set|splitAt|makeSeq)' + builtin_ident: '(?:unit|never|addi|subi|muli|divi|modi|negi|lti|leqi|gti|geqi|eqi|neqi|slli|srli|srai|arity|addf|subf|mulf|divf|negf|ltf|leqf|gtf|geqf|eqf|neqf|char2int|int2char|int2float|string2float|length|concat|reverse|splitAt|makeSeq|cons|snoc|get|set|print|dprint|argv|readFile|writeFile|fileExists|deleteFile|error|floorfi|ceilfi|roundfi)' reserved_ident: '(?:if|then|else|match|with|let|recursive|utest|lam|lang|syn|sem|con|type|use|in|end|mexpr)' type_ident: '(?:Dyn|Bool|Int|Float|Char|String)' ident: '(?:[a-zA-Z_][a-zA-Z_0-9]*)' @@ -62,6 +62,11 @@ contexts: ### Comments ### ### ### comment: + - include: comment-line + - include: comment-block + - include: comment-block-illegal + + comment-line: - match: '--' scope: comment.line.mcore push: @@ -70,9 +75,27 @@ contexts: pop: true - include: comment-line-content comment-line-content: - - match: '.*' + - match: '.' scope: comment.line.mcore + comment-block: + - match: '[*]-' + scope: comment.block.mcore + push: + - match: '-[*]' + scope: comment.block.mcore + pop: true + - include: comment-block-content + comment-block-content: + - include: comment-block # <-- checks nested block comments + - match: '.' + scope: comment.block.mcore + + # This ending is illegal outside of a block comment + comment-block-illegal: + - match: '-[*]' + scope: invalid.illegal.block.mcore + ### ### ### Illegal RParen/RSquareBracket/RCurlyBracket ### ### ### diff --git a/src/mcore/mcore.sublime-syntax-base b/src/mcore/mcore.sublime-syntax-base index 8918e62..353fe85 100644 --- a/src/mcore/mcore.sublime-syntax-base +++ b/src/mcore/mcore.sublime-syntax-base @@ -6,7 +6,7 @@ file_extensions: scope: source.mcore variables: - builtin_ident: '(?:unit|not|and|or|addi|subi|muli|divi|modi|negi|lti|leqi|gti|geqi|eqi|neqi|slli|srli|srai|arity|addf|subf|mulf|divf|negf|ltf|leqf|gtf|geqf|eqf|neqf|char2int|int2char|int2float|string2float|length|concat|nth|cons|snoc|slice|reverse|print|dprint|argv|readFile|writeFile|fileExists|deleteFile|error|floorfi|ceilfi|roundfi|get|set|splitAt|makeSeq)' + builtin_ident: '(?:unit|never|addi|subi|muli|divi|modi|negi|lti|leqi|gti|geqi|eqi|neqi|slli|srli|srai|arity|addf|subf|mulf|divf|negf|ltf|leqf|gtf|geqf|eqf|neqf|char2int|int2char|int2float|string2float|length|concat|reverse|splitAt|makeSeq|cons|snoc|get|set|print|dprint|argv|readFile|writeFile|fileExists|deleteFile|error|floorfi|ceilfi|roundfi)' reserved_ident: '(?:if|then|else|match|with|let|recursive|utest|lam|lang|syn|sem|con|type|use|in|end|mexpr)' type_ident: '(?:Dyn|Bool|Int|Float|Char|String)' ident: '(?:[a-zA-Z_][a-zA-Z_0-9]*)' @@ -62,6 +62,11 @@ contexts: ### Comments ### ### ### comment: + - include: comment-line + - include: comment-block + - include: comment-block-illegal + + comment-line: - match: '--' scope: comment.line.mcore push: @@ -70,9 +75,27 @@ contexts: pop: true - include: comment-line-content comment-line-content: - - match: '.*' + - match: '.' scope: comment.line.mcore + comment-block: + - match: '[*]-' + scope: comment.block.mcore + push: + - match: '-[*]' + scope: comment.block.mcore + pop: true + - include: comment-block-content + comment-block-content: + - include: comment-block # <-- checks nested block comments + - match: '.' + scope: comment.block.mcore + + # This ending is illegal outside of a block comment + comment-block-illegal: + - match: '-[*]' + scope: invalid.illegal.block.mcore + ### ### ### Illegal RParen/RSquareBracket/RCurlyBracket ### ### ###