From 2fc8ffcc38efddd94cfdde6d4b7e7470da1f0777 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 6 Mar 2013 20:04:54 +0400 Subject: [PATCH] add highlighting for LogicBlox --- demo/kitchen-sink/doclist.js | 1 + demo/kitchen-sink/docs/logicblox.logic | 16 +++ demo/kitchen-sink/modelist.js | 1 + lib/ace/mode/logicblox.js | 55 +++++++++ lib/ace/mode/logicblox_highlight_rules.js | 131 ++++++++++++++++++++++ 5 files changed, 204 insertions(+) create mode 100644 demo/kitchen-sink/docs/logicblox.logic create mode 100644 lib/ace/mode/logicblox.js create mode 100644 lib/ace/mode/logicblox_highlight_rules.js diff --git a/demo/kitchen-sink/doclist.js b/demo/kitchen-sink/doclist.js index a47c00e6..0a066afe 100644 --- a/demo/kitchen-sink/doclist.js +++ b/demo/kitchen-sink/doclist.js @@ -93,6 +93,7 @@ var docs = { "docs/lsl.lsl": "LSL", "docs/scheme.scm": "Scheme", "docs/liquid.liquid": "Liquid", + "docs/logicblox.logic": "LogicBlox", "docs/lua.lua": "Lua", "docs/lucene.lucene": "Lucene", "docs/luapage.lp": "LuaPage", diff --git a/demo/kitchen-sink/docs/logicblox.logic b/demo/kitchen-sink/docs/logicblox.logic new file mode 100644 index 00000000..910862d7 --- /dev/null +++ b/demo/kitchen-sink/docs/logicblox.logic @@ -0,0 +1,16 @@ +// ancestors +parentof("douglas", "john"). +parentof("john", "bob"). +parentof("bob", "ebbon"). + +parentof("douglas", "jane"). +parentof("jane", "jan"). + +ancestorof(A, B) <- parentof(A, B). +ancestorof(A, C) <- ancestorof(A, B), parentof(B,C). + +grandparentof(A, B) <- parentof(A, C), parentof(C, B). + +cousins(A,B) <- grandparentof(C,A), grandparentof(C,B). + +parentof[`arg](A, B) -> int[32](A), !string(B). \ No newline at end of file diff --git a/demo/kitchen-sink/modelist.js b/demo/kitchen-sink/modelist.js index 695a325f..1291ce66 100644 --- a/demo/kitchen-sink/modelist.js +++ b/demo/kitchen-sink/modelist.js @@ -65,6 +65,7 @@ var modesByName = { lisp: ["Lisp" , "lisp"], scheme: ["Scheme" , "scm|rkt"], liquid: ["Liquid" , "liquid"], + logicblox: ["LogicBlox" , "logic"], lua: ["Lua" , "lua"], luapage: ["LuaPage" , "lp"], // http://keplerproject.github.com/cgilua/manual.html#templates lucene: ["Lucene" , "lucene"], diff --git a/lib/ace/mode/logicblox.js b/lib/ace/mode/logicblox.js new file mode 100644 index 00000000..944533ad --- /dev/null +++ b/lib/ace/mode/logicblox.js @@ -0,0 +1,55 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2012, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var Tokenizer = require("../tokenizer").Tokenizer; +var LogicBloxHighlightRules = require("./logicblox_highlight_rules").LogicBloxHighlightRules; +// TODO: pick appropriate fold mode +var FoldMode = require("./folding/cstyle").FoldMode; + +var Mode = function() { + var highlighter = new LogicBloxHighlightRules(); + this.foldingRules = new FoldMode(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); +}; +oop.inherits(Mode, TextMode); + +(function() { + this.lineCommentStart = "//"; + this.blockComment = {start: "/*", end: "*/"}; + // Extra logic goes here. +}).call(Mode.prototype); + +exports.Mode = Mode; +}); \ No newline at end of file diff --git a/lib/ace/mode/logicblox_highlight_rules.js b/lib/ace/mode/logicblox_highlight_rules.js new file mode 100644 index 00000000..ea8573bb --- /dev/null +++ b/lib/ace/mode/logicblox_highlight_rules.js @@ -0,0 +1,131 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2012, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +/* THIS FILE WAS AUTOGENERATED FROM tool\LogicBlox.tmbundle\Syntaxes\LogicBlox.tmLanguage (UUID: 59bf5022-e261-453f-b1cb-9f9fa0712413) */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var LogicBloxHighlightRules = function() { + // regexp must not have capturing parentheses. Use (?:) instead. + // regexps are ordered -> the first match is used + + this.$rules = { start: + [ { token: 'comment.block', + regex: '/\\*', + push: + [ { token: 'comment.block', regex: '\\*/', next: 'pop' }, + { defaultToken: 'comment.block' } ], + //A block comment. + }, + { token: 'comment.single', + regex: '//.*', + //A single line comment. + }, + { token: 'constant.numeric', + regex: '\\d+', + //An integer constant. + }, + { token: 'constant.numeric', + regex: '\\d+(.\\d+){,1}[eE][+-]{,1}\\d+', + //Real numbers. + }, + { token: 'string', + regex: '"', + push: + [ { token: 'string', regex: '"', next: 'pop' }, + { defaultToken: 'string' } ], + //Strings + }, + { token: 'constant.language', + regex: '\\b(true|false)\\b', + //Boolean values. + }, + { token: 'entity.name.type.logicblox', + regex: '`[a-zA-Z_:]+(\\d|\\a)*\\b', + //LogicBlox Symbol + }, + { token: 'keyword.other', regex: '->', comment: 'Constraint' }, + { token: 'keyword.other', + regex: '-->', + //Level 1 Constraint + }, + { token: 'keyword.other', regex: '<-', comment: 'Rule' }, + { token: 'keyword.other', regex: '<--', comment: 'Level 1 Rule' }, + { token: 'keyword.other', regex: '\\.', comment: 'Terminator' }, + { token: 'keyword.other', regex: '!', comment: 'Negation' }, + { token: 'keyword.other', regex: ',', comment: 'Conjunction' }, + { token: 'keyword.other', regex: ';', comment: 'Disjunction' }, + { token: 'keyword.operator', + regex: '<=|>=|!=|<|>', + //Equality + }, + { token: 'keyword.other', regex: '@', comment: 'Equality' }, + { token: 'keyword.operator', + regex: '\\+|-|\\*|/', + //Arithmetic operations + }, + { token: 'keyword', regex: '::', comment: 'Colon colon' }, + { token: 'support.function', + regex: '\\b(agg\\s*<<)', + push: + [ { include: '$self' }, + { token: 'support.function', + regex: '>>', + next: 'pop' } ], + //Aggregations + }, + { token: 'storage.modifier', + regex: '\\b(lang:[\\w:]*)', + //All the lang system predicates + }, + { token: [ 'storage.type', 'text' ], + regex: '(export|sealed|clauses|block|alias)\\s*\\((?=`)', + //Module keywords + }, + { token: 'entity.name', + regex: '[a-zA-Z_][a-zA-Z_0-9:]*(@prev|@init|@final)?(?=(\\(|\\[))', + //A predicate name. + }, + { token: 'variable.parameter', + regex: '([a-zA-Z][a-zA-Z_0-9]*|_)\\s*(?=(,|\\.|<-|->|\\)|\\]|=))', + //A variable to a functional predicate. + } ] } + + this.normalizeRules(); +}; + +oop.inherits(LogicBloxHighlightRules, TextHighlightRules); + +exports.LogicBloxHighlightRules = LogicBloxHighlightRules; +}); \ No newline at end of file