Skip to content

Commit

Permalink
Add support for mixins. (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch authored Nov 1, 2023
1 parent 3df5553 commit 6c26aab
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
29 changes: 23 additions & 6 deletions code_mirror/toit.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,13 @@
var CLASS_SIGNATURE_AFTER_NAME = 1;
var CLASS_SIGNATURE_AFTER_EXTENDS = 2;
var CLASS_SIGNATURE_AFTER_EXTENDS_TYPE = 3
var CLASS_SIGNATURE_AFTER_IMPLEMENTS = 4;
var CLASS_SIGNATURE_AFTER_FIRST_IMPLEMENTS_NAME = 5;
var CLASS_BODY = 6;
var CLASS_SIGNATURE_AFTER_WITH = 4
var CLASS_SIGNATURE_AFTER_FIRST_WITH_NAME = 5;
var CLASS_SIGNATURE_AFTER_IMPLEMENTS = 6;
var CLASS_SIGNATURE_AFTER_FIRST_IMPLEMENTS_NAME = 7;
var CLASS_BODY = 8;
function tryClass(stream, state) {
if (stream.match(/(abstract[ ]+)?class\b/) || stream.match(/interface\b/)) {
if (stream.match(/(abstract[ ]+)?class\b/) || stream.match(/interface\b/) || stream.match(/mixin\b/) || stream.match(/monitor\b/)) {
state.context.push([tokenizeClass, 2]);
state.subState.push(CLASS_SIGNATURE_AFTER_CLASS);
return "keyword"
Expand Down Expand Up @@ -617,9 +619,13 @@
setSubState(state, CLASS_SIGNATURE_AFTER_EXTENDS);
return "keyword";
}
// Fall through.
// Fall through.

case CLASS_SIGNATURE_AFTER_EXTENDS_TYPE:
if (stream.match(/with\b/)) {
setSubState(state, CLASS_SIGNATURE_AFTER_WITH);
return "keyword";
}
if (stream.match(/implements\b/)) {
setSubState(state, CLASS_SIGNATURE_AFTER_IMPLEMENTS);
return "keyword";
Expand All @@ -635,12 +641,17 @@
setSubState(state, CLASS_SIGNATURE_AFTER_EXTENDS_TYPE);
return tokenizeType(stream, state, false);

case CLASS_SIGNATURE_AFTER_WITH:
case CLASS_SIGNATURE_AFTER_IMPLEMENTS:
// The first *requires* an type.
if (!stream.match(TYPE, false)) return signatureError();
setSubState(state, CLASS_SIGNATURE_AFTER_FIRST_IMPLEMENTS_NAME);
const nextSubState = subState(state) == CLASS_SIGNATURE_AFTER_WITH
? CLASS_SIGNATURE_AFTER_FIRST_WITH_NAME
: CLASS_SIGNATURE_AFTER_FIRST_IMPLEMENTS_NAME;
setSubState(state, nextSubState);
return tokenizeType(stream, state, false);

case CLASS_SIGNATURE_AFTER_FIRST_WITH_NAME:
case CLASS_SIGNATURE_AFTER_FIRST_IMPLEMENTS_NAME:
if (stream.match(TYPE, false)) {
return tokenizeType(stream, state, false);
Expand All @@ -649,6 +660,12 @@
setSubState(state, CLASS_BODY);
return "class_body_colon";
}
if (subState(state) == CLASS_SIGNATURE_AFTER_FIRST_WITH_NAME) {
if (stream.match(/implements\b/)) {
setSubState(state, CLASS_SIGNATURE_AFTER_IMPLEMENTS);
return "keyword";
}
}
return signatureError();

case CLASS_BODY:
Expand Down
4 changes: 2 additions & 2 deletions start/vim/syntax/toit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ syntax sync minlines=500
" TODO: Find out why 'syntax iskeyword' doesn't work.
setlocal iskeyword=a-z,A-Z,48-57,_,-

syntax keyword toitKeyword it super extends implements as return abstract static unreachable break continue
syntax keyword toitKeyword it super extends implements as return abstract static unreachable break continue with
highlight link toitKeyword Keyword

syntax keyword toitNull null
Expand Down Expand Up @@ -175,7 +175,7 @@ highlight link toitDeclaration Identifier
syntax match toitToplevelDeclaration "\v^[a-zA-Z_][a-zA-Z0-9_-]*"
highlight link toitToplevelDeclaration Identifier

syntax region toitClass matchgroup=toitStructure start=/\v(^|^abstract[ ]+)@<=(class|interface)>/ end=/\v^[^ ]@=/ contains=toitComment,toitMultiComment,toitMemberDeclaration,toitKeyword
syntax region toitClass matchgroup=toitStructure start=/\v(^|^abstract[ ]+)@<=(class|interface|mixin|monitor)>/ end=/\v^[^ ]@=/ contains=toitComment,toitMultiComment,toitMemberDeclaration,toitKeyword
highlight link toitStructure Structure

syntax region toitMemberBody start="" end=/\v(^ ? ?[a-zA-Z0-9_-])@=/ contained contains=TOP
Expand Down
6 changes: 5 additions & 1 deletion vscode/syntaxes/toit.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"class-section": {
"name": "meta.class.toit",
"begin": "^(?:(abstract)[ ]+)?(class|monitor|interface)(?!-)\\b",
"begin": "^(?:(abstract)[ ]+)?(class|interface|mixin|monitor)(?!-)\\b",
"end": "^(?=[^\\s/]|/[^/*])",
"beginCaptures": {
"1": {
Expand Down Expand Up @@ -129,6 +129,10 @@
"name": "keyword.control.implements.toit",
"match": "\\b(?<!-)implements(?!-)\\b"
},
{
"name": "keyword.control.with.toit",
"match": "\\bwith\\b"
},
{
"include": "#type-name"
}
Expand Down
4 changes: 3 additions & 1 deletion vscode/syntaxes/toit.tmLanguage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ repository:

class-section:
name: meta.class.toit
begin: ^(?:(abstract)[ ]+)?(class|monitor|interface)(?!-)\b
begin: ^(?:(abstract)[ ]+)?(class|interface|mixin|monitor)(?!-)\b
end: ^(?=[^\s/]|/[^/*]) # Ends with a non-indented different section. (Note the negative look-ahead to avoid consuming the next token).
beginCaptures:
1:
Expand Down Expand Up @@ -100,6 +100,8 @@ repository:
match: \b(?<!-)extends(?!-)\b
- name: keyword.control.implements.toit
match: \b(?<!-)implements(?!-)\b
- name: keyword.control.with.toit
match: \bwith\b
- include: "#type-name"

toplevel-section:
Expand Down

0 comments on commit 6c26aab

Please sign in to comment.