Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code-mirror. #13

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions tool/toit.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) ||
Expand Down
Loading