4Devs: ‘Mozaic Language Support’ for Code Text Editors v1.6

This package enhances external code text editors with syntax highlighting, full Mozaic language validation, jump markers, code completion and templates.

This syntax parser is supported by the commercial Textastic IOS/Mac and the Sublime 3 code text editor on Windows, OS X and Linux.

https://youtube.com/watch?v=vmcCutt8DHA

If scripts get longer and more complicated, the process of refactoring the script is much simpler in an external code text editor as these offer more editing and comfort features

Syntax Highlighting
======================
– Consistent colors and styles for all language elements
– Variables styling for constants, locals, parameters and globals

Code Completion (Textastic)
======================
The package offers code completion for Mozaic commands, functions and control statements. There is support for parameter snippets, which can be stepped through using the tab key

Templates (Textastic)
======================
There are 4 Mozaic templates for new files
– The first only contains a @Description and @OnLoad block
– The three others contain skeletons for pads, knobs and xy layout including optional debugging output

All four templates support parameter snippets stepped through using the tab and shift-tab key

Mozaic Language Validator
======================
– Knows all mozaic events, commands, functions and constants
– Checks number and type of parameter for all commands and functions
– Checks all expressions including parenthesis nesting
– Checks control flow
– Checks variable names including indexing

Content
======================
The zip package consists of the following files inside a Mozaic_Language_Support folder.

Readme.txt …………………………………………. This installation guide
Intro.moz ……………………………………………. Introduction to the
UnitTests.moz …………………………………….. All unit tests done
#Textastic …………………………………………… Folder needed by Textastic
. . . – Monokai-Mozaic.tmTheme …………. Theme file
. . . – CodeCompletion ………………………… Folder for code completion
. . . . . . – mozaic.json …………………………… Mozaic code completion definition
. . . – Mozaic ………………………………………… Folder for language definition
. . . . . . – Mozaic.sublime-syntax ………….. Syntax definition
. . . . . . – SymClasses.tmPreferences ……. Symbol List: add mozaic events
. . . . . . – SymFunctions.tmPreferences … Symbol List: add user events
. . . . . . – SymHide.tmPreferences ………… Symbol List: hide @End keyword
. . . – Templates …………………………………… Folder for templates
. . . . . . – mozaic.json ……………………………. Mozaic template

All these files are ascii textfiles and can be opened and edited in any text editor.

The Monokai-Mozaic Theme file is a slight modification of the Monkai theme by Monokai, adds orange color for Mozaic keywords and dims down the error-highlights.

Textastic IOS Installation
======================
Download the zip either with Documents app or into AudioShare. Unzip and you get the MozaicLanguageSupport folder containing the above files, which all need to be copied into the On My Ipad / Textastic folder.

– If you used the Documents app to unzip, the easiest way to do this is to use the Documents app and navigate into the unzipped folder, select all
3 files plus the #Textastic folder and then ‘share’ and ‘save into files’ selecting the On my iPad / Textastic folder as destination.

– If you used AudioShare to unzip, use the Files app and navigate into the unzipped folder, select all 3 files plus the folder and then ‘move’. In the destination dialog, select the On my iPad / Textastic folder and then ‘copy’

Textastic MAC Installation
======================
Download the zip and unpack.

Please refer to the manual on how to open the textastic library folder and then copy the content of the #Textastic folder into that folder.

Installation for Sublime3
======================
Download the zip and unpack.

Open Sublime 3 and choose ‘Preferences / Browse Packages…’ to show the the package folder on your operating system. (on Windows this opens “users” / “userid” / AppData / Roaming / Sublime Text 3 / Packages )

Create a ‘User’ folder (if not already present) and copy the content of the #Textastic folder (except for the CodeCompletion and Templates folders) into this ‘User’ folder.

After restarting Sublime 3, the new Mozaic syntax definition and Monokai-Mozaic theme should be available.

Testing the Installation
======================
Opening the Intro.moz should automatically use the syntax definition, since the moz extension is registered in the synatax definition

The Monokai-Mozaic theme needs to be manually enabled:
– In Textastic styles are found under settings/code-editor/theme.
– In Sublime 3 find it at preferences/color scheme

Disclaimer
======================
Textastic IOS ($10) and Sublime3 ($80) are both commercial code text editors. I am in no way associated with either of them. Textastic was just the only IOS editor i found that allowed for user defined syntax definitions – and these have to be done in sublime3 syntax.

Author
645 PM
  • Platform:
  • Category: Utility
  • Revision: 1.6
  • Views: 629
  • Modified: 1 month ago
Chat about this patch on Discord! Download (44)
Appreciate 6
17 comments on “4Devs: ‘Mozaic Language Support’ for Code Text Editors v1.6
  • Kitusai on said:

    ok! It was not clear for me that you have first to buy Textastic in order for this package to work.

  • -ki on said:

    Sorry, i’ll add some clarification – this work should not be seen as advert for Textastic. I have spend about 170 hours of my spare time and weekends to get the syntax validator running and i am in no way associated with Textastic or Sublime3.

    Textastic was just the only code text editor on IOS that allowed for user defined syntax definitions and these have to be in the sublime3 format.

    You can use the package on desktop maschines with the Sublime3 editor, which may be downloaded and evaluated for free, however a license must be purchased for continued use. There is currently no enforced time limit for the evaluation.

  • peblin on said:

    Wow -ki, this is super! What an effort!

    Now I need to either start using Sublime 3 or convert this to Visual Studio Code :D

  • Acoustiman on said:

    Thx for this labor of love!

  • mcdtracy on said:

    I am familiar with your programming skills from our collaborations with StreamByter code.
    It doesn’t surprise me that you would do this work for your own benefit just to make
    Mosaic coding more efficient. But going the extra “miles” for someone to follow is a great
    contribution.

    I’ll use this on Sublime which I just installed to start digging into Mosaic as a programming
    exercise.

    Thanks!!!

  • mcdtracy on said:

    The only thing more exciting for me would be a Mac OS X version of Mosaic or any application
    that can accept Mosaic code to generate MIDI streams.

    Given Bram’s history as a programmer it’s possible he could create versions for multiple platforms
    like OS X, Windows and Android. In that order of course!

  • MrBlaschke on said:

    Hi all :)
    @-ki – is .moz an official Mozaic extension?
    My files keep adding the .mozaic extension thus making the file not compatible within Textastic. Only .moz files are correctly recognized. Any way to extend to .mozaic? Could only find the EXT parameter for sublime.

  • -ki on said:

    @MrBlaschke
    Using .mozaic as extension for ascii script files is prone to problems – that extension is used by the binary mozaic files (also containing the saved state etc). Double tap such a ‘script only’ .mozaic in the files app would therefor start Mozaic and the app would choke on the wrong file content.

    That’s why i made up the .moz extension. Bram wrote in the Audiobus forum that he will additionally register .moz to mozaic and add loading of ascii script files in a future version ;-)

    .

    You can change the used syntax file for each loaded file manually under file settings/syntax definition – simply select Mozaic

    .

    And if you really insist on keeping the .mozaic extension, open up #Textastic/Mozaic/Mozaic.sublime-syntax in Textastic and change line 6 from ‘ – moz’ to ‘ – moz mozaic’
    Restart Textastic and after that change Textastic will auto-enable the mozaic style for both .moz and your .mozaic extension

  • MrBlaschke on said:

    Hi -ki

    Thanks for the reply – found that content on the forum yesterday after writing here.
    Also thanks for the description you gave…and of course for your efforts :)

    Kind regards.

  • Paulinko on said:

    Thank you very much for creating these Mozaic language support files. They work great in Textastic which is my code editor app of choice.

  • Mike Lee on said:

    Hi,
    Love your work here and I tried your Sublime Extension (Windows), but can‘t get the script to work.
    When opening the file in mozaic, it shows up in the preset folder and I can open it, but the code does not load. When I copy and paste the code into mozaic it does not compile, it doesn‘t even show the „ [MOZAIC] Script loaded.“ when uploading. Any Idea? An encoding issue maybe?

    Attachment  RandomRuis.zip

  • -ki on said:

    When editing mozaic scripts, you should use the .moz extension, because .mozaic is used for binary patch files. Your zip contained an ascii script but used .mozaic extension. I used AudioShare to change your files extension to .moz .

    The Mozaic app can’t yet load ascii .moz files (Bram wrote he will add that feature sometimes in an update) . This will allow to double-tap on such a .moz file and Mozaic will load that ascii file.

    So to currently get a script into Mozaic, you need to open the file with an editor on the ipad (for instance with the documents app), select all text and copy (to the clipboard) . The open mozaic, open the code editor, select all (to select the old script) and paste to overwrite with the script from the clipboard.

    When using the Textastic editor, its the same procedure: Select all, copy, change to Mozaic, select all, paste.

    Don’t forget to save the changed script as mozaic preset.

  • Mike Lee on said:

    Thank you for your fast reply.
    I tried copy and paste, but the script does not start. Even when I put a log at the beginning of @OnLoad, it does not show up in the log when uploading the script.

  • -ki on said:

    You are right – the copy/paste of your script does not work at all, adding a Log { } message as first line in OnLoad does not output. But if i added a new @OnLoad above the original one, i got output.

    Looking at your source, i could only see that you used tabs instead of spaces for indentation – but that shouldn’t matter.

    The copy/paste action worked after changing the line-ends in Textastic from Windows (CR LF) to Unix (LF) style – so you need to set Sublime to use LF only on your pc.

    I probably didn’t run into that problems, because i started all my test scripts in Mozaic and moved these over to the PC – perhaps Sublime then recognized the unix line end style.

    I will inform Brambos of that problem, so when he develops the ascii i port, he could also recognize cr-lf line endings.

  • Mike Lee on said:

    Thank you so much!!!
    I have tons of ideas that I just want to type down first in Sublime and then finetune and debug in mozaic.
    Maybe I’ll give Textastic a try, now that the iPad works with mouse and keyboard!

  • -ki on said:

    Update v1.6
    ============
    – Added: Support for the new ColorPad and SystemTime Moazic language features
    – Added: Context dependend code completion for Textastic
    – Added: Mozaic templates for Textastic
    – Bugfix: FOR lvalue allowed controlflow keywords and verbal operators
    – Bugfix: expressions allowed ‘and’ or ‘or’ as variable names
    – Added; Start typing ‘and’ or ‘or’ in expression uses ‘depricated’ highlight
    – Bugfix: Comments with boxdrawing chars were shown italic under Linux

    Code Completion for Textastic
    =============================
    Start typing and Textastic will show a popup of completions depending on the current context. There are different completions outside or inside events, inside IF statements or in expressions etc.

    The completion list updates according to the typed characters, one can navigate in longer completion lists using the the up and down arrow keys or scroll using touch. Using the arrow key will show a highlight on the current selected completion, the tab key or finger press adds the completion. If no highlight is shown, the tab key will add the topmost completion.

    Parameters snippets are marked with triangle carets. Entering a snippet by pressing the tab key selects the snippet and typing something new replaces the whole snippet. Navigate between snippets using tab and shift tab key. A final press of the tab key jumps to the end position of that code completion.

    Example:

    – Inside an event block (like @OnLoad) typing ‘f’ will show the completion popup containing a list with ‘FillArray, FlashPad, FlashUserLed and for’. Typing ‘o’ will redurce that list to ‘for’. Typing ‘tab’ adds this completion.

    – The ‘for’ completion contains snippets for the variable name, start and end value and adds the ‘endfor’ – all of them marked by triangle carets.

    – The first snippet for the variable name is automatically selected, typing something will replace the name. Upon finishing the name, press ‘tab’ to step to the start value snippet.

    – Either change the value or press ‘tab’ to step the the end value to edit its snippet. (BTW ‘shift tab’ steps back to the previous snippet)

    – Using ‘tab’ at the end value will position the cursor inside the for statement with correct indentation.

    Templates for Textastic
    =============================
    There are 4 Mozaic templates for new files
    – The first only contains a @Description and @OnLoad block
    – The three others contain skeletons for pads, knobs and xy layout
    including optional debugging output

    All four templates support parameter snippets stepped through using the tab and shift-tab key

  • Espiegel123 on said:

    Thank you so much!

  • Leave a Reply