Skip to content

Commit

Permalink
Add support for block comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwikman committed Sep 9, 2020
1 parent f9796ac commit 5e1f39b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
27 changes: 25 additions & 2 deletions mcore.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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]*)'
Expand Down Expand Up @@ -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:
Expand All @@ -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 ###
### ###
Expand Down
27 changes: 25 additions & 2 deletions src/mcore/mcore.sublime-syntax-base
Original file line number Diff line number Diff line change
Expand Up @@ -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]*)'
Expand Down Expand Up @@ -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:
Expand All @@ -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 ###
### ###
Expand Down

0 comments on commit 5e1f39b

Please sign in to comment.