Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/codemirror/mode/makefile.js
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// CodeMirror, copyright (c) by Marijn Haverbeke and others6// Distributed under an MIT license: http://codemirror.net/LICENSE7// derived from https://github.com/notepadqq/CodeMirror/blob/d790fc39c1a5f06aa66415110b8ebe3026df665a/mode/makefile/makefile.js89import * as CodeMirror from "codemirror";1011CodeMirror.defineMode('makefile', function() {1213var words = {};1415function tokenBase(stream, state) {16if (stream.eatSpace()) return null;1718var sol = stream.sol();19var ch = stream.next();20var cur = stream.current();2122if (ch === '@') { return "atom"; }2324if (sol) {2526if (ch === '#') {27if (stream.eat('!')) {28stream.skipToEnd();29return 'meta';30}31stream.skipToEnd();32return 'tag';33}3435// if, ifdef, ifndef, ifeq, ifneq36if (ch === 'i' && (stream.match('f ') || stream.match('fdef ') || stream.match('fndef ') || stream.match('feq (') || stream.match('fneq ('))) {37stream.skipToEnd();38return "bracket";39}40// else, endif41if (ch === 'e' && (stream.match('lse') || stream.match('ndif'))) { return "bracket"; }42// include43if (ch === 'i' && stream.match('nclude ')) { return "string"; }44// -include45if (ch === '-' && stream.match('include ')) { return "string"; }46// vpath47if (ch === 'v' && stream.match('path ')) { return "string"; }4849// makros50if ((stream.match(/^[\w]+[\s]+/) || stream.match(/^[\w]+/)) &&51(stream.peek() === '=' ||52((stream.match('?') || stream.match('+') || stream.match('-')) && stream.peek() === '='))53) { return "variable-2"; }5455// Makefile targets56if ( stream.eat(':') || stream.match(/^[\w]+:/) || stream.match(/^(.)+[\w]+:/) ||57(ch === '$' && stream.match(/^\(+[\w]+\)+/) && stream.eat(':'))58) {59if (stream.peek() === '=') {60return "variable-2";61} else {62return "header";63}64}6566} else {6768if (ch === '*') { return "quote"; }69if (ch === '%') { return 'atom'; }70if (ch === '\\' && stream.eol()) { return "comment"; }71if (ch === '#') {72stream.skipToEnd();73return 'tag';74}7576if ((stream.eat(':') || stream.eat('+')) && stream.peek('=')) { return "variable-2"; }7778if (ch === '$' && stream.eat('$') && stream.match(/^[\w]+/)) { return "variable-2"; }79if (ch === '$' && stream.eat('(')) {80state.tokens.unshift(tokenDollar);81return tokenize(stream, state);82}83if (ch === '$' && stream.eat('{')) {84state.tokens.unshift(tokenDollarB);85return tokenize(stream, state);86}87if (ch === '$' && (stream.eat('@') || stream.eat('<') || stream.eat('^'))) { return "quote"; }8889if (ch === '\'' || ch === '"' || ch === '`') {90state.tokens.unshift(tokenString(ch));91return tokenize(stream, state);92}93}9495stream.eatWhile(/[\w-]/);96return words.hasOwnProperty(cur) ? words[cur] : null;97}9899function tokenString(quote) {100return function(stream, state) {101var next, end = false, escaped = false;102while ((next = stream.next()) != null) {103if (next === quote && !escaped) {104end = true;105break;106}107}108if (end || !escaped) {109state.tokens.shift();110}111return ((quote === ')' || quote === '}') ? 'variable-2' : 'string');112};113};114115var tokenDollar = function(stream, state) {116if (state.tokens.length > 1) stream.eat('$');117state.tokens[0] = tokenString(')');118return tokenize(stream, state);119};120var tokenDollarB = function(stream, state) {121if (state.tokens.length > 1) stream.eat('$');122state.tokens[0] = tokenString('}');123return tokenize(stream, state);124};125126function tokenize(stream, state) {127return (state.tokens[0] || tokenBase) (stream, state);128};129130return {131startState: function() {return {tokens:[]};},132token: function(stream, state) {133return tokenize(stream, state);134},135lineComment: "#"136};137});138139CodeMirror.defineMIME('text/x-makefile', 'makefile');140141142143