diff --git a/demo/kitchen-sink/docs/drools.drl b/demo/kitchen-sink/docs/drools.drl new file mode 100644 index 00000000000..80e7b78425b --- /dev/null +++ b/demo/kitchen-sink/docs/drools.drl @@ -0,0 +1,127 @@ +/* + * Copyright 2010 JBoss Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + Original source + https://github.com/droolsjbpm/drools/blob/master/drools-examples/ + http://docs.jboss.org/drools/ +*/ +package com.example.ace + +import java.math.BigDecimal +import function my.package.Foo.hello + +declare FactType + @author( Bob ) + id : String + name : String @maxLength(100) @notnull + + value : BigDecimal +end + +declare FactType2 extends AnotherType +end + +declare trait TraitType extends com.package.AnotherType +end + + +declare trait GoldenCustomer + balance : long @Alias( "org.acme.foo.accountBalance" ) +end + +global org.slf4j.Logger logger + +/** + * @param name who we'll salute? + */ +function String hello(String name) { + return "Hello "+name+"!"; +} + +rule "Trim all strings" + dialect "java" + no-loop +when // fdsfds + $s : String(a == null || == "empty", $g : size) + Cheese( name matches "(Buffalo)?\\S*Mozarella" ) + CheeseCounter( cheeses contains $var ) // contains with a variable + CheeseCounter( cheese memberof $matureCheeses ) + Cheese( name soundslike 'foobar' ) + Message( routingValue str[startsWith] "R1" ) + Cheese( name in ( "stilton", "cheddar", $cheese ) ) + Person( eval( age == girlAge + 2 ), sex = 'M' ) +then + /** + * TODO There mus be better way + */ + retract($s); + String a = "fd"; + a.toString(); + + insert($s.trim()); +end + +query isContainedIn( String x, String y ) + Location( x, y; ) + or + ( Location( z, y; ) and isContainedIn( x, z; ) ) +end + +rule "go" salience 10 +when + $s : String( ) +then + System.out.println( $s ); +end + +rule "When all English buses are not red" +when + not(forall( $bus : Bus( nationality == 'english') + Bus( this == $bus, color = 'red' ) )) +then + // What if all english buses are not red? +end + +rule "go1" +when + String( this == "go1" ) + isContainedIn("Office", "House"; ) +then + System.out.println( "office is in the house" ); +end + +rule "go2" +when + String( this == "go2" ) + isContainedIn("Draw", "House"; ) +then + System.out.println( "Draw in the House" ); +end + +/** + * Go Right + */ +rule GoRight dialect "mvel" salience (Math.abs( $df.colDiff )) when + $df : DirectionDiff(colDiff > 0 ) + $target : Cell( row == $df.row, col == ($df.col + 1) ) + CellContents( cell == $target, cellType != CellType.WALL ) + not Direction(character == $df.fromChar, horizontal == Direction.RIGHT ) +then + System.out.println( "monster right" ); + retract( $df ); + insert( new Direction($df.fromChar, Direction.RIGHT, Direction.NONE ) ); +end diff --git a/lib/ace/ext/modelist.js b/lib/ace/ext/modelist.js index fcd0b150f9a..5c394f86f52 100644 --- a/lib/ace/ext/modelist.js +++ b/lib/ace/ext/modelist.js @@ -67,6 +67,7 @@ var supportedModes = { Diff: ["diff|patch"], Dockerfile: ["^Dockerfile"], Dot: ["dot"], + Drools: ["drl"], Dummy: ["dummy"], DummySyntax: ["dummy"], Eiffel: ["e|ge"], diff --git a/lib/ace/mode/_test/tokens_drools.json b/lib/ace/mode/_test/tokens_drools.json new file mode 100644 index 00000000000..8df67565899 --- /dev/null +++ b/lib/ace/mode/_test/tokens_drools.json @@ -0,0 +1,935 @@ +[[ + "block.comment", + ["comment","/*"] +],[ + "block.comment", + ["comment.block"," * Copyright 2010 JBoss Inc"] +],[ + "block.comment", + ["comment.block"," *"] +],[ + "block.comment", + ["comment.block"," * Licensed under the Apache License, Version 2.0 (the \"License\");"] +],[ + "block.comment", + ["comment.block"," * you may not use this file except in compliance with the License."] +],[ + "block.comment", + ["comment.block"," * You may obtain a copy of the License at"] +],[ + "block.comment", + ["comment.block"," *"] +],[ + "block.comment", + ["comment.block"," * http://www.apache.org/licenses/LICENSE-2.0"] +],[ + "block.comment", + ["comment.block"," *"] +],[ + "block.comment", + ["comment.block"," * Unless required by applicable law or agreed to in writing, software"] +],[ + "block.comment", + ["comment.block"," * distributed under the License is distributed on an \"AS IS\" BASIS,"] +],[ + "block.comment", + ["comment.block"," * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied."] +],[ + "block.comment", + ["comment.block"," * See the License for the specific language governing permissions and"] +],[ + "block.comment", + ["comment.block"," * limitations under the License."] +],[ + "start", + ["comment.block"," */"] +],[ + "start" +],[ + "block.comment", + ["comment","/*"] +],[ + "block.comment", + ["comment.block"," Original source"] +],[ + "block.comment", + ["comment.block"," https://github.com/droolsjbpm/drools/blob/master/drools-examples/"] +],[ + "block.comment", + ["comment.block"," http://docs.jboss.org/drools/"] +],[ + "start", + ["comment.block","*/"] +],[ + "start", + ["keyword","package"], + ["text"," "], + ["entity.name.type","com.example.ace"] +],[ + "start" +],[ + "start", + ["keyword","import"], + ["text"," "], + ["entity.name.type","java.math.BigDecimal"] +],[ + "start", + ["keyword","import"], + ["text"," "], + ["keyword","function"], + ["text"," "], + ["entity.name.type","my.package.Foo.hello"] +],[ + "start" +],[ + "start", + ["keyword","declare"], + ["text"," "], + ["entity.name.type","FactType"] +],[ + "start", + ["text"," "], + ["entity.name.type","@author"], + ["paren.lparen","("], + ["text"," "], + ["identifier","Bob"], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["variable.other","id"], + ["text"," "], + ["text",":"], + ["text"," "], + ["support.class","String"] +],[ + "start", + ["text"," "], + ["variable.other","name"], + ["text"," "], + ["text",":"], + ["text"," "], + ["support.class","String"], + ["text"," "], + ["entity.name.type","@maxLength"], + ["paren.lparen","("], + ["constant.numeric","100"], + ["paren.rparen",")"], + ["text"," "], + ["entity.name.type","@notnull"] +],[ + "start" +],[ + "start", + ["text"," "], + ["variable.other","value"], + ["text"," "], + ["text",":"], + ["text"," "], + ["identifier","BigDecimal"] +],[ + "start", + ["keyword","end"] +],[ + "start" +],[ + "start", + ["keyword","declare"], + ["text"," "], + ["entity.name.type","FactType2"], + ["text"," "], + ["keyword","extends"], + ["text"," "], + ["entity.name.type","AnotherType"] +],[ + "start", + ["keyword","end"] +],[ + "start" +],[ + "start", + ["keyword","declare"], + ["text"," "], + ["keyword","trait"], + ["text"," "], + ["entity.name.type","TraitType"], + ["text"," "], + ["keyword","extends"], + ["text"," "], + ["entity.name.type","com.package.AnotherType"] +],[ + "start", + ["keyword","end"] +],[ + "start" +],[ + "start" +],[ + "start", + ["keyword","declare"], + ["text"," "], + ["keyword","trait"], + ["text"," "], + ["entity.name.type","GoldenCustomer"] +],[ + "start", + ["text"," "], + ["variable.other","balance"], + ["text"," "], + ["text",":"], + ["text"," "], + ["keyword","long"], + ["text"," "], + ["entity.name.type","@Alias"], + ["paren.lparen","("], + ["text"," "], + ["string","\"org.acme.foo.accountBalance\""], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["keyword","end"] +],[ + "start" +],[ + "start", + ["keyword","global"], + ["text"," "], + ["entity.name.type","org.slf4j.Logger"], + ["text"," "], + ["variable","logger"] +],[ + "start" +],[ + "doc-start", + ["comment.doc","/**"] +],[ + "doc-start", + ["comment.doc"," * "], + ["comment.doc.tag","@param"], + ["comment.doc"," name who we'll salute?"] +],[ + "start", + ["comment.doc"," */"] +],[ + "start", + ["keyword","function"], + ["text"," "], + ["support.class","String"], + ["text"," "], + ["identifier","hello"], + ["paren.lparen","("], + ["support.class","String"], + ["text"," "], + ["identifier","name"], + ["paren.rparen",")"], + ["text"," "], + ["paren.lparen","{"] +],[ + "start", + ["text"," "], + ["keyword","return"], + ["text"," "], + ["string","\"Hello \""], + ["keyword.operator","+"], + ["identifier","name"], + ["keyword.operator","+"], + ["string","\"!\""], + ["text",";"] +],[ + "start", + ["paren.rparen","}"] +],[ + "start" +],[ + "start", + ["keyword","rule"], + ["text"," "], + ["entity.name","\"Trim all strings\""] +],[ + "start", + ["text"," "], + ["keyword","dialect"], + ["text"," "], + ["string","\"java\""] +],[ + "start", + ["text"," "], + ["keyword","no"], + ["keyword.operator","-"], + ["keyword","loop"] +],[ + "start", + ["keyword","when"], + ["text"," "], + ["comment","// fdsfds"] +],[ + "start", + ["text"," "], + ["variable.other","$s"], + ["text"," "], + ["text",":"], + ["text"," "], + ["support.class","String"], + ["paren.lparen","("], + ["identifier","a"], + ["text"," "], + ["keyword.operator","=="], + ["text"," "], + ["constant.language","null"], + ["text"," "], + ["keyword.operator","||"], + ["text"," "], + ["keyword.operator","=="], + ["text"," "], + ["string","\"empty\""], + ["text",", "], + ["variable.other","$g"], + ["text"," "], + ["text",":"], + ["text"," "], + ["identifier","size"], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["identifier","Cheese"], + ["paren.lparen","("], + ["text"," "], + ["identifier","name"], + ["text"," "], + ["keyword","matches"], + ["text"," "], + ["string","\"(Buffalo)?\\\\S*Mozarella\""], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["identifier","CheeseCounter"], + ["paren.lparen","("], + ["text"," "], + ["identifier","cheeses"], + ["text"," "], + ["keyword","contains"], + ["text"," "], + ["identifier","$var"], + ["text"," "], + ["paren.rparen",")"], + ["text"," "], + ["comment","// contains with a variable"] +],[ + "start", + ["text"," "], + ["identifier","CheeseCounter"], + ["paren.lparen","("], + ["text"," "], + ["identifier","cheese"], + ["text"," "], + ["keyword","memberof"], + ["text"," "], + ["identifier","$matureCheeses"], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["identifier","Cheese"], + ["paren.lparen","("], + ["text"," "], + ["identifier","name"], + ["text"," "], + ["keyword","soundslike"], + ["text"," "], + ["string","'foobar'"], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["identifier","Message"], + ["paren.lparen","("], + ["text"," "], + ["identifier","routingValue"], + ["text"," "], + ["keyword","str"], + ["paren.lparen","["], + ["identifier","startsWith"], + ["paren.rparen","]"], + ["text"," "], + ["string","\"R1\""], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["identifier","Cheese"], + ["paren.lparen","("], + ["text"," "], + ["identifier","name"], + ["text"," "], + ["keyword","in"], + ["text"," "], + ["paren.lparen","("], + ["text"," "], + ["string","\"stilton\""], + ["text",", "], + ["string","\"cheddar\""], + ["text",", "], + ["identifier","$cheese"], + ["text"," "], + ["paren.rparen",")"], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["identifier","Person"], + ["paren.lparen","("], + ["text"," "], + ["keyword","eval"], + ["paren.lparen","("], + ["text"," "], + ["identifier","age"], + ["text"," "], + ["keyword.operator","=="], + ["text"," "], + ["identifier","girlAge"], + ["text"," "], + ["keyword.operator","+"], + ["text"," "], + ["constant.numeric","2"], + ["text"," "], + ["paren.rparen",")"], + ["text",", "], + ["identifier","sex"], + ["text"," "], + ["keyword.operator","="], + ["text"," "], + ["string","'M'"], + ["text"," "], + ["paren.rparen",")"] +],[ + "java-start", + ["keyword","then"] +],[ + "java-doc-start", + ["text"," "], + ["comment.doc","/**"] +],[ + "java-doc-start", + ["comment.doc"," * "], + ["comment.doc.tag.storage.type","TODO"], + ["comment.doc"," There mus be better way"] +],[ + "java-start", + ["comment.doc"," */"] +],[ + "java-start", + ["text"," "], + ["support.function","retract"], + ["lparen","("], + ["identifier","$s"], + ["rparen",")"], + ["text",";"] +],[ + "java-start", + ["text"," "], + ["support.function","String"], + ["text"," "], + ["identifier","a"], + ["text"," "], + ["keyword.operator","="], + ["text"," "], + ["string","\"fd\""], + ["text",";"] +],[ + "java-start", + ["text"," "], + ["identifier","a"], + ["text","."], + ["identifier","toString"], + ["lparen","("], + ["rparen",")"], + ["text",";"] +],[ + "java-start" +],[ + "java-start", + ["text"," "], + ["support.function","insert"], + ["lparen","("], + ["identifier","$s"], + ["text","."], + ["identifier","trim"], + ["lparen","("], + ["rparen","))"], + ["text",";"] +],[ + "start", + ["keyword","end"] +],[ + "start" +],[ + "start", + ["keyword","query"], + ["text"," "], + ["entity.name","isContainedIn"], + ["paren.lparen","("], + ["text"," "], + ["support.class","String"], + ["text"," "], + ["identifier","x"], + ["text",", "], + ["support.class","String"], + ["text"," "], + ["identifier","y"], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["identifier","Location"], + ["paren.lparen","("], + ["text"," "], + ["identifier","x"], + ["text",", "], + ["identifier","y"], + ["text","; "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["keyword","or"] +],[ + "start", + ["text"," "], + ["paren.lparen","("], + ["text"," "], + ["identifier","Location"], + ["paren.lparen","("], + ["text"," "], + ["identifier","z"], + ["text",", "], + ["identifier","y"], + ["text","; "], + ["paren.rparen",")"], + ["text"," "], + ["keyword","and"], + ["text"," "], + ["identifier","isContainedIn"], + ["paren.lparen","("], + ["text"," "], + ["identifier","x"], + ["text",", "], + ["identifier","z"], + ["text","; "], + ["paren.rparen",")"], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["keyword","end"] +],[ + "start" +],[ + "start", + ["keyword","rule"], + ["text"," "], + ["entity.name","\"go\""], + ["text"," "], + ["keyword","salience"], + ["text"," "], + ["constant.numeric","10"] +],[ + "start", + ["keyword","when"] +],[ + "start", + ["text"," "], + ["variable.other","$s"], + ["text"," "], + ["text",":"], + ["text"," "], + ["support.class","String"], + ["paren.lparen","("], + ["text"," "], + ["paren.rparen",")"] +],[ + "java-start", + ["keyword","then"] +],[ + "java-start", + ["text"," "], + ["support.function","System"], + ["text","."], + ["identifier","out"], + ["text","."], + ["identifier","println"], + ["lparen","("], + ["text"," "], + ["identifier","$s"], + ["text"," "], + ["rparen",")"], + ["text",";"] +],[ + "start", + ["keyword","end"] +],[ + "start" +],[ + "start", + ["keyword","rule"], + ["text"," "], + ["entity.name","\"When all English buses are not red\""] +],[ + "start", + ["keyword","when"] +],[ + "start", + ["text"," "], + ["keyword","not"], + ["paren.lparen","("], + ["keyword","forall"], + ["paren.lparen","("], + ["text"," "], + ["variable.other","$bus"], + ["text"," "], + ["text",":"], + ["text"," "], + ["identifier","Bus"], + ["paren.lparen","("], + ["text"," "], + ["identifier","nationality"], + ["text"," "], + ["keyword.operator","=="], + ["text"," "], + ["string","'english'"], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["identifier","Bus"], + ["paren.lparen","("], + ["text"," "], + ["keyword","this"], + ["text"," "], + ["keyword.operator","=="], + ["text"," "], + ["identifier","$bus"], + ["text",", "], + ["identifier","color"], + ["text"," "], + ["keyword.operator","="], + ["text"," "], + ["string","'red'"], + ["text"," "], + ["paren.rparen",")"], + ["text"," "], + ["paren.rparen","))"] +],[ + "java-start", + ["keyword","then"] +],[ + "java-start", + ["text"," "], + ["comment","// What if all english buses are not red?"] +],[ + "start", + ["keyword","end"] +],[ + "start" +],[ + "start", + ["keyword","rule"], + ["text"," "], + ["entity.name","\"go1\""] +],[ + "start", + ["keyword","when"] +],[ + "start", + ["text"," "], + ["support.class","String"], + ["paren.lparen","("], + ["text"," "], + ["keyword","this"], + ["text"," "], + ["keyword.operator","=="], + ["text"," "], + ["string","\"go1\""], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["identifier","isContainedIn"], + ["paren.lparen","("], + ["string","\"Office\""], + ["text",", "], + ["string","\"House\""], + ["text","; "], + ["paren.rparen",")"] +],[ + "java-start", + ["keyword","then"] +],[ + "java-start", + ["text"," "], + ["support.function","System"], + ["text","."], + ["identifier","out"], + ["text","."], + ["identifier","println"], + ["lparen","("], + ["text"," "], + ["string","\"office is in the house\""], + ["text"," "], + ["rparen",")"], + ["text",";"] +],[ + "start", + ["keyword","end"] +],[ + "start" +],[ + "start", + ["keyword","rule"], + ["text"," "], + ["entity.name","\"go2\""] +],[ + "start", + ["keyword","when"] +],[ + "start", + ["text"," "], + ["support.class","String"], + ["paren.lparen","("], + ["text"," "], + ["keyword","this"], + ["text"," "], + ["keyword.operator","=="], + ["text"," "], + ["string","\"go2\""], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["identifier","isContainedIn"], + ["paren.lparen","("], + ["string","\"Draw\""], + ["text",", "], + ["string","\"House\""], + ["text","; "], + ["paren.rparen",")"] +],[ + "java-start", + ["keyword","then"] +],[ + "java-start", + ["text"," "], + ["support.function","System"], + ["text","."], + ["identifier","out"], + ["text","."], + ["identifier","println"], + ["lparen","("], + ["text"," "], + ["string","\"Draw in the House\""], + ["text"," "], + ["rparen",")"], + ["text",";"] +],[ + "start", + ["keyword","end"] +],[ + "start" +],[ + "doc-start", + ["comment.doc","/**"] +],[ + "doc-start", + ["comment.doc"," * Go Right"] +],[ + "start", + ["comment.doc"," */"] +],[ + "start", + ["keyword","rule"], + ["text"," "], + ["entity.name","GoRight"], + ["text"," "], + ["keyword","dialect"], + ["text"," "], + ["string","\"mvel\""], + ["text"," "], + ["keyword","salience"], + ["text"," "], + ["paren.lparen","("], + ["support.class","Math"], + ["text","."], + ["identifier","abs"], + ["paren.lparen","("], + ["text"," "], + ["identifier","$df"], + ["text","."], + ["identifier","colDiff"], + ["text"," "], + ["paren.rparen","))"], + ["text"," "], + ["keyword","when"] +],[ + "start", + ["text"," "], + ["variable.other","$df"], + ["text"," "], + ["text",":"], + ["text"," "], + ["identifier","DirectionDiff"], + ["paren.lparen","("], + ["identifier","colDiff"], + ["text"," "], + ["keyword.operator",">"], + ["text"," "], + ["constant.numeric","0"], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["variable.other","$target"], + ["text"," "], + ["text",":"], + ["text"," "], + ["identifier","Cell"], + ["paren.lparen","("], + ["text"," "], + ["identifier","row"], + ["text"," "], + ["keyword.operator","=="], + ["text"," "], + ["identifier","$df"], + ["text","."], + ["identifier","row"], + ["text",", "], + ["identifier","col"], + ["text"," "], + ["keyword.operator","=="], + ["text"," "], + ["paren.lparen","("], + ["identifier","$df"], + ["text","."], + ["identifier","col"], + ["text"," "], + ["keyword.operator","+"], + ["text"," "], + ["constant.numeric","1"], + ["paren.rparen",")"], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["identifier","CellContents"], + ["paren.lparen","("], + ["text"," "], + ["identifier","cell"], + ["text"," "], + ["keyword.operator","=="], + ["text"," "], + ["identifier","$target"], + ["text",", "], + ["identifier","cellType"], + ["text"," "], + ["keyword.operator","!="], + ["text"," "], + ["identifier","CellType"], + ["text","."], + ["identifier","WALL"], + ["text"," "], + ["paren.rparen",")"] +],[ + "start", + ["text"," "], + ["keyword","not"], + ["text"," "], + ["identifier","Direction"], + ["paren.lparen","("], + ["identifier","character"], + ["text"," "], + ["keyword.operator","=="], + ["text"," "], + ["identifier","$df"], + ["text","."], + ["identifier","fromChar"], + ["text",", "], + ["identifier","horizontal"], + ["text"," "], + ["keyword.operator","=="], + ["text"," "], + ["identifier","Direction"], + ["text","."], + ["identifier","RIGHT"], + ["text"," "], + ["paren.rparen",")"] +],[ + "java-start", + ["keyword","then"] +],[ + "java-start", + ["text"," "], + ["support.function","System"], + ["text","."], + ["identifier","out"], + ["text","."], + ["identifier","println"], + ["lparen","("], + ["text"," "], + ["string","\"monster right\""], + ["text"," "], + ["rparen",")"], + ["text",";"] +],[ + "java-start", + ["text"," "], + ["support.function","retract"], + ["lparen","("], + ["text"," "], + ["identifier","$df"], + ["text"," "], + ["rparen",")"], + ["text",";"] +],[ + "java-start", + ["text"," "], + ["support.function","insert"], + ["lparen","("], + ["text"," "], + ["keyword","new"], + ["text"," "], + ["identifier","Direction"], + ["lparen","("], + ["identifier","$df"], + ["text","."], + ["identifier","fromChar"], + ["text",", "], + ["identifier","Direction"], + ["text","."], + ["identifier","RIGHT"], + ["text",", "], + ["identifier","Direction"], + ["text","."], + ["identifier","NONE"], + ["text"," "], + ["rparen",")"], + ["text"," "], + ["rparen",")"], + ["text",";"] +],[ + "start", + ["keyword","end"] +],[ + "start" +]] \ No newline at end of file diff --git a/lib/ace/mode/drools.js b/lib/ace/mode/drools.js new file mode 100644 index 00000000000..1f408c59da7 --- /dev/null +++ b/lib/ace/mode/drools.js @@ -0,0 +1,55 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2014, 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 DroolsHighlightRules = require("./drools_highlight_rules").DroolsHighlightRules; +var Range = require("../range").Range; +var DroolsFoldMode = require("./folding/drools").FoldMode; + +var Mode = function() { + this.HighlightRules = DroolsHighlightRules; + this.foldingRules = new DroolsFoldMode(); + +}; +oop.inherits(Mode, TextMode); + +(function() { + this.lineCommentStart = "//"; + this.$id = "ace/mode/drools"; +}).call(Mode.prototype); + +exports.Mode = Mode; + +}); + diff --git a/lib/ace/mode/drools_highlight_rules.js b/lib/ace/mode/drools_highlight_rules.js new file mode 100644 index 00000000000..59d32c48a60 --- /dev/null +++ b/lib/ace/mode/drools_highlight_rules.js @@ -0,0 +1,262 @@ +/* ***** 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 TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; +var JavaHighlightRules = require("./java_highlight_rules").JavaHighlightRules; +var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; + +var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*"; +var packageIdentifierRe = "[a-zA-Z\\$_\u00a1-\uffff][\\.a-zA-Z\\d\\$_\u00a1-\uffff]*"; + +var DroolsHighlightRules = function() { + + var keywords = ("date|effective|expires|lock|on|active|no|loop|auto|focus" + + "|activation|group|agenda|ruleflow|duration|timer|calendars|refract|direct" + + "|dialect|salience|enabled|attributes|extends|template" + + "|function|contains|matches|eval|excludes|soundslike" + + "|memberof|not|in|or|and|exists|forall|over|from|entry|point|accumulate|acc|collect" + + "|action|reverse|result|end|init|instanceof|extends|super|boolean|char|byte|short" + + "|int|long|float|double|this|void|class|new|case|final|if|else|for|while|do" + + "|default|try|catch|finally|switch|synchronized|return|throw|break|continue|assert" + + "|modify|static|public|protected|private|abstract|native|transient|volatile" + + "|strictfp|throws|interface|enum|implements|type|window|trait|no-loop|str" + ); + + var langClasses = ( + "AbstractMethodError|AssertionError|ClassCircularityError|"+ + "ClassFormatError|Deprecated|EnumConstantNotPresentException|"+ + "ExceptionInInitializerError|IllegalAccessError|"+ + "IllegalThreadStateException|InstantiationError|InternalError|"+ + "NegativeArraySizeException|NoSuchFieldError|Override|Process|"+ + "ProcessBuilder|SecurityManager|StringIndexOutOfBoundsException|"+ + "SuppressWarnings|TypeNotPresentException|UnknownError|"+ + "UnsatisfiedLinkError|UnsupportedClassVersionError|VerifyError|"+ + "InstantiationException|IndexOutOfBoundsException|"+ + "ArrayIndexOutOfBoundsException|CloneNotSupportedException|"+ + "NoSuchFieldException|IllegalArgumentException|NumberFormatException|"+ + "SecurityException|Void|InheritableThreadLocal|IllegalStateException|"+ + "InterruptedException|NoSuchMethodException|IllegalAccessException|"+ + "UnsupportedOperationException|Enum|StrictMath|Package|Compiler|"+ + "Readable|Runtime|StringBuilder|Math|IncompatibleClassChangeError|"+ + "NoSuchMethodError|ThreadLocal|RuntimePermission|ArithmeticException|"+ + "NullPointerException|Long|Integer|Short|Byte|Double|Number|Float|"+ + "Character|Boolean|StackTraceElement|Appendable|StringBuffer|"+ + "Iterable|ThreadGroup|Runnable|Thread|IllegalMonitorStateException|"+ + "StackOverflowError|OutOfMemoryError|VirtualMachineError|"+ + "ArrayStoreException|ClassCastException|LinkageError|"+ + "NoClassDefFoundError|ClassNotFoundException|RuntimeException|"+ + "Exception|ThreadDeath|Error|Throwable|System|ClassLoader|"+ + "Cloneable|Class|CharSequence|Comparable|String|Object" + ); + + var keywordMapper = this.createKeywordMapper({ + "variable.language": "this", + "keyword": keywords, + "constant.language": "null", + "support.class" : langClasses, + "support.function" : "retract|update|modify|insert" + }, "identifier"); + + // regexp must not have capturing parentheses. Use (?:) instead. + // regexps are ordered -> the first match is used + + var stringRules = function() { + return [{ + token : "string", // single line + regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' + }, { + token : "string", // single line + regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" + }]; + }; + + + var basicPreRules = function(blockCommentRules) { + return [{ + token : "comment", + regex : "\\/\\/.*$" + }, + DocCommentHighlightRules.getStartRule("doc-start"), + { + token : "comment", // multi line comment + regex : "\\/\\*", + next : blockCommentRules + }, { + token : "constant.numeric", // hex + regex : "0[xX][0-9a-fA-F]+\\b" + }, { + token : "constant.numeric", // float + regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" + }, { + token : "constant.language.boolean", + regex : "(?:true|false)\\b" + }]; + }; + + var blockCommentRules = function(returnRule) { + return [ + { + token : "comment.block", // closing comment + regex : ".*?\\*\\/", + next : returnRule + }, { + token : "comment.block", // comment spanning whole line + regex : ".+" + } + ]; + } + + var basicPostRules = function() { + return [{ + token : keywordMapper, + // TODO: Unicode escape sequences + // TODO: Unicode identifiers + regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + }, { + token : "keyword.operator", + regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)" + }, { + token : "lparen", + regex : "[[({]" + }, { + token : "rparen", + regex : "[\\])}]" + }, { + token : "text", + regex : "\\s+" + }]; + }; + + + this.$rules = { + "start" : [].concat(basicPreRules("block.comment"), [ + { + token : "entity.name.type", + regex : "@[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + }, { + // package com.example + token : ["keyword","text","entity.name.type"], + regex : "(package)(\\s+)(" + packageIdentifierRe +")" + }, { + // import function com.Util.staticMethod + token : ["keyword","text","keyword","text","entity.name.type"], + regex : "(import)(\\s+)(function)(\\s+)(" + packageIdentifierRe +")" + }, { + // import function com.Util.staticMethod + token : ["keyword","text","entity.name.type"], + regex : "(import)(\\s+)(" + packageIdentifierRe +")" + }, { + // global com.example.Type identifier + token : ["keyword","text","entity.name.type","text","variable"], + regex : "(global)(\\s+)(" + packageIdentifierRe +")(\\s+)(" + identifierRe +")" + }, { + // declare trait DeclaredType + token : ["keyword","text","keyword","text","entity.name.type"], + regex : "(declare)(\\s+)(trait)(\\s+)(" + identifierRe +")" + }, { + // declare trait DeclaredType + token : ["keyword","text","entity.name.type"], + regex : "(declare)(\\s+)(" + identifierRe +")" + }, { + // declare trait DeclaredType + token : ["keyword","text","entity.name.type"], + regex : "(extends)(\\s+)(" + packageIdentifierRe +")" + }, { + // rule ... + token : ["keyword","text"], + regex : "(rule)(\\s+)", + next : "asset.name" + }], + stringRules(), + [{ + // variable : + token : ["variable.other","text","text"], + regex : "(" + identifierRe + ")(\\s*)(:)", + }, { + // query ... + token : ["keyword","text"], + regex : "(query)(\\s+)", + next : "asset.name" + }, { + // when ... + token : ["keyword","text"], + regex : "(when)(\\s*)", + }, { + // then end + token : ["keyword","text"], + regex : "(then)(\\s*)", + next : "java-start" + }, { + token : "paren.lparen", + regex : /[\[({]/, + }, { + token : "paren.rparen", + regex : /[\])}]/ + }], basicPostRules()), + "block.comment" : blockCommentRules("start"), + "asset.name" : [ + { + token : "entity.name", + regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' + }, { + token : "entity.name", + regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" + }, { + token : "entity.name", + regex : identifierRe + }, { + regex: "", + token: "empty", + next: "start" + }] + }; + this.embedRules(DocCommentHighlightRules, "doc-", + [ DocCommentHighlightRules.getEndRule("start") ]); + + this.embedRules(JavaHighlightRules, "java-", [ + { + token : "support.function", + regex: "\\b(insert|modify|retract|update)\\b", + }, { + token : "keyword", + regex: "\\bend\\b", + next : "start" + }]); + +}; + +oop.inherits(DroolsHighlightRules, TextHighlightRules); + +exports.DroolsHighlightRules = DroolsHighlightRules; +}); diff --git a/lib/ace/mode/folding/drools.js b/lib/ace/mode/folding/drools.js new file mode 100644 index 00000000000..dfe1e66ec7b --- /dev/null +++ b/lib/ace/mode/folding/drools.js @@ -0,0 +1,49 @@ +define(function(require, exports, module) { +"use strict"; + +var oop = require("../../lib/oop"); +var Range = require("../../range").Range; +var BaseFoldMode = require("./fold_mode").FoldMode; +var TokenIterator = require("../../token_iterator").TokenIterator; + +var FoldMode = exports.FoldMode = function() {}; +oop.inherits(FoldMode, BaseFoldMode); + +(function() { + + // regular expressions that identify starting and stopping points + this.foldingStartMarker = /(rule|declare|query|when|then)/; + this.foldingStopMarker = /end/; + + this.getFoldWidgetRange = function(session, foldStyle, row) { + var line = session.getLine(row); + console.log(line); + var match = line.match(this.foldingStartMarker); + if (match) { + var i = match.index; + + if (match[1]) { + var position = {row: row, column: line.length}; + var iterator = new TokenIterator(session, position.row, position.column); + var seek = "end"; + var token = iterator.getCurrentToken(); + if (token.value == "when") { + seek = "then"; + } + while(token) { + if (token.value == seek) { + return Range.fromPoints(position + ,{row: iterator.getCurrentTokenRow(), + column: iterator.getCurrentTokenColumn()}); + } + token = iterator.stepForward(); + } + } + + } + // test each line, and return a range of segments to collapse + } + +}).call(FoldMode.prototype); + +}); \ No newline at end of file diff --git a/lib/ace/snippets/drools.js b/lib/ace/snippets/drools.js new file mode 100644 index 00000000000..c578eae49b8 --- /dev/null +++ b/lib/ace/snippets/drools.js @@ -0,0 +1,7 @@ +define(function(require, exports, module) { +"use strict"; + +exports.snippetText = require("../requirejs/text!./drools.snippets"); +exports.scope = "drools"; + +}); diff --git a/lib/ace/snippets/drools.snippets b/lib/ace/snippets/drools.snippets new file mode 100644 index 00000000000..3687bec18da --- /dev/null +++ b/lib/ace/snippets/drools.snippets @@ -0,0 +1,19 @@ + +snippet rule + rule "${1?:rule_name}" + when + ${2:// when...} + then + ${3:// then...} + end + +snippet query + query ${1?:query_name} + ${2:// find} + end + +snippet declare + declare ${1?:type_name} + ${2:// attributes} + end +