apushkarev / Krpano-Markup-Language

Syntax definition for SublimeText 3
33 stars 11 forks source link

Krpano Markup Language (KML)

Latest update: krpano 1.19-pr16

Sample Screenshot

Package inclides

Contents

Installation

  1. Clone or download this repo to some location;
  2. Find dist folder in package and open it's contents;
  3. Open Sublime Text, run Preferences –> Browse Packages... on Windows or Sublime Text -> Preferences -> Browse Packages on Mac;
  4. Navigate to User folder;
  5. Copy contents of dist folder into opened User folder;
  6. Select Preferences - Color Scheme - User and then one of two themes: Monokai Extended or May Thunderstorm.

Features

I. Syntax definition is based on official krpano documentation, plugin docs and is intended to recognize all structural entities(e.g. elements, properties or keywords) of KML.

Current list of recognized entities includes:

1. Single line C-styled comments are not supported niether in actions nor in event handlers. They should be removed from source code before execution. You can put XML-styled comments where it's possible by XML rules.

II. KML has a wide amount of entities so it needs custom color theme to display them all. This package includes two themes:

Both tmemes support all other languages and are optimized to display Krpano syntax nicely.

Code formatting recomendations

String recognition.

It happened that strings in double quotation marks ("") in KML are used for two purposes:

This syntax highlighting recognizes difference between the two by code formatting. String value should not have next line symbol (\n) right after opening quotation mark:

attribute="value" would be recognized as string and highlighted as a string entirely;

attribute="
    some_code();
"

would be recognized as a piece of script.

Strings inside single quotation marks are always recognized as string values.

Code blocks separation.

KML does not have any specific separation symbols which would clearly show nesting of code blocks like curly brackets {} in C or JavaScript.

Such complicated cunstructions as if condition or loops, or delayedcalls or tweens are just functions that take values and blocks of code as arguments.

So the only way to divide blocks of code are demonstrative indentations which coder put into code.

For example,

if (condition,
    actions;
,
    else actions;
);

would be a nice and correct way to format condition statement. For loops it might look like

for (set(i, 0), i LT some_array.count, inc(i),
    actions;
);

As one can see comma is playing role of opening curly bracket and closing bracket with semicolon plays role of closing curly bracket.

This is the basic principle of KML code intendation: if you want to put some code into function arguments you write comma and then go to next line with one more tab. If you have finished with block of code, you go to next line. Then you go one tab back to the left and then put ); closing the function call.

This simple rule would make your code much easier to read and review. It also is used on screenshot above.

Modifying

See Syntax Definitions chapter of ST unofficial manual, use the same process to modify color scheme.

Comments

Krpano uses two different comment styles taken from JS and XML. Only one JS comment style is fully supported inside krpano actions: / \/ For XML part of code one can use ordinary XML comments.

Default comment style that user can set with Cmd/Ctrl + / shortcut is JS one. To create XML comment use xmlc snippe OR make a keyboar shortvut for xml comment style snippet:

    {
        "keys": ["shift+super+forward_slash"],
        "command": "insert_snippet", 
        "args": { "name": "Packages/User/KrpanoMarkup/snippets/xml-comment.sublime-snippet" }
    }

Krpano snippets and completions

There is a set of shortcuts to cover majority of writing code cases. Please feel free to troubleshoot;

Snippets and autocompletions

Majority of other krpano words is also here.