jrclogic / SMCDEL

A symbolic model checker for Dynamic Epistemic Logic.
https://w4eg.de/malvin/illc/smcdelweb
GNU General Public License v2.0
41 stars 9 forks source link

web: provide syntax highlighting for input format #32

Closed m4lvin closed 10 months ago

m4lvin commented 1 year ago

Highlighting keywords such as OBS would be nice, and also giving different colors to agents, formula connectives etc.

We are using Ace, so according to https://ace.c9.io/#nav=higlighter it should be easy to define our own highlighting mode. See https://ace.c9.io/tool/mode_creator.html and try to find a minimal example.

Other helpful notes: https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode

m4lvin commented 10 months ago

A first attempt, based off the COBOL rules :wink:

"use strict";

var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;

var SmcdelHighlightRules = function() {
    var keywords = "VARS|LAW|OBS|VALID|WHERE|TRUE"; // TODO: how to include "?"

    var builtinConstants = "AND|OR|knows|that|whether|comknow|";

    var builtinFunctions = "alice|bob|carol"; // unused

    var keywordMapper = this.createKeywordMapper({
        "support.function": builtinFunctions,
        "keyword": keywords,
        "constant.language": builtinConstants
    }, "identifier", true);

    this.$rules = {
        "start" : [ {
            token : "comment",
            regex : "--*.*$"
        }, {
            token : "constant.numeric", // float
            regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
        }, {
            token : keywordMapper,
            regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
        }, {
            token : "text",
            regex : "\\s+"
        } ]
    };
};

oop.inherits(SmcdelHighlightRules, TextHighlightRules);

exports.SmcdelHighlightRules = SmcdelHighlightRules;
m4lvin commented 10 months ago

Done in https://github.com/jrclogic/SMCDEL/commit/93d16c13919a9479f0af85c95b57c05a6e90bde9