Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.pyc
*.cache
*.sublime-project
*.sublime-workspace
9 changes: 4 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ Syntax Definition Development

In AAAPackageDev, syntax definitions are written in JSON. Because Sublime Text
uses ``.tmLanguage`` files, though, they need to be converted before use. The
conversion is done through the included build system ``Json to tmLanguage``.
conversion is done through the included build system ``JSON to Property List``.

Creating a New Syntax Definition
********************************

#. Create new template (through **Tools | Packages | Package Development**) or the *Command Palette*
#. Select ``Json to tmLanguage`` build system from **Tools | Build System**
#. Select ``JSON to Property List`` build system from **Tools | Build System** or leave as ``Automatic``
#. Press ``F7``

To reload changes to a syntax definition, you must restart Sublime Text.

Other included resources for syntax definition development:

Expand All @@ -68,7 +67,7 @@ Commands

.. Completions
.. -----------
..
..
.. * sublime text plugin dev (off by default)
.. Will clutter your completions list in any kind of python dev.
.. To turn on, change scope selector so ``source.python``.
Expand Down Expand Up @@ -133,7 +132,7 @@ About Snippets in AAAPackageDev

The ``AAAPackageDev/Snippets`` folder contains many snippets for all kinds of
development mentioned above. These snippets follow memorable rules to make their
use easy.
use easy.

The snippets used more often have short tab triggers like ``f`` (*field*),
``c`` (*completion*), ``k`` (*key binding*), etc. In cases where increasingly
Expand Down
2 changes: 1 addition & 1 deletion Support/AAAPackageDev.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{ "caption": "z:AAAPackageDev: New Syntax Definition", "command": "new_syntax_def" },
{ "caption": "z:AAAPackageDev: New Syntax Definition from Buffer", "command": "new_syntax_def_from_buffer" },
{ "caption": "z:AAAPackageDev: Generate .tmLanguage from Buffer", "command": "make_tmlanguage" },
{ "caption": "z:AAAPackageDev: JSON to Property List", "command": "json_to_plist" },

{ "caption": "z:AAAPackageDev: New Settings File", "command": "new_settings" },

Expand Down
4 changes: 4 additions & 0 deletions Support/JSON to Property List.sublime-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"target": "json_to_plist",
"selector": "source.json, source.json-tmlanguage"
}
3 changes: 0 additions & 3 deletions Support/Json to tmLanguage.sublime-build

This file was deleted.

14 changes: 0 additions & 14 deletions json2plist.py

This file was deleted.

52 changes: 33 additions & 19 deletions syntax_def_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
import os
import plistlib
import uuid
import re

import sublime_plugin

from sublime_lib.path import root_at_packages
from sublime_lib.view import has_file_ext, in_one_edit
from sublime_lib.view import in_one_edit


JSON_TMLANGUAGE_SYNTAX = 'Packages/AAAPackageDev/Support/Sublime JSON Syntax Definition.tmLanguage'
Expand Down Expand Up @@ -57,28 +58,41 @@ def run(self, edit):


# XXX: Why is this a WindowCommand? Wouldn't it work otherwise in build-systems?
class MakeTmlanguageCommand(sublime_plugin.WindowCommand):
"""Generates a ``.tmLanguage`` file from a ``.JSON-tmLanguage`` syntax def.
Should be used from a ``.build-system only``.
class JsonToPlistCommand(sublime_plugin.WindowCommand):
"""
# XXX: We whould prevent this from working except if called in a build system.
Parses ``.json`` files and writes them into corresponding ``.plist``.
Source file ``.JSON-XXX`` will generate a plist file named ``.XXX``.
Pretty useful with ``.JSON-tmLanguage`` but works with almost any other name.
"""
ext_regexp = re.compile(r'\.json(?:-([^\.]+))?$', flags=re.I)

def is_enabled(self):
return has_file_ext(self.window.active_view(), '.JSON-tmLanguage')
return self.get_file_ext(self.window.active_view().file_name()) is not None

def get_file_ext(self, file_name):
ret = self.ext_regexp.search(file_name)
if ret is None:
return None
return '.' + (ret.group(1) or 'plist')

def run(self, **kwargs):
v = self.window.active_view()
path = v.file_name()
if not (os.path.exists(path) and has_file_ext(v, 'JSON-tmLanguage')):
print "[AAAPackageDev] Not a valid JSON-tmLanguage file. (%s)" % path
ext = self.get_file_ext(path)
if not os.path.exists(path):
print "[AAAPackageDev] File does not exists. (%s)" % path
return
if ext is None:
print "[AAAPackageDev] Not a valid JSON file, please check extension. (%s)" % path
return

assert os.path.exists(path), "Need a path to a .JSON-tmLanguage file."
self.make_tmlanguage_grammar(path)
self.json_to_plist(path, ext)

def make_tmlanguage_grammar(self, json_grammar):
path, fname = os.path.split(json_grammar)
grammar_name, ext = os.path.splitext(fname)
file_regex = r"Error:\s+'(.*?)'\s+.*?\s+line\s+(\d+)\s+column\s+(\d+)"
def json_to_plist(self, json_file, new_ext):
print os.path.split(json_file)
path, fname = os.path.split(json_file)
fbase, old_ext = os.path.splitext(fname)
file_regex = r"Error parsing JSON:\s+'(.*?)'\s+.*?\s+line\s+(\d+)\s+column\s+(\d+)"

if not hasattr(self, 'output_view'):
# Try not to call get_output_panel until the regexes are assigned
Expand All @@ -94,13 +108,13 @@ def make_tmlanguage_grammar(self, json_grammar):

with in_one_edit(self.output_view) as edit:
try:
with open(json_grammar) as grammar_in_json:
tmlanguage = json.load(grammar_in_json)
with open(json_file) as json_content:
tmlanguage = json.load(json_content)
except ValueError, e:
self.output_view.insert(edit, 0, "Error: '%s' %s" % (json_grammar, str(e)))
self.output_view.insert(edit, 0, "Error parsing JSON: '%s' %s" % (json_file, str(e)))
else:
target = os.path.join(path, grammar_name + '.tmLanguage')
self.output_view.insert(edit, 0, "Writing tmLanguage... (%s)" % target)
target = os.path.join(path, fbase + new_ext)
self.output_view.insert(edit, 0, "Writing plist... (%s)" % target)
plistlib.writePlist(tmlanguage, target)

self.window.run_command("show_panel", {"panel": "output.aaa_package_dev"})