diff --git a/tool/toit.js b/tool/toit.js index 14adf27..f69e3d0 100644 --- a/tool/toit.js +++ b/tool/toit.js @@ -1,3 +1,7 @@ +/* eslint-disable */ +// Code copied from toitware/ide-tools. Used 'prettier' and slightly modified the start. +// DO NOT EDIT. + // Copyright (C) 2021 Toitware ApS. All rights reserved. // Use of this source code is governed by an MIT-style license that can be // found in the LICENSE file. @@ -32,12 +36,12 @@ CodeMirror.defineMode('toit', function (config) { var atoms = makeJsObject('true|false|null') var specialVars = makeJsObject('this|super|it') - var IDENTIFIER = /[a-zA-Z_]\w*/ - var TYPE = /[a-zA-Z_]\w*(\.[a-zA-Z_]\w*)?/ + var IDENTIFIER = /[a-zA-Z_]([\w-]*\w)?/ + var TYPE = /[a-zA-Z_]([\w-]*\w)?(\.[a-zA-Z_]([\w-]*\w)?)?/ var OVERRIDABLE_OPERATOR = /==|>=|<=|<<|>>>|>>|\*|\+|-|%|\/|<|>|&|\||\^|~|\[\]\=|\[\]|\[\.\.\]/ - var CONSTANT_HEURISTIC = /_?[A-Z][A-Z_0-9]+/ - var TYPE_HEURISTIC = /_?[A-Z]\w*[a-z]\w*/ + var CONSTANT_HEURISTIC = /^_?[A-Z][A-Z_0-9-]*$/ + var TYPE_HEURISTIC = /^_?[A-Z][\w-]*[a-z][\w-]*$/ var CONTROL = /[?:;]/ function isKeyword(str) { @@ -408,21 +412,29 @@ CodeMirror.defineMode('toit', function (config) { return null } - function tryIdentifier(stream, state) { + function tryPostfixMemberOrIdentifier(stream, state) { + return tryIdentifier(stream, state, true) + } + + function tryIdentifier(stream, state, allowPrefixedDot) { + // If we allow a prefixed dot, consume it (but put it back if + // it's not followed by an identifier). + if (allowPrefixedDot && stream.match('.')) { + if (!stream.match(IDENTIFIER, false)) { + stream.backUp(1) + return null + } + return 'dot' + } if (!stream.match(IDENTIFIER)) return null var id = stream.current() if (isKeyword(id)) return 'keyword' if (isSpecialVar(id)) return 'special_var' if (isAtom(id)) return 'atom' - if (id.match(CONSTANT_HEURISTIC)) { - return 'constant' - } - if (id.match(TYPE_HEURISTIC)) { - return 'type' - } - if (stream.match(/[ ]*:?:=/, false)) { - return 'declaration' - } + if (id.match(CONSTANT_HEURISTIC)) return 'constant' + if (id.match(TYPE_HEURISTIC)) return 'type' + if (stream.match(/[ ]*:?:=/, false)) return 'declaration' + if (stream.match(/[ ]*[/][ ]*[\w_.]+[?]?[ ]*:?:=/, false)) { state.context.push([localAnnotation, -1]) state.subState.push(LOCAL_ANNOTATION_DIV) @@ -932,6 +944,10 @@ CodeMirror.defineMode('toit', function (config) { tryOperator(stream, state) || tryString(stream, state) || tryIsAs(stream, state) || + // In theory we need to check whether the postfix member is + // prefixed by another expression but for the syntax highlighter we + // just assume that was the case. + tryPostfixMemberOrIdentifier(stream, state) || tryIdentifier(stream, state) || tryPrimitive(stream, state) || tryDelimited(stream, state) ||