Git Product home page Git Product logo

sublime-alan-if's Introduction

Sublime-Alan

Package Status  Alan Version  Sublime Text Version  MIT License  Build Status

Alan IF 3 syntax for Sublime Text 3.

IMPORTANT CHANGES!!! — Both the repository and package were renamed, click here to read about the required actions you should take.

ALPHA STAGE — This project is still a WIP Alpha version! Most features are still experimental and subject to continuos changes. Screenshots and descriptions might not always accurately represent the latest changes.

The following document isn't always updated to cover all the added features, it's mainly intended to illustrate the project goals; for a full list of current features, see the CHANGELOG.


Table of Contents


About

I've created this Alan 3 syntax package just to add some support for Alan source files in Sublime Text, for my own personal use. I haven't really planned to make this a finished product to share on Package Control. Nevertheless, I've decided to share it publicly — just in case it might be useful to others too, or in the remote chance that someone else will join in the project and give me a hand to flesh it out.

I'll be polishing the sytnax and adding features as needs arise, and try to document changes. As a guideline, I'll be pushing to master only tested features, so you should be safe keeping the package synced to master branch.

Features

A brief presentation of the features so far implemented.

Syntax Highlighting

Although the Alan syntax isn't yet fully implemented, it's already mature enough to provide some decent syntax highlighting.

I still need to implement semantic scoping of syntax elements, so that proper indexing can be achieved (Goto functionality, etc.).

For more info on the roadmap and wishlist, see:

The package also ships with additional syntax definitions and color schemes for:

Ligatures Support

Alan syntax has been optimized to enable support of code ligatures. The following Alan operators and keywords are converted to ligatures (if enabled and if font supports them):

token ligature syntax element
>= Greater or equal operator
<= Less or equal operator
== String identity operator
=> Alternative syntax for THEN (in Rules)

Screenshot of ligatures

Not all code fonts implement in the same way ligatures for =>, <=, >= and =<, depending on which of those are treated as comparison operators and which as arrows (some fonts, like Fixedsys Excelsior, are available in dual choice). This is a crucial point for rendering correctly Alan's operators in ligatures.

The following code-ligatures fonts have been tested with Sublime Alan:

font name comments
Fira Code Highly recommended.
Iosevka Works fine.
DejaVu Sans Code Works fine.
Fixedsys Excelsior Must use the "Default" version!
Monoid No. Doesn't support "=="
Hasklig No. Doesn't support "<=" and ">="

To disable ligatures for the Alan syntax, open/create your User settings file for Alan syntax and add "no_calt" to the "font_options" option:

{
    "font_options":
    [
        "no_calt",
    ],
}

Color Schemes

Sublime-Alan ships with the "Alan DarkFluo" color scheme:

Screenshot of Alan DarkFluo color scheme

This color scheme is still pretty much work-in-progress. The goal is to provide a palette which doesn't strain the eyes, and where the prose parts of the Alan source stand out from the rest of the code, allowing to easily switch focus between the adventure text and its code.

Goto Symbols

Amongst the goals of this package is that of providing good indexing functionality of Alan language's symbols in order to maximize Sublime Text's Goto Symbol functionality.

Currently, the following syntax elements are captured and indexed:

  • Class declaration identifiers.
  • Instance declaration identifiers.

Quoted identifiers are transformed before indexing: the delimiting quotes are removed, and any escaped single quotes inside the identifier are replaced with one single quote (eg: 'Tom''s Cat' is indexed as Tom's Cat). This is intended to facilitate looking up identifiers in Goto Symbol functionality, by representing them sa they are seen in the Alan adventure world.

Build Systems

The build system allows compiling alan source files directly from within th editor (CtrlB). Errors reported by Alan compiler will be overimposed in the sourcecode panel, and the user can navigate through the results via F4 and CtrlF4:

Screenshot of Build system errors navigation in the editor

The full error log from the compiler will also be shown in Sublime Text's console. This package syntax highlights the error log to improve visual navigations of the different error types and messages:

Screenshot of Build system errors report in Sublime Text console

Currently there is only one build system, which compiles the current editor's alan source file ("*.alan" files only) without extra options (except -cc, to allow capturing error reports). Additional Build systems will be added soon.

NOTE — Build functionality requires Alan binary compiler to be available on the system PATH.

Autocompletions

I'm working on autocompletions to provide a fast coding experience thanks to contextual suggestions.

NOTE — I haven't yet found the time to list main completions in this document. For a detailed and always up-to-date overview of the available completions, see the contents of completions/ folder.

Snippets

Sublime-Alan ships with some useful snippets to simplify writing your adventures.

trigger description
"h1"+Tab Commented Heading 1 Frame
"h2"+Tab Commented Heading 2 Frame
"h3"+Tab Commented Heading 3 Frame
"h4"+Tab Commented Heading 4 Frame
"h5"+Tab Commented Heading 5 Frame
"h6"+Tab Commented Heading 6 (underlined)

New Adventure Boilerplate

The New Adventure Boilerplate snippet provides a quick template for starting a new adventure using Alan Standard Library v2.1:

By typing "newadv"+Tab inside an Alan source file, you'll get:

Screenshot of "New Adventure Boilerplate" snippet in action

The snippet provides some presets and placeholder values, you can then edit each field and/or skip to the next one via the Tab key.

Custom Variables Support

The newadv snippets also supports custom environment variables as default values for some of its fields:

Screenshot of "New Adventure Boilerplate" snippet using custom variables

The supported variables are:

  • ALAN_AUTHOR

When this environment variable is defined, its value will automatically be used to fill the author field.

To define these environment variables, create a "Alan Env Vars.tmPreferences" file (the actual filename doesn't really matter, only the extension) in "Packages/User/", and define them like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>name</key>
    <string>Custom Alan env vars</string>
    <key>scope</key>
    <string>source.alan</string>
    <key>settings</key>
    <dict>
        <key>shellVariables</key>
        <array>
            <dict>
                <key>name</key>
                <string>ALAN_AUTHOR</string>
                <key>value</key>
                <string>Tristano Ajmone</string>
            </dict>
        </array>
    </dict>
</dict>
</plist>

After creating this file, the newadv snippet will automatically fill-in the author field with your custom variable:


--==============================================================================
-- "Game Title" by Tristano Ajmone, 2018.
--==============================================================================
IMPORT 'library.i'. -- ALAN Standard Library v2.1


THE my_game ISA DEFINITION_BLOCK

  HAS title    "Game Title".
  HAS subtitle "".
  HAS author   "Tristano Ajmone".
  HAS year     2018.
  HAS version  "1".

END THE.


THE start_loc ISA LOCATION

END THE start_loc.


Start at start_loc.
DESCRIBE banner.

Transcipt and Solution Syntaxes

This package also provides additional syntax definitions for Alan game transcripts and solution files:

The alternative .a3sol and .a3log extensions were arbitrarily invented and introduced by this package, long before Alan adopted their new official counterparts .a3s and .a3t, respectively (See alan-if/alan#2). The package currently supports both new (official) and old (arbitrary) extensions because there are various projects still using the older extensions, so we want to provide a grace period to allow them to migrate to the new official extensions, before deprecating them.

The purpose of these syntaxes is to simplify handling of game transcript and solution files by settings Sublime Text to handle these files with ISO-8859-1 encoding, as well as providing some minimal syntax highlighting and allowing the user to associate custom color schemes to them. Without a basic syntax definition, and its encoding settings, Sublime Text would default to UTF-8 encoding, which would cause lots of problems and errors if the solution file contains special characters (like accented letters), and would not display correctly transcripts containing special chars.

Hopefully, these two extra syntaxes will simplify creating and using command scripts to test adventures during the authoring stage, and to correctly visualize game transcripts (i.e. provided the "*.a3s" and "*.a3t" file extensions are used).

Alan Solution Files Syntax

This package also defines an Alan IF Solution syntax associated to the *.a3s/*.a3sol file extensions.

Solution files (aka "commands scripts") are text files containing player commands used to run an adventure in automated mode, by passing the script to the interpreter. The *.a3s/*.a3sol file extensions are intuitively similar to the "*.sol" extension often used for solution files, but at the same time can be uniquely uniquely associated to Alan (Alan adventures having the *.a3c extension), allowing to enforce custom setting without the risk that they might affect other commonly used extensions.

In Alan IF Solution files, single-line comments are enabled via the usual comment keyboard shortcuts, producing the "; " comment delimiter.

Alan Solution Color Scheme

This package also sets a predefined hidden color scheme to preview Alan Solution files:

Screenshot of Alan IF Solution file color scheme

... which is intended to make editing command script file more pleasant to the eye.

The color scheme is created by converting the YAML source file "Alan IF Solution.YAML-propertyList-tmTheme" via PackageDev's build system "Convert to ... - Property List"; since the YAML format is easier to maintain.

Alan Solution Snippets

A few snippets are also available to allow commenting solution files:

trigger description
"h1"+Tab Commented Heading 1 Frame
"h2"+Tab Commented Heading 2 Frame
"h3"+Tab Commented Heading 3 Frame
"h4"+Tab Commented Heading 4 Frame

; ==============================================================================
; Heading 1 Frame
; ==============================================================================

; ------------------------------------------------------------------------------
; Heading 2 Frame
; ------------------------------------------------------------------------------

; ===============
; Heading 3 Frame
; ===============

; ---------------
; Heading 4 Frame
; ---------------

Alan Transcript Files Syntax

This package also defines an Alan IF Transcript syntax associated to the *.a3t/*.a3log file extensions. While transcripts generated with the Alan interpreters used to have the .log file extension, now Alan as officially adopted the .a3t extension because .log is already being used in so many different contexts that it doesn't allow to enforce special editor settings on it.

The syntax also syntax highlights the player input lines, capturing the prompt (assuming it's always ">"), strings and comments. The output text from the adventure is not highlighted, as the scope of this syntax is to provide easy color separation between player commands and game output text.

In trasncripts of adventures which change the prompt (from the default ">" symbol) the player input line won't be captured and syntax highlighted.

In Alan IF Transcript files, single-line comments are enabled via the usual comment keyboard shortcuts, producing a "> ; " comment delimiter. The reason why commented lines are preceded by a prompt (unlike Solution files, which use just a semicolon) is that this is the expected behavior in this context. Transcipts are automatically produced by the interpreter, and the purpose of the Alan IF Transcript syntax is to allow a nicer preview of these files; but in some cases the user might wish to add some comments to the transcipts before sharing them with other (eg, to pinpoint a typo or a bug), and these added comments should be represented as a comment line added by the player during the game session (hence the addition of the prompt before the comment delimiter).

Alan Transcript Color Scheme

This package also sets a predefined hidden color scheme to preview Alan Transcript files:

Screenshot of Alan Transcript file color scheme

... which is intended to make previewing of game transcript files more pleasant to the eye.

The color scheme is created by converting the YAML source file "Alan IF Transcript.YAML-propertyList-tmTheme" via PackageDev's build system "Convert to ... - Property List"; since the YAML format is easier to maintain.

Requirements

  • Minum requirement: Sublime Text 3 BUILD >=3170 (uses new .sublime-color-scheme format).
  • Recomended: bleeding-edge Sublime Text 3 Dev BUILD.

This package is being developed using the latests ST3 Dev Builds, and it might use features not included in the latest stable build; I can't grant that it will work with ST3 Stable Builds.

This package is being developed using the latests ST3 Dev Builds, but now that Sublime Text 3 has reached its end of life, and its next major incarnation is about to be released at any moment, there shouldn't be any longer any differences between ST3 Dev Builds and ST3 Stable Builds, since no further updates are expected, except for bug fixes.

Installation

Create an "Alan_IF" folder inside "<data_path>/Packages/", open a shell inside "<data_path>/Packages/Alan_IF/" and type:

git clone https://github.com/tajmone/sublime-alan-if .

Don't forget the "." after the repository URL! it's needed in order to clone the repository contents directly into the current folder, without creating a "sublime-alan-if" container folder.

License

MIT License

Copyright (c) 2018 Tristano Ajmone
https://github.com/tajmone/sublime-alan-if

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Acknowledgements

I would like to thank the following people who have helped me out with the difficulties of creating this syntax:

Without their precious help I wouldn't have overcome many of the problems related to implementing the syntax and choosing the right scopes.

I'd also like to express my gratitude to the authors of invaluable guidelines and tutorials which fill the huge gaps of undocumented Sublime Text 3 features and guidelines:


IMPORTANT CHANGES!!!

Package and Repository Renamed

June 7, 2021 — The repository was renamed from sublime-alan to sublime-alan-if to prevent clashes with the Alan Programming Language by Alan Technologies, Inc (see alantech/alan/#548).

Furthermore, the package was renamed from "Alan" to "Alan IF" to prevent conflicts in case a user would install both Alan IF and the Alan language by Alan Technologies, since they are planning to create a Sublime Text package in the future (see alantech/alan/#257).

Due to these changes, you should take the following action:

  1. Update the Git remote of your local repository to point to the new repository URL:

    https://github.com/tajmone/sublime-alan-if

  2. Rename the <data_path>/Packages/Alan/ folder to <data_path>/Packages/Alan_IF/.


Links

Alan IF links:

sublime-alan-if's People

Contributors

tajmone avatar

Stargazers

 avatar

Watchers

 avatar  avatar

sublime-alan-if's Issues

Fix Name Clashes with Alan Language by Alan Tech. Inc.

Tweak the Alan syntax definition to avoid any potential conflicts with the Alan programming language by Alan Technologies, Inc (alantech/alan#548).

File Names

In the event of an upcoming package for Alan Tech's Alan lang we should rename all the syntaxes files and their internal names to avoid conflicts in case a user installs both this package and theirs.

  • ALANAlan.sublime-syntax
    • Rename Syntax to Alan IF.sublime-syntax
      • name: ALan IF
    • Rename all associated ST files and themes accordingly.
  • ALAN SolutionAlan Solution.sublime-syntax
    • Rename Syntax to Alan IF Solution.sublime-syntax
      • name: ALan IF Solution
    • Rename all associated ST files and themes accordingly.
  • ALAN TranscriptAlan Transcript.sublime-syntax
    • Rename Syntax to Alan IF Transcript.sublime-syntax
      • name: ALan IF Transcript
    • Rename all associated ST files and themes accordingly.

Scopes

Likewise, we should change the base scope name used by this package.

  • ALANsource.alanif
    • Fix all other package files that rely on scope for their functionality:
      • Build files.
      • Color schemes.
      • Comments Preferences.
      • Completions.
      • Indentation rules.
      • Snippets.
      • Symbols.
      • Syntax tests.

The scopes of the other syntaxes are fine, and not at risk of clashing:

  • ALAN Solutionsource.a3s
  • ALAN Transcriptsource.a3t

Add EditorConfig Settings

Enforce code styles consistency to the repository:

  • Add and enforce EditorConfig rules.
  • Add code styles validation script (via EClint).
  • Enable Travis CI code styles validation (via EClint).
    • Add Travis badge (and others) to README.
  • Git hooks for local commit validation (via EClint).

Adopt New Official Extensions for ALAN3 Solution and Transcript Files

Switch to the upcoming official extensions .a3s and .a3t for ALAN3 solution files and transcripts, respectively (see alan-if/alan#2):

  • Update syntaxes:
    • Alan Transcript.sublime-syntax:
      • Add .a3t as main extension (but keep .a3log).
      • Change scope from .a3log to .a3t.
      • Update scopes and references in all package files.
    • Alan Solution.sublime-syntax:
      • Add .a3s as main extension (but keep .a3sol).
      • Change scope from .a3sol to .a3s.
      • Update scopes and references in all package files.
  • Rename snippets-a3sol/ folder.
  • Update documentation accordingly.

NOTE — Initially I'll add the new extensions along with the old ones (.a3sol and .a3log) for a grace period, so that old projects would still be usable in Sublime ALAN.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.