diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..3942950 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Nicolas Stucki + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3fe04f --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# Scala Syntax + +This is my Scala syntax for VS Code and it is based on https://github.com/sellmerfud/scala.tmbundle + +I decided create a new extension after problems with Scala extension from Iliya Tryapitsin. + +## Features + +Only scala syntax. + +## Requirements + +No requirements. + +## License +[MIT](LICENSE) + +----------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/images/smooth-spiral.png b/images/smooth-spiral.png new file mode 100644 index 0000000..39f5c60 Binary files /dev/null and b/images/smooth-spiral.png differ diff --git a/language-configuration.json b/language-configuration.json new file mode 100644 index 0000000..0ec3071 --- /dev/null +++ b/language-configuration.json @@ -0,0 +1,33 @@ +{ + "comments": { + // symbol used for single line comment. Remove this entry if your language does not support line comments + "lineComment": "//", + // symbols used for start and end a block comment. Remove this entry if your language does not support block comments + "blockComment": [ "/*", "*/" ] + }, + // symbols used as brackets + "brackets": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["'{", "}"], + ["'[", "]"], + ["'(", ")"] + ], + // symbols that are auto closed when typing + "autoClosingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"] + ], + // symbols that that can be used to surround a selection + "surroundingPairs": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["\"", "\""], + ["'", "'"] + ] +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..7f179ff --- /dev/null +++ b/package.json @@ -0,0 +1,43 @@ +{ + "name": "scala", + "displayName": "Scala Syntax", + "description": "Scala Syntax", + "version": "0.0.3", + "publisher": "Nicolas Stucki", + "license": "SEE LICENSE IN LICENSE.md", + "engines": { + "vscode": "^1.5.0" + }, + "homepage": "https://github.com/scala/vscode-scala-syntax/blob/master/README.md", + "repository": { + "type": "git", + "url": "https://github.com/scala/vscode-scala-syntax.git" + }, + "icon": "images/smooth-spiral.png", + "categories": [ + "Languages" + ], + "contributes": { + "languages": [ + { + "id": "scala", + "aliases": [ + "Scala", + "scala" + ], + "extensions": [ + ".scala", + ".sbt" + ], + "configuration": "./language-configuration.json" + } + ], + "grammars": [ + { + "language": "scala", + "scopeName": "source.scala", + "path": "./syntaxes/Scala.tmLanguage" + } + ] + } +} diff --git a/syntaxes/Scala.tmLanguage b/syntaxes/Scala.tmLanguage new file mode 100644 index 0000000..e088578 --- /dev/null +++ b/syntaxes/Scala.tmLanguage @@ -0,0 +1,1189 @@ + + + + + fileTypes + + scala + + firstLineMatch + ^#!/.*\b\w*scala\b + foldingStartMarker + /\*\*|\{\s*$ + foldingStopMarker + \*\*/|^\s*\} + keyEquivalent + ^~S + name + Scala + patterns + + + include + #code + + + repository + + block-comments + + begin + /\* + beginCaptures + + 1 + + name + punctuation.definition.comment.begin.scala + + + end + \*/ + endCaptures + + 1 + + name + punctuation.definition.comment.end.scala + + + name + comment.block.scala + patterns + + + include + #block-comments + + + + char-literal + + begin + ' + beginCaptures + + 0 + + name + punctuation.definition.character.begin.scala + + + end + ' + endCaptures + + 0 + + name + punctuation.definition.character.end.scala + + + name + constant.character.literal.scala + patterns + + + match + \\(?:[btnfr\\"']|[0-7]{1,3}|u[0-9A-Fa-f]{4}) + name + constant.character.escape.scala + + + match + \\. + name + invalid.illegal.unrecognized-character-escape.scala + + + match + [^']{2,} + name + invalid.illegal.character-literal-too-long + + + match + (?<!')[^'] + name + invalid.illegal.character-literal-too-long + + + + code + + patterns + + + include + #storage-modifiers + + + include + #declarations + + + include + #inheritance + + + include + #imports + + + include + #comments + + + include + #strings + + + include + #initialization + + + include + #xml-literal + + + include + #keywords + + + include + #constants + + + include + #scala-symbol + + + include + #char-literal + + + include + #empty-blocks + + + include + #parameter-list + + + include + #qualifiedClassName + + + include + #meta-brackets + + + include + #meta-bounds + + + include + #meta-colons + + + + comments + + patterns + + + captures + + 0 + + name + punctuation.definition.comment.scala + + + match + /\*\*/ + name + comment.block.empty.scala + + + begin + ^\s*(/\*\*) + beginCaptures + + 1 + + name + punctuation.definition.comment.scala + + + end + \*/ + endCaptures + + 0 + + name + punctuation.definition.comment.scala + + + name + comment.block.documentation.scala + patterns + + + captures + + 1 + + name + keyword.other.documentation.scaladoc.scala + + 2 + + name + variable.parameter.scala + + + match + (@param)\s+(\S+) + + + captures + + 1 + + name + keyword.other.documentation.scaladoc.scala + + 2 + + name + entity.name.type.class.scala + + + match + (@(?:tparam|throws))\s+(\S+) + + + match + @(return|see|note|example|usecase|author|version|since|todo|deprecated|migration|define|inheritdoc)\b + name + keyword.other.documentation.scaladoc.scala + + + captures + + 1 + + name + punctuation.definition.documentation.link.scala + + 2 + + name + entity.name.type.class.documentation.link.scala + + 3 + + name + punctuation.definition.documentation.link.scala + + + match + (\[\[)([^\]]+)(\]\]) + + + + + include + #block-comments + + + captures + + 1 + + name + comment.line.double-slash.scala + + 2 + + name + punctuation.definition.comment.scala + + + match + \s*((//).*$\n?) + + + + constants + + patterns + + + match + \b(false|null|true|Nil|None)\b + name + constant.language.scala + + + match + \b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)([LlFfUuDd]|UL|ul)?\b + name + constant.numeric.scala + + + match + \b(this|super|self)\b + name + variable.language.scala + + + match + \b(Unit|Boolean|Byte|Char|Short|Int|Float|Long|Double)\b + name + storage.type.primitive.scala + + + match + \b(String|Symbol)\b + name + storage.type.scala + + + + declarations + + patterns + + + captures + + 1 + + name + keyword.control.def.scala + + 2 + + name + entity.name.function.declaration.scala + + + match + (?x) + \b(def)\s+ + (`[^`]+`|[_$a-zA-Z][_$a-zA-Z0-9]*(?:_[^\s])(?=[(\t ])|[_$a-zA-Z][_$a-zA-Z0-9]*|[-?~><^+*%:!#|/@\\]+) + + + captures + + 1 + + name + storage.modifier.case.scala + + 2 + + name + storage.type.$1.scala + + 3 + + name + entity.name.type.class.declaration.scala + + + match + (?:(case) +)?\b(class|trait|object)\s+([^\s\{\(\[]+) + + + captures + + 1 + + name + keyword.control.type.scala + + 2 + + name + entity.name.type.type.declaration.scala + + + match + \b(type)\s+(`[^`]+`|[_$a-zA-Z][_$a-zA-Z0-9]*(?:_[^\s])(?=[\t ])|[_$a-zA-Z][_$a-zA-Z0-9]*|[-?~><^+*%:!#|/@\\]+) + + + captures + + 1 + + name + storage.type.stable.scala + + 2 + + name + storage.type.volatile.scala + + 3 + + name + entity.name.type.val.declaration.scala + + + match + \b(?:(val)|(var))\s+(?:(`[^`]+`|[_$a-zA-Z][_$a-zA-Z0-9]*(?:_[^\s])(?=[\t ])|[_$a-zA-Z][_$a-zA-Z0-9]*|[-?~><^+*%:!#|/@\\]+)|(?=\()) + + + captures + + 1 + + name + storage.type.package.scala + + 2 + + name + storage.type.package.object.scala + + 3 + + name + entity.name.type.class.declaration.scala + + + match + \b(package) (object)\s+([^\s\{\(\[]+) + + + captures + + 1 + + name + storage.type.package.scala + + 2 + + name + entity.name.type.package.scala + + + match + \b(package)\s+([\w\.]+) + name + meta.package.scala + + + + empty-blocks + + patterns + + + captures + + 1 + + name + punctuation.definition.parentheses.begin.scala + + 2 + + name + punctuation.definition.parentheses.end.scala + + + match + (\()(\)) + name + meta.parentheses.scala + + + captures + + 1 + + name + punctuation.definition.parentheses.begin.scala + + 2 + + name + punctuation.definition.parentheses.end.scala + + + match + (\{)(\}) + name + meta.braces.scala + + + + imports + + begin + \b(import)\s+ + beginCaptures + + 1 + + name + keyword.control.import.scala + + + end + (?<=[\n;]) + name + meta.import.scala + patterns + + + include + #comments + + + match + ([^\s{;.]+)\s*\.\s* + name + variable.other.package.scala + + + match + ([^\s{;.]+)\s* + name + variable.other.import.scala + + + begin + { + beginCaptures + + 0 + + name + meta.bracket.scala + + + end + } + endCaptures + + 0 + + name + meta.bracket.scala + + + name + meta.import.selector.scala + patterns + + + captures + + 1 + + name + variable.other.import.renamed-from.scala + + 2 + + name + keyword.operator.scala + + 3 + + name + variable.other.import.renamed-to.scala + + + match + (?x) \s* + ([^\s.,}]+) \s* + (=>) \s* + ([^\s.,}]+) \s* + + + + match + ([^\s.,}]+) + name + variable.other.import.scala + + + + + + inheritance + + patterns + + + captures + + 1 + + name + storage.modifier.extends.scala + + 2 + + name + entity.other.inherited-class.scala + + + match + (extends|with)\s+([^\s\{\(\[\]]+) + + + + initialization + + captures + + 1 + + name + keyword.control.directive.scala + + 2 + + name + entity.name.type.class.scala + + + match + \b(new)\s+([^\s\{\(\[]+) + + keywords + + patterns + + + match + \b(return|throw)\b + name + keyword.control.flow.jump.scala + + + match + \b(classOf|isInstanceOf|asInstanceOf)\b + name + support.function.type-of.scala + + + match + \b(else|if|do|while|for|yield|match|case)\b + name + keyword.control.flow.scala + + + match + \b(catch|finally|try)\b + name + keyword.control.exception.scala + + + match + (==?|!=|<=|>=|<>|<|>) + name + keyword.operator.comparison.scala + + + match + (\-|\+|\*|/(?![/*])|%|~) + name + keyword.operator.arithmetic.scala + + + match + (!|&&|\|\|) + name + keyword.operator.logical.scala + + + match + (<-|←|->|→|=>|⇒|\?|\:+|@|\|)+ + name + keyword.operator.scala + + + + meta-bounds + + comment + For themes: Matching view bounds + match + <%|=:=|<:<|<%<|>:|<: + name + meta.bounds.scala + + meta-brackets + + comment + For themes: Brackets look nice when colored. + patterns + + + match + {|}|\(|\)|\[|\] + name + meta.bracket.scala + + + + meta-colons + + comment + For themes: Matching type colons + patterns + + + match + (?<!:):(?!:) + name + meta.colon.scala + + + + parameter-list + + patterns + + + captures + + 1 + + name + variable.parameter.scala + + 2 + + name + meta.colon.scala + + + comment + We do not match param names that start with a Capitol letter + match + (?<=[^\._$a-zA-Z0-9])(`[^`]+`|[_$a-z][_$a-zA-Z0-9]*(?:_[^\s])(?=[\t ])|[_$a-z][_$a-zA-Z0-9]*|[-?~><^+*%:!#|/@\\]+)\s*(:)\s+ + + + + qualifiedClassName + + captures + + 1 + + name + entity.name.type.class.scala + + + match + (\b([A-Z][\w]*)) + + scala-symbol + + match + '\w+(?=[^'\w]) + name + entity.name.type.symbol.scala + + storage-modifiers + + patterns + + + match + \b(private\[\S+\]|protected\[\S+\]|private|protected)\b + name + storage.modifier.access.scala + + + match + \b(synchronized|@volatile|abstract|final|lazy|sealed|implicit|override|@transient|@native)\b + name + storage.modifier.other.scala + + + + strings + + patterns + + + begin + """ + beginCaptures + + 0 + + name + punctuation.definition.string.begin.scala + + + end + """(?!") + endCaptures + + 0 + + name + punctuation.definition.string.end.scala + + + name + string.quoted.triple.scala + patterns + + + match + \\\\|\\u[0-9A-Fa-f]{4} + name + constant.character.escape.scala + + + + + begin + " + beginCaptures + + 0 + + name + punctuation.definition.string.begin.scala + + + end + " + endCaptures + + 0 + + name + punctuation.definition.string.end.scala + + + name + string.quoted.double.scala + patterns + + + match + \\(?:[btnfr\\"']|[0-7]{1,3}|u[0-9A-Fa-f]{4}) + name + constant.character.escape.scala + + + match + \\. + name + invalid.illegal.unrecognized-string-escape.scala + + + + + + xml-doublequotedString + + begin + " + beginCaptures + + 0 + + name + punctuation.definition.string.begin.xml + + + end + " + endCaptures + + 0 + + name + punctuation.definition.string.end.xml + + + name + string.quoted.double.xml + patterns + + + include + #xml-entity + + + + xml-embedded-content + + patterns + + + begin + { + captures + + 0 + + name + meta.bracket.scala + + + end + } + name + meta.source.embedded.scala + patterns + + + include + #code + + + + + captures + + 1 + + name + entity.other.attribute-name.namespace.xml + + 2 + + name + entity.other.attribute-name.xml + + 3 + + name + punctuation.separator.namespace.xml + + 4 + + name + entity.other.attribute-name.localname.xml + + + match + (?:([-_a-zA-Z0-9]+)((:)))?([_a-zA-Z-]+)= + + + include + #xml-doublequotedString + + + include + #xml-singlequotedString + + + + xml-entity + + captures + + 1 + + name + punctuation.definition.constant.xml + + 3 + + name + punctuation.definition.constant.xml + + + match + (&)([:a-zA-Z_][:a-zA-Z0-9_.-]*|#[0-9]+|#x[0-9a-fA-F]+)(;) + name + constant.character.entity.xml + + xml-literal + + patterns + + + begin + (<)((?:([_a-zA-Z0-9][_a-zA-Z0-9]*)((:)))?([_a-zA-Z0-9][-_a-zA-Z0-9:]*))(?=(\s[^>]*)?></\2>) + beginCaptures + + 1 + + name + punctuation.definition.tag.xml + + 3 + + name + entity.name.tag.namespace.xml + + 4 + + name + entity.name.tag.xml + + 5 + + name + punctuation.separator.namespace.xml + + 6 + + name + entity.name.tag.localname.xml + + + comment + We do not allow a tag name to start with a - since this would + likely conflict with the <- operator. This is not very common + for tag names anyway. Also code such as -- if (val <val2 || val> val3) + will falsly be recognized as an xml tag. The solution is to put a + space on either side of the comparison operator + end + (>(<))/(?:([-_a-zA-Z0-9]+)((:)))?([-_a-zA-Z0-9:]*[_a-zA-Z0-9])(>) + endCaptures + + 1 + + name + punctuation.definition.tag.xml + + 2 + + name + meta.scope.between-tag-pair.xml + + 3 + + name + entity.name.tag.namespace.xml + + 4 + + name + entity.name.tag.xml + + 5 + + name + punctuation.separator.namespace.xml + + 6 + + name + entity.name.tag.localname.xml + + 7 + + name + punctuation.definition.tag.xml + + + name + meta.tag.no-content.xml + patterns + + + include + #xml-embedded-content + + + + + begin + (</?)(?:([_a-zA-Z0-9][-_a-zA-Z0-9]*)((:)))?([_a-zA-Z0-9][-_a-zA-Z0-9:]*)(?=[^>]*?>) + captures + + 1 + + name + punctuation.definition.tag.xml + + 2 + + name + entity.name.tag.namespace.xml + + 3 + + name + entity.name.tag.xml + + 4 + + name + punctuation.separator.namespace.xml + + 5 + + name + entity.name.tag.localname.xml + + + end + (/?>) + name + meta.tag.xml + patterns + + + include + #xml-embedded-content + + + + + include + #xml-entity + + + + xml-singlequotedString + + begin + ' + beginCaptures + + 0 + + name + punctuation.definition.string.begin.xml + + + end + ' + endCaptures + + 0 + + name + punctuation.definition.string.end.xml + + + name + string.quoted.single.xml + patterns + + + include + #xml-entity + + + + + scopeName + source.scala + uuid + 158C0929-299A-40C8-8D89-316BE0C446E8 + + diff --git a/vsc-extension-quickstart.md b/vsc-extension-quickstart.md new file mode 100644 index 0000000..5c03c0b --- /dev/null +++ b/vsc-extension-quickstart.md @@ -0,0 +1,27 @@ +# Welcome to your VS Code Extension + +## What's in the folder +* This folder contains all of the files necessary for your extension +* `package.json` - this is the manifest file in which you declare your language support and define +the location of the grammar file that has been copied into you extension. +* `syntaxes/Scala.tmLanguage` - this is the Text mate grammar file that is used for tokenization +* `language-configuration.json` - this the language configuration, defining the tokens that are used for +comments and brackets. + +## Get up and running straight away +* Make sure the language configuration settings in `language-configuration.json` are accurate +* press `F5` to open a new window with your extension loaded +* create a new file with a file name suffix matching your language +* verify that syntax highlight works and that the language configuration settings are working + +## Make changes +* you can relaunch the extension from the debug toolbar after making changes to the files listed above +* you can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes + +## Add more language features +* To add features such as intellisense, hovers and validators check out the VS Code extenders documentation at +https://code.visualstudio.com/docs + +## Install your extension +* To start using your extension with Visual Studio Code copy it into the /.vscode/extensions folder and restart Code. +* To share your extension with the world, read on https://code.visualstudio.com/docs about publishing an extension. \ No newline at end of file