diff --git a/.no-sublime-package b/.no-sublime-package deleted file mode 100644 index e69de29..0000000 diff --git a/JSX (Outer).YAML-tmPreferences b/JSX (Outer).YAML-tmPreferences index d1e3052..7cd9a17 100644 --- a/JSX (Outer).YAML-tmPreferences +++ b/JSX (Outer).YAML-tmPreferences @@ -1,11 +1,9 @@ # [PackageDev] target_format: plist, ext: tmPreferences name: JSX 2 -scope: source.js +scope: source.js - string - comment settings: # The indent patterns can't be limited to meta.jsx.js. Otherwise they wouldn't # work for the outer most tag since it would fall outside of that scope. - # They're also not limited with '- string - comment' since you may be writing - # JSX in your documentation or template strings. decreaseIndentPattern: >- (?x) ^\s*]+>$ diff --git a/JSX (Outer).tmPreferences b/JSX (Outer).tmPreferences index 788984b..ac822e3 100644 --- a/JSX (Outer).tmPreferences +++ b/JSX (Outer).tmPreferences @@ -5,7 +5,7 @@ name JSX 2 scope - source.js + source.js - string - comment settings decreaseIndentPattern diff --git a/JavaScript (Babel).YAML-tmLanguage b/LightScript.YAML-tmLanguage similarity index 89% rename from JavaScript (Babel).YAML-tmLanguage rename to LightScript.YAML-tmLanguage index 9e9772d..74240e3 100644 --- a/JavaScript (Babel).YAML-tmLanguage +++ b/LightScript.YAML-tmLanguage @@ -1,8 +1,8 @@ # [PackageDev] target_format: plist, ext: tmLanguage -name: JavaScript (Babel) +name: LightScript scopeName: source.js -fileTypes: [js, jsx, babel, es6] -firstLineMatch: ^#!\s*/.*\b(node|js)$\n? +fileTypes: [lsc,lsx,lsc.js,lsc.jsx] +firstLineMatch: ^#!\s*/.*\b(lsc-node|js)$\n? patterns: - include: '#core' @@ -12,6 +12,7 @@ repository: patterns: - include: '#literal-function-labels' - include: '#literal-arrow-function-labels' + - include: '#literal-lightscript-blocks' - include: '#literal-labels' - include: '#literal-for' @@ -163,6 +164,39 @@ repository: literal-class: patterns: + # a halfhearted attempt at lightscript classes, that just ignores the body + # the other approach I came up with detected top-level dedent with `^(?- + (?x) + (? + # LIGHTSCRIPT + - name: meta.function.arrow.js + begin: >- + (?x) + ([_$a-zA-Z][$\w]*) + (?= + (?:\<[^\n]+\>)? + (\((?>(?>[^()]+)|\g<-1>)*\)) + (?::[^\n]+)? + \s* + [=-](?:get|set|\*|\/)?> + ) + beginCaptures: + '1': {name: entity.name.function.js} + end: \s*([=-](?:get|set|\*|\/)?>) + endCaptures: + '1': {name: storage.type.function.arrow.js} + patterns: + - begin: (?<=[$\w])(?=\<) + end: (?<=\>)(?=\() + patterns: + - include: '#flowtype-polymorph' + - begin: (?=\() + end: (?<=\)) + patterns: + - include: '#function-declaration-parameters' + - begin: (?<=\))(?=:) + end: (?=\s*[=-](?:get|set|\*|\/)?>) + patterns: + - include: '#flowtype-annotation' + + literal-arrow-function: patterns: + - include: '#named-arrow-function' + # e.g. (args) -> { } + # LIGHTSCRIPT + - name: meta.function.arrow.js + begin: >- + (?x) + (?=(\((?>(?>[^()]+)|\g<-1>)*\))\s*([=-](?:\*|\/)?>)) + end: (?<=\))\s*([=-](?:\*|\/)?>) + endCaptures: + '1': {name: storage.type.function.arrow.js} + patterns: + - include: '#function-declaration-parameters' + + # e.g. foo.bar.play(args) => { } + # LIGHTSCRIPT + - name: meta.function.static.arrow.js + begin: >- + (?x) + (?<=[$\w]\.) + ([_$a-zA-Z][$\w]*) + \s*(?=(\((?>(?>[^()]+)|\g<-1>)*\))\s*([=-](?:\*|\/)?>)) + beginCaptures: + '1': {name: entity.name.function.js} + end: (?<=\))\s*([=-](?:\*|\/)?>) + endCaptures: + '1': {name: storage.type.function.arrow.js} + patterns: + - include: '#flowtype-polymorph' + - include: '#function-declaration-parameters' + + # e.g. (args) => { } # e.g. play = (args) => { } - name: meta.function.arrow.js @@ -821,7 +922,7 @@ repository: literal-keyword-storage: patterns: - name: storage.type.js - match: (?const|let|var)\b + match: (?const|let|var|now)\b literal-keywords: patterns: @@ -836,7 +937,7 @@ repository: match: (?if|else)\b + match: (?if|else|elif)\b - name: keyword.control.trycatch.js match: (?catch|finally|throw|try)\b @@ -850,21 +951,51 @@ repository: - name: keyword.other.js match: (?delete|instanceof|in|new|of|typeof|void|with)\b + match: (?delete|instanceof|in|new|of|typeof|void|with|from|idx|elem|key|val)\b - name: keyword.operator.logical.js match: >- (?x) - !(?!=)| # logical-not right-to-left right - && | # logical-and left-to-right both - \|\| | # logical-or left-to-right both + !(?!=) | # logical-not right-to-left right + && | # logical-and left-to-right both + \|\| | # logical-or left-to-right both + or(?=\s) | # logical-or left-to-right both + and(?=\s)| # logical-and left-to-right both + not(?=\s) # logical-not left-to-right both - name: keyword.operator.assignment.js match: >- (?x) - =(?!=)| # assignment right-to-left both + =(?!=) # assignment right-to-left both - name: keyword.operator.assignment.augmented.js match: >- @@ -925,7 +1059,7 @@ repository: \|= | # assignment right-to-left both <<= | # assignment right-to-left both >>= | # assignment right-to-left both - >>>= | # assignment right-to-left both + >>>= # assignment right-to-left both - name: keyword.operator.bitwise.js match: >- @@ -1031,6 +1165,7 @@ repository: patterns: # ignore ++, -- since they're uncommon, distinguishing them is not possible in sublime text, see: # http://stackoverflow.com/questions/5519596/when-parsing-javascript-what-determines-the-meaning-of-a-slash + # TODO LIGHTSCRIPT: ensure there is not an opening space - name: string.regexp.js begin: >- (?x) @@ -1215,11 +1350,13 @@ repository: '3': {name: support.type.object.process.js} '4': {name: support.function.process.js} - - match: (?- + (?x) + (if|elif|else|try|catch|for)[^\n]*:$ + | [\w_$]*\([^\n]*\)(?:\:\s+[^\n]+)?\s+[-=](?:get|set|\/|\*)?>$ + | {[^}\"']*$ + | \[[^\]\"']*$ + | \([^)\"']*$ + | <[a-zA-Z][^/]*$ + | ^\s*>$ + decreaseIndentPattern: >- + (?x) + ^\s*(\s*/[*].*[*]/\s*)*[}\])] + | ^\s*() diff --git a/JavaScript (Babel).tmLanguage b/LightScript.tmLanguage similarity index 91% rename from JavaScript (Babel).tmLanguage rename to LightScript.tmLanguage index 2ba5be6..98c8f4f 100644 --- a/JavaScript (Babel).tmLanguage +++ b/LightScript.tmLanguage @@ -4,15 +4,15 @@ fileTypes - js - jsx - babel - es6 + lsc + lsx + lsc.js + lsc.jsx firstLineMatch - ^#!\s*/.*\b(node|js)$\n? + ^#!\s*/.*\b(lsc-node|js)$\n? name - JavaScript (Babel) + LightScript patterns @@ -463,6 +463,10 @@ include #literal-arrow-function-labels + + include + #literal-lightscript-blocks + include #literal-labels @@ -1335,6 +1339,72 @@ patterns + + include + #named-arrow-function + + + begin + (?x) + (?=(\((?>(?>[^()]+)|\g<-1>)*\))\s*([=-](?:\*|\/)?>)) + end + (?<=\))\s*([=-](?:\*|\/)?>) + endCaptures + + 1 + + name + storage.type.function.arrow.js + + + name + meta.function.arrow.js + patterns + + + include + #function-declaration-parameters + + + + + begin + (?x) + (?<=[$\w]\.) + ([_$a-zA-Z][$\w]*) + \s*(?=(\((?>(?>[^()]+)|\g<-1>)*\))\s*([=-](?:\*|\/)?>)) + beginCaptures + + 1 + + name + entity.name.function.js + + + end + (?<=\))\s*([=-](?:\*|\/)?>) + endCaptures + + 1 + + name + storage.type.function.arrow.js + + + name + meta.function.static.arrow.js + patterns + + + include + #flowtype-polymorph + + + include + #function-declaration-parameters + + + begin (?x) @@ -1841,6 +1911,96 @@ patterns + + begin + (?x) + (?<!\.)\b(?:(class)|(interface))\b + (?=[^\n]+:) + beginCaptures + + 1 + + name + storage.type.class.js + + 2 + + name + storage.type.interface.flowtype.js + + + end + (:) + endCaptures + + 0 + + name + meta.brace.curly.begin.js + + + name + meta.class.js + patterns + + + include + #comments + + + begin + ([_$a-zA-Z][$\w]*) + beginCaptures + + 0 + + name + entity.name.class.js + + + end + (?=:) + patterns + + + include + #comments + + + include + #flowtype-polymorph + + + begin + (?<!\.)\b(extends)\b + beginCaptures + + 0 + + name + storage.type.extends.js + + + end + (?=:) + name + meta.class.extends.js + patterns + + + include + #flowtype-polymorph + + + include + #expression + + + + + + + begin (?<!\.)\b(?:(class)|(interface))\b @@ -1950,6 +2110,10 @@ include #class-properties + + include + #named-arrow-function + include #class-method-definition @@ -2033,7 +2197,7 @@ end - \) + (?:\)|:) endCaptures 0 @@ -2052,7 +2216,7 @@ begin - \( + (?:\(|(?=[_$a-zA-Z]|\{|\[)) beginCaptures 0 @@ -2062,7 +2226,7 @@ end - (?=\)) + (?=\)|:) patterns @@ -2479,7 +2643,7 @@ match - (?<!\.)\b(?>const|let|var)\b + (?<!\.)\b(?>const|let|var|now)\b name storage.type.js @@ -2518,7 +2682,7 @@ match - (?<!\.)\b(?>if|else)\b + (?<!\.)\b(?>if|else|elif)\b name keyword.control.conditional.js @@ -2682,6 +2846,101 @@ + literal-lightscript-blocks + + patterns + + + begin + (?<!\.)\b(if|elif|else)\b + beginCaptures + + 1 + + name + keyword.control.conditional.js + + + end + (:) + endCaptures + + 0 + + name + meta.brace.round.begin.js + + + name + meta.if.js + patterns + + + include + #comments + + + include + #expression + + + + + captures + + 1 + + name + keyword.control.trycatch.js + + 2 + + name + meta.brace.round.begin.js + + + match + (?<!\.)\b(try)(:) + name + meta.try.js + + + begin + (?<!\.)\b(catch)\b + beginCaptures + + 1 + + name + keyword.control.trycatch.js + + + end + (:) + endCaptures + + 0 + + name + meta.brace.round.begin.js + + + name + meta.catch.js + patterns + + + include + #comments + + + include + #literal-variable + + + + + literal-method patterns @@ -2981,23 +3240,26 @@ match - (?<!\.)\b(?>delete|instanceof|in|new|of|typeof|void|with)\b + (?<!\.)\b(?>delete|instanceof|in|new|of|typeof|void|with|from|idx|elem|key|val)\b name keyword.operator.js match (?x) - !(?!=)| # logical-not right-to-left right - && | # logical-and left-to-right both - \|\| | # logical-or left-to-right both + !(?!=) | # logical-not right-to-left right + && | # logical-and left-to-right both + \|\| | # logical-or left-to-right both + or(?=\s) | # logical-or left-to-right both + and(?=\s)| # logical-and left-to-right both + not(?=\s) # logical-not left-to-right both name keyword.operator.logical.js match (?x) - =(?!=)| # assignment right-to-left both + =(?!=) # assignment right-to-left both name keyword.operator.assignment.js @@ -3014,7 +3276,7 @@ \|= | # assignment right-to-left both <<= | # assignment right-to-left both >>= | # assignment right-to-left both - >>>= | # assignment right-to-left both + >>>= # assignment right-to-left both name keyword.operator.assignment.augmented.js @@ -3528,6 +3790,86 @@ + named-arrow-function + + patterns + + + begin + (?x) + ([_$a-zA-Z][$\w]*) + (?= + (?:\<[^\n]+\>)? + (\((?>(?>[^()]+)|\g<-1>)*\)) + (?::[^\n]+)? + \s* + [=-](?:get|set|\*|\/)?> + ) + beginCaptures + + 1 + + name + entity.name.function.js + + + end + \s*([=-](?:get|set|\*|\/)?>) + endCaptures + + 1 + + name + storage.type.function.arrow.js + + + name + meta.function.arrow.js + patterns + + + begin + (?<=[$\w])(?=\<) + end + (?<=\>)(?=\() + patterns + + + include + #flowtype-polymorph + + + + + begin + (?=\() + end + (?<=\)) + patterns + + + include + #function-declaration-parameters + + + + + begin + (?<=\))(?=:) + end + (?=\s*[=-](?:get|set|\*|\/)?>) + patterns + + + include + #flowtype-annotation + + + + + + + round-brackets patterns @@ -3860,28 +4202,6 @@ match (?<!\.)\b(process)(?:(\.)(?:(arch|argv|config|env|execArgv|execPath|exitCode|mainModule|pid|platform|stderr|stdin|stdout|title|version|versions)|(abort|chdir|cwd|exit|getgid|getgroups|getuid|hrtime|initgroups|kill|memoryUsage|nextTick|setgid|setgroups|setuid|umask|uptime)))?\b - - captures - - 1 - - name - support.type.object.module.js - - 2 - - name - keyword.operator.accessor.js - - 3 - - name - support.type.object.module.js - - - match - (?<!\.)\b(exports|module(?:(\.)(children|exports|filename|id|loaded|parent)))?\b - begin {{ diff --git a/LightScript.tmPreferences b/LightScript.tmPreferences new file mode 100644 index 0000000..ebfd783 --- /dev/null +++ b/LightScript.tmPreferences @@ -0,0 +1,26 @@ + + + + + name + LightScript + scope + source.js + settings + + decreaseIndentPattern + (?x) + ^\s*(\s*/[*].*[*]/\s*)*[}\])] + | ^\s*(</|/>) + increaseIndentPattern + (?x) + (if|elif|else|try|catch|for)[^\n]*:$ + | [\w_$]*\([^\n]*\)(?:\:\s+[^\n]+)?\s+[-=](?:get|set|\/|\*)?>$ + | {[^}\"']*$ + | \[[^\]\"']*$ + | \([^)\"']*$ + | <[a-zA-Z][^/]*$ + | ^\s*>$ + + + diff --git a/README.md b/README.md index 1ea3e92..36d1d93 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,13 @@ -# babel-sublime +# lightscript-sublime -> Only supports **Sublime Text 3**. Sublime Text 2 is no longer supported. +Syntax Highlighting for [LightScript](http://lightscript.org) -Language definitions for [ES6+ JavaScript](http://kangax.github.io/compat-table/es6/) with [React JSX syntax](http://facebook.github.io/react/docs/jsx-in-depth.html) extensions. - -## Installation - -Find it as [**Babel**](https://packagecontrol.io/packages/Babel) through [Package Control](https://packagecontrol.io/). - -#### Setting as the default syntax - -To set it as the default syntax for a particular extension: - 1. Open a file with that extension, - 2. Select `View` from the menu, - 3. Then `Syntax` `->` `Open all with current extension as...` `->` `Babel` `->` `JavaScript (Babel)`. - 4. Repeat this for each extension (e.g.: `.js` and `.jsx`). - -#### Setting a Color Scheme - -`Babel` comes bundled with `Next` and `Monokai` from [Benvie/JavaScriptNext.tmLanguage](https://github.com/Benvie/JavaScriptNext.tmLanguage). Select one from `Preferences` `->` `Color Scheme` `->` `Babel` - -#### Advanced usage - -It's possible to set `Babel` as the _only_ JavaScript package by disabling the stock one. To do so, add `"ignored_packages": ["JavaScript"]` to your `Preferences.sublime-settings`. The benefits include: - * extension-less node scripts will automatically be recognized as `JavaScript (Babel)`, - * and reduced clutter in the syntax menu. - -**Keep in mind**, the stock snippets will no longer work (you may still use your own), and other third-party packages that depend on the stock package may break (no known ones so far). - -## Screenshots - -![babel-sublime-vs-sublime-react--react-class](https://raw.githubusercontent.com/babel/babel-sublime/45c7d37/screenshots/compare-react-class@2x.png) - -* `babel-sublime` supports modern JavaScript syntax, including [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), [destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment), [shorthand methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions), [template strings](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings), and more. +Based on [babel-sublime](https://github.com/babel/babel-sublime). -![babel-sublime-vs-sublime-react--jsx-comments-etc](https://raw.githubusercontent.com/babel/babel-sublime/9a6e85f/screenshots/compare-jsx-comments-etc@2x.png) +Only supports Sublime Text 3. -* `babel-sublime` correctly matches JSX comments between attributes, namespaced components, and non-alpha characters in tag/attribute names. - -![babel-sublime-vs-sublime-react--jsx-tight](https://raw.githubusercontent.com/babel/babel-sublime/9a6e85f/screenshots/compare-jsx-tight@2x.png) - -* Greater-/less-than comparisons are correctly identified as such and not mistaken for JSX tags. - -## Snippets - -Find them separately at [babel/babel-sublime-snippets](https://github.com/babel/babel-sublime-snippets) or as [**Babel Snippets**](https://packagecontrol.io/packages/Babel Snippets) through [Package Control](https://packagecontrol.io/). - -## Suggested Resources - -Sublime Text Color Schemes which are ready for JavaScript's new features and babel-sublime package. - -#### [Oceanic Next Color Scheme](https://github.com/voronianski/oceanic-next-theme) - -[![](https://raw.githubusercontent.com/voronianski/babel-sublime/master/screenshots/oceanic-next.png)](https://github.com/voronianski/oceanic-next-theme) - -#### [Zeus Color Scheme](https://github.com/zaynali53/Zeus-Theme) - -[![zeus-color-scheme](https://raw.githubusercontent.com/zaynali53/Zeus-Theme/master/Zeus-Color-Scheme.PNG)](https://github.com/zaynali53/Zeus-Theme) - -## About - -Under the hood, _babel-sublime_ is based on the excellent [Benvie/JavaScriptNext.tmLanguage](https://github.com/Benvie/JavaScriptNext.tmLanguage) with JSX syntax support built on top. The initial definitions for JSX came from [reactjs/sublime-react](https://github.com/reactjs/sublime-react) via [yungters/sublime](https://github.com/yungsters/sublime.git) - special thanks go to [@jgebhardt](https://github.com/jgebhardt) and [@zpao](https://github.com/zpao). +Language definitions for [ES6+ JavaScript](http://kangax.github.io/compat-table/es6/) with [React JSX syntax](http://facebook.github.io/react/docs/jsx-in-depth.html) extensions. -## Contributing +## Installation -Pull Requests should include your changes to the respective `YAML-tmKittens` file as well as the converted `tmKittens` file. Use [AAAPackageDev](https://github.com/SublimeText/AAAPackageDev) to convert the `YAML-tmKittens` files. +Find it as [**LightScript**](https://packagecontrol.io/packages/lightscript) through [Package Control](https://packagecontrol.io/). diff --git a/messages.json b/messages.json index 80aa64c..de1e76b 100644 --- a/messages.json +++ b/messages.json @@ -4,5 +4,6 @@ "5.0.0": "messages/5.0.0.txt", "7.1.0": "messages/7.1.0.txt", "7.1.1": "messages/7.1.0.txt", - "8.0.0": "messages/8.0.0.txt" + "8.0.0": "messages/8.0.0.txt", + "108.0.0": "messages/108.0.0.txt" } diff --git a/messages/108.0.0.txt b/messages/108.0.0.txt new file mode 100644 index 0000000..3ca82c9 --- /dev/null +++ b/messages/108.0.0.txt @@ -0,0 +1,8 @@ +lightscript-sublime +------------------- + +First release of LightScript syntax highlighting. + +Hacky and probably incomplete. + +Since this is a fork, and Sublime Package Control uses git tags for versioning, a version bump of 100 is being used to ensure LightScript is ahead of previous Babel versions. diff --git a/screenshots/compare-jsx-comments-etc@2x.png b/screenshots/compare-jsx-comments-etc@2x.png deleted file mode 100644 index 6246d27..0000000 Binary files a/screenshots/compare-jsx-comments-etc@2x.png and /dev/null differ diff --git a/screenshots/compare-jsx-illegal@2x.png b/screenshots/compare-jsx-illegal@2x.png deleted file mode 100644 index ac8931f..0000000 Binary files a/screenshots/compare-jsx-illegal@2x.png and /dev/null differ diff --git a/screenshots/compare-jsx-tight@2x.png b/screenshots/compare-jsx-tight@2x.png deleted file mode 100644 index 9aa4a2e..0000000 Binary files a/screenshots/compare-jsx-tight@2x.png and /dev/null differ diff --git a/screenshots/compare-react-class@2x.png b/screenshots/compare-react-class@2x.png deleted file mode 100644 index 197d36d..0000000 Binary files a/screenshots/compare-react-class@2x.png and /dev/null differ diff --git a/screenshots/oceanic-next.png b/screenshots/oceanic-next.png deleted file mode 100644 index 4256f52..0000000 Binary files a/screenshots/oceanic-next.png and /dev/null differ diff --git a/test/lightscript_test.lsc b/test/lightscript_test.lsc new file mode 100644 index 0000000..08e5f58 --- /dev/null +++ b/test/lightscript_test.lsc @@ -0,0 +1,71 @@ +// this isn't a real test file (yet), just monkeying around with examples + +fn(): void -> 4 + +someFn() -> + return something() + +someOtherFn() -> 4 + +someOtherFn() -*> 3 + +const x: void = 4 + +fn(blah): void -> 4 +fn(blah: T = {}, bar: number = 8, ...blah): void -> 4 +fn(blah: T = {}, bar: number = 8, ...blah): void -> 4 + +foo = (blah = {}, bar: number = 8) => { + +} + +function foo(blah = {}, bar: number = 8, ...blah): void { + +} + +class HelloWorld extends Blah: + constructor() -> + hello() + + bar(blah): void -> + hello() + 1 + 1 + export default blah + +d + +class Blah: + @decorator() + thing = 4 + method() -> { + + } + x: 4 +export default HelloWorld + +class Hello { + method() { + + } + method2() { + } + +} + +hello + + +if true { + class SomeThing { + method() {} + method() -get> { + blah() + } + method3() { + hello() + } + } + class Hello: + method() -> + blah() +}