New syntax definition (PlantUML2)

283 views
Skip to first unread message

Manuel López

unread,
Nov 14, 2014, 12:49:12 PM11/14/14
to ace-d...@googlegroups.com
Hello!

I'm using the Ace Mode Creator to create a new syntax hightlighter for the PlantUML2 pseudo-code.

It works well, now I'd like to get some help to see if it can be added to the project, after some corrections (it keeps expecting a semi-colon to terminate a sentence, Idon't know why...)

AND (this is kind-of-off-topic, I fear) any help to add the syntaxt definition to the SlimText editor (a Chrome's extension which uses ACE editor).

Thanks. BTW, this is the code:

/**
 * based on
 * " Vim PlantUML syntax file
 * "    Language: PlantUML2
 * "    Revision: 0.1
 * "  Maintainer: Manuel López <nic...@gmail.com>
 * " Last Change: 2014-11-12
 **/
ace.define(
    "ace/mode/plantuml",
    ["require","exports","module","ace/lib/oop","ace/mode/text","ace/tokenizer","ace/mode/plantuml_highlight_rules","ace/range"],
    function(e,t,n){
        var r=e("../lib/oop"),
        i=e("./text").Mode,
        s=e("../tokenizer").Tokenizer,
        o=e("./plantuml_highlight_rules").PlantUmlHighlightRules,
        u=e("../range").Range,
        a=function(){
            this.HighlightRules=o
        };
        r.inherits(a,i),
        function(){
            this.lineCommentStart="--",
            this.$id="ace/mode/plantuml"
        }.call(a.prototype),
        t.Mode=a
    }
),
ace.define(
    "ace/mode/plantuml",
    ["require","exports","module","ace/lib/oop","ace/mode/text","ace/tokenizer","ace/mode/plantuml_highlight_rules","ace/range"],
    function(require, exports, module) {
        "use strict";
        var oop = require("../lib/oop");
        var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;

        var lang  = "!(?:autonumber|skinparam|include|ifdef|define|endif)";
            lang += "|top to bottom|direction|left to right|width|height";
            lang += "|title|hide footbox|header|endheader|legend|endlegend|newpage";
            lang += "|center|footer|scale|autonumber";

        // skinparam keywords
        var skinKeywords = "|activityArrowColor|activityArrowFontColor|activityArrowFontName";
            skinKeywords+= "|activityArrowFontSize|activityArrowFontStyle|activityBackgroundColor";
            skinKeywords+= "|activityBarColor|activityBorderColor|activityEndColor|activityFontColor";
            skinKeywords+= "|activityFontName|activityFontSize|activityFontStyle|activityStartColor";
            skinKeywords+= "|backgroundColor|circledCharacterFontColor|circledCharacterFontName";
            skinKeywords+= "|circledCharacterFontSize|circledCharacterFontStyle|circledCharacterRadius";
            skinKeywords+= "|classArrowColor|classArrowFontColor|classArrowFontName|classArrowFontSize";
            skinKeywords+= "|classArrowFontStyle|classAttributeFontColor|classAttributeFontName";
            skinKeywords+= "|classAttributeFontSize|classAttributeFontStyle|classAttributeIconSize";
            skinKeywords+= "|classBackgroundColor|classBorderColor|classFontColor|classFontName";
            skinKeywords+= "|classFontSize|classFontStyle|classStereotypeFontColor|classStereotypeFontName";
            skinKeywords+= "|classStereotypeFontSize|classStereotypeFontStyle|componentArrowColor";
            skinKeywords+= "|componentArrowFontColor|componentArrowFontName|componentArrowFontSize";
            skinKeywords+= "|componentArrowFontStyle|componentBackgroundColor|componentBorderColor";
            skinKeywords+= "|componentFontColor|componentFontName|componentFontSize|componentFontStyle";
            skinKeywords+= "|componentInterfaceBackgroundColor|componentInterfaceBorderColor";
            skinKeywords+= "|componentStereotypeFontColor|componentStereotypeFontName";
            skinKeywords+= "|componentStereotypeFontSize|componentStereotypeFontStyle|footerFontColor";
            skinKeywords+= "|footerFontName|footerFontSize|footerFontStyle|headerFontColor|headerFontName";
            skinKeywords+= "|headerFontSize|headerFontStyle|noteBackgroundColor|noteBorderColor";
            skinKeywords+= "|noteFontColor|noteFontName|noteFontSize|noteFontStyle|packageBackgroundColor";
            skinKeywords+= "|packageBorderColor|packageFontColor|packageFontName|packageFontSize";
            skinKeywords+= "|packageFontStyle|sequenceActorBackgroundColor|sequenceActorBorderColor";
            skinKeywords+= "|sequenceActorFontColor|sequenceActorFontName|sequenceActorFontSize";
            skinKeywords+= "|sequenceActorFontStyle|sequenceArrowColor|sequenceArrowFontColor";
            skinKeywords+= "|sequenceArrowFontName|sequenceArrowFontSize|sequenceArrowFontStyle";
            skinKeywords+= "|sequenceDividerBackgroundColor|sequenceDividerFontColor|sequenceDividerFontName";
            skinKeywords+= "|sequenceDividerFontSize|sequenceDividerFontStyle|sequenceGroupBackgroundColor";
            skinKeywords+= "|sequenceGroupingFontColor|sequenceGroupingFontName|sequenceGroupingFontSize";
            skinKeywords+= "|sequenceGroupingFontStyle|sequenceGroupingHeaderFontColor";
            skinKeywords+= "|sequenceGroupingHeaderFontName|sequenceGroupingHeaderFontSize";
            skinKeywords+= "|sequenceGroupingHeaderFontStyle|sequenceLifeLineBackgroundColor";
            skinKeywords+= "|sequenceLifeLineBorderColor|sequenceParticipantBackgroundColor";
            skinKeywords+= "|sequenceParticipantBorderColor|sequenceParticipantFontColor";
            skinKeywords+= "|sequenceParticipantFontName|sequenceParticipantFontSize";
            skinKeywords+= "|sequenceParticipantFontStyle|sequenceTitleFontColor|sequenceTitleFontName";
            skinKeywords+= "|sequenceTitleFontSize|sequenceTitleFontStyle|stateArrowColor";
            skinKeywords+= "|stateArrowFontColor|stateArrowFontName|stateArrowFontSize|stateArrowFontStyle";
            skinKeywords+= "|stateAttributeFontColor|stateAttributeFontName|stateAttributeFontSize";
            skinKeywords+= "|stateAttributeFontStyle|stateBackgroundColor|stateBorderColor|stateEndColor";
            skinKeywords+= "|stateFontColor|stateFontName|stateFontSize|stateFontStyle|stateStartColor";
            skinKeywords+= "|stereotypeABackgroundColor|stereotypeCBackgroundColor";
            skinKeywords+= "|stereotypeEBackgroundColor|stereotypeIBackgroundColor|titleFontColor";
            skinKeywords+= "|titleFontName|titleFontSize|titleFontStyle|usecaseActorBackgroundColor";
            skinKeywords+= "|usecaseActorBorderColor|usecaseActorFontColor|usecaseActorFontName";
            skinKeywords+= "|usecaseActorFontSize|usecaseActorFontStyle|usecaseActorStereotypeFontColor";
            skinKeywords+= "|usecaseActorStereotypeFontName|usecaseActorStereotypeFontSize";
            skinKeywords+= "|usecaseActorStereotypeFontStyle|usecaseArrowColor|usecaseArrowFontColor";
            skinKeywords+= "|usecaseArrowFontName|usecaseArrowFontSize|usecaseArrowFontStyle";
            skinKeywords+= "|usecaseBackgroundColor|usecaseBorderColor|usecaseFontColor|usecaseFontName";
            skinKeywords+= "|usecaseFontSize|usecaseFontStyle|usecaseStereotypeFontColor";
            skinKeywords+= "|usecaseStereotypeFontName|usecaseStereotypeFontSize|usecaseStereotypeFontStyle";
            skinKeywords+= "|ActorBackgroundColor|ActorBorderColor|ActorFontColor|ActorFontName";
            skinKeywords+= "|ActorFontSize|ActorFontStyle|ActorStereotypeFontColor|ActorStereotypeFontName";
            skinKeywords+= "|ActorStereotypeFontSize|ActorStereotypeFontStyle|ArrowColor|ArrowFontColor";
            skinKeywords+= "|ArrowFontName|ArrowFontSize|ArrowFontStyle|AttributeFontColor|AttributeFontName";
            skinKeywords+= "|AttributeFontSize|AttributeFontStyle|AttributeIconSize|BackgroundColor|BarColor";
            skinKeywords+= "|BorderColor|CharacterFontColor|CharacterFontName|CharacterFontSize";
            skinKeywords+= "|CharacterFontStyle|CharacterRadius|Color|DividerBackgroundColor";
            skinKeywords+= "|DividerFontColor|DividerFontName|DividerFontSize|DividerFontStyle|EndColor";
            skinKeywords+= "|FontColor|FontName|FontSize|FontStyle|GroupBackgroundColor|GroupingFontColor";
            skinKeywords+= "|GroupingFontName|GroupingFontSize|GroupingFontStyle|GroupingHeaderFontColor";
            skinKeywords+= "|GroupingHeaderFontName|GroupingHeaderFontSize|GroupingHeaderFontStyle";
            skinKeywords+= "|InterfaceBackgroundColor|InterfaceBorderColor|LifeLineBackgroundColor";
            skinKeywords+= "|LifeLineBorderColor|ParticipantBackgroundColor|ParticipantBorderColor";
            skinKeywords+= "|ParticipantFontColor|ParticipantFontName|ParticipantFontSize";
            skinKeywords+= "|ParticipantFontStyle|StartColor|stateArrowColor|stereotypeABackgroundColor";
            skinKeywords+= "|stereotypeCBackgroundColor|stereotypeEBackgroundColor|StereotypeFontColor";
            skinKeywords+= "|StereotypeFontName|StereotypeFontSize|StereotypeFontStyle";
            skinKeywords+= "|stereotypeIBackgroundColor|TitleFontColor|TitleFontName|TitleFontSize|TitleFontStyle";

        var plantFunctions = "|actor|boundary|control|entity|database|participant"; // Sequence Diagram objects
            plantFunctions+= "|alt|else|opt|loop|par|break|critical|group|box";     // Sequence Diagram grouping controls
            plantFunctions+= "|note|rnote|hnote|right|left|top|bottom|over|of|end"; // PlantUML2 notes
            plantFunctions+= "|activate|create|deactivate|destroy";                 // Sequence Diagram lifeline controls
            plantFunctions+= "|usecase|rectangle";                               // Use Case Diagram objects
            plantFunctions+= "|start|stop|if|then|else|endif|repeat|while|endwhile";// Activity Diagram controls
            plantFunctions+= "|fork|forkagain|endfork|partition|\\|Swimlane\\w+\\||detach";
            plantFunctions+= "|class|\\{(?:abstract|static|classifier)\\}";         // Class diagram objects and controls
            plantFunctions+= "|abstract|interface|annotation|enum|hide";
            plantFunctions+= "|hide empty (?:members|attributes|methods|circle|stereotype|fields)";
            plantFunctions+= "|show (?:members|attributes|methods|circle|stereotype|fields)";
            plantFunctions+= "|package(?:<<(?:Node|Rect|Folder|Frame|Cloud|Database)>>)?|";
            plantFunctions+= "|namespace|set\\snamespaceSeparator";
            plantFunctions+= "|package|node|folder|frame|cloud|database";           // Component Diagram group
            plantFunctions+= "|\\[\\*\\]|state";
            plantFunctions+= "|object";
            //plantFunctions+= "|";

        var constants = "right|left|up|down|over|of|as|is";

        var plantUMLHighlightRules = function() {

            var keywordMapper = this.createKeywordMapper({
                "variable.language":  lang,
                "variable.parameter": skinKeywords,
                "keyword.function":   plantFunctions,
                "keyword.constant":   constants,
                "support.type":
                    "bool(?:ean)?|string|int(?:eger)?|float|double|(?:var)?char|" +
                    "decimal|date|time|timestamp|array|void|none",
            }, "text", true, "|");

            this.$rules = {
                "start" : [
                    {token : "string", regex : '"', next  : "string"},
                    {token : "string", regex : ': .*$', next  : "start"},
                    {token : "language.constant", regex: "@startuml|@enduml", next: "start"},
                    {token : keywordMapper, regex : "\\b\\w+\\b"},
                    {token : "keyword", regex : /^\\s*:[^\\/;|}{\\n]+[}{;\\\|\\/]$/mi},
                    {token : "doc.comment", regex : /^'.+/},
                    {token : "keyword.operator", regex: /(:?[-\/o<]{1,2})?-(:?[-\/o>]{1,2})|(?:<\|--?-?(?:\|>)?)|(?:\.\.?\.?\|?>)/},
                    {token : "paren.lparen", regex : "[:\\[({]"},
                    {token : "paren.rparen", regex : "[:\\])}]"},
                    {caseInsensitive: true}
                ],
                "string" : [
                    {token : "constant.language.escape",  regex : "\\\\"},
                    {token : "string", regex : '"',     next  : "start"},
                    {defaultToken : "string"}
                ],
            };
        };

        oop.inherits(plantUMLHighlightRules, TextHighlightRules);
        exports.plantUMLHighlightRules = plantUMLHighlightRules;

});


And two UML codes:

An activity Diagram:
@startuml

title While Loop - Activity Diagram 


start

while (Hungry?)  is (Yes)
  :Eat Hot Wings;
  :Drink Homebrew;
endwhile (No)

:Go To Sleep;

stop

@enduml



And a sequence Diagram:

@startuml

title "Comments - Sequence Diagram"

'This is a single line comment

/'
This is a multi-
line comment
'/

actor User
boundary "Web GUI" as GUI
control "Shopping Cart" as SC
entity Widget
database Widgets

User -> GUI : To boundary
GUI -> SC : To control
SC -> Widget : To entity
Widget -> Widgets : To database

@enduml



Reply all
Reply to author
Forward
0 new messages