diff --git a/packages/languages/data/grammars/java.json b/packages/languages/data/grammars/java.json index 0e29ea4e8..3cfa6f563 100644 --- a/packages/languages/data/grammars/java.json +++ b/packages/languages/data/grammars/java.json @@ -1,102 +1,110 @@ { - "fileTypes": [ - "java", - "bsh" + "information_for_contributors": [ + "This file has been converted from https://github.com/atom/language-java/blob/master/grammars/java.cson", + "If you want to provide a fix or improvement, please create a pull request against the original repository.", + "Once accepted there, we are happy to receive an update request." ], - "keyEquivalent": "^~J", + "version": "https://github.com/atom/language-java/commit/2e179ceac423403eb5bf0eff26884093c3edba6f", "name": "Java", + "scopeName": "source.java", "patterns": [ { - "captures": { - "1": { - "name": "keyword.other.package.java" - }, - "2": { - "name": "storage.modifier.package.java" - }, - "3": { - "name": "punctuation.terminator.java" - } - }, - "match": "^\\s*(package)\\b(?:\\s*([^ ;$]+)\\s*(;)?)?", - "name": "meta.package.java" - }, - { - "begin": "(import static)\\b\\s*", + "begin": "\\b(package)\\b\\s*", "beginCaptures": { "1": { - "name": "keyword.other.import.static.java" - } - }, - "captures": { - "1": { - "name": "keyword.other.import.java" - }, - "2": { - "name": "storage.modifier.import.java" - }, - "3": { - "name": "punctuation.terminator.java" + "name": "keyword.other.package.java" } }, - "contentName": "storage.modifier.import.java", - "end": "\\s*(?:$|(;))", + "end": "\\s*(;)", "endCaptures": { "1": { "name": "punctuation.terminator.java" } }, - "name": "meta.import.java", + "name": "meta.package.java", + "contentName": "storage.modifier.package.java", "patterns": [ { - "match": "\\.", - "name": "punctuation.separator.java" + "include": "#comments" + }, + { + "match": "(?<=\\.)\\s*\\.|\\.(?=\\s*;)", + "name": "invalid.illegal.character_not_allowed_here.java" + }, + { + "match": "(?\n\t\t\t\t\t\t\t0[xX]\t\t\t\t\t\t\t\t\t# Start literal\n\t\t\t\t\t\t\t(\\h([\\h_]*\\h)?)?\t\t\t\t\t\t# Optional Number\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t(?<=\\h)\\.\t\t\t\t\t\t\t# A number must exist on\n\t\t\t\t\t\t | \\.(?=\\h)\t\t\t\t\t\t\t# one side of the decimal\n\t\t\t\t\t\t | (?<=\\h)\t\t\t\t\t\t\t\t# Decimal not required\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t(\\h([\\h_]*\\h)?)?\t\t\t\t\t\t# Optional Number\n\t\t\t\t\t\t\t[pP]\t\t\t\t\t\t\t\t\t# Exponent Indicator\n\t\t\t\t\t\t\t[+-]?(0|[1-9]([0-9_]*[0-9])?)\t\t\t# Signed Integer\n\t\t\t\t\t\t\t[fFdD]?\t\t\t\t\t\t\t\t\t# Float Type Suffix\n\t\t\t\t\t\t)\n\t\t\t\t\t\t(?!\\w)\t\t\t\t\t\t\t\t\t\t# Ensure word boundry\n\t\t\t\t\t", - "name": "constant.numeric.hex-float.java" + "match": "\\b(true|false|null)\\b", + "name": "constant.language.java" }, { - "match": "(?x)\n\t\t\t\t\t\t(?\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t(0|[1-9]([0-9_]*[0-9])?)\t\t\t\t# Leading digits\n\t\t\t\t\t\t\t\t(?=[eEfFdD.])\t\t\t\t\t\t\t# Allow for numbers without .\n\t\t\t\t\t\t\t)?\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t(?<=[0-9])(?=[eEfFdD])\t\t\t\t\t# Allow for numbers without .\n\t\t\t\t\t\t\t | \\.\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t[0-9]([0-9_]*[0-9])?\t\t\t\t\t# Numbers after .\n\t\t\t\t\t\t\t)?\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t[eE][+-]?(0|[1-9]([0-9_]*[0-9])?)\t\t# Exponent\n\t\t\t\t\t\t\t)?\n\t\t\t\t\t\t\t[fFdD]?\t\t\t\t\t\t\t\t\t\t# Float Type Suffix\n\t\t\t\t\t\t)\n\t\t\t\t\t\t(?!\\w)\t\t\t\t\t\t\t\t\t\t\t# Ensure word boundry\n\t\t\t\t\t", - "name": "constant.numeric.float.java" + "match": "\\bthis\\b", + "name": "variable.language.this.java" }, { - "captures": { - "1": { - "name": "keyword.operator.dereference.java" - } - }, - "match": "(\\.)?\\b([A-Z][A-Z0-9_]+)(?!<|\\.class|\\s*\\w+\\s*=)\\b", - "name": "constant.other.java" + "match": "\\bsuper\\b", + "name": "variable.language.java" } ] }, "enums": { - "begin": "^(?=\\s*[A-Z0-9_]+\\s*({|\\(|,))", - "end": "(?=;|})", + "begin": "^\\s*([\\w\\s]*)(enum)\\s+(\\w+)", + "beginCaptures": { + "1": { + "patterns": [ + { + "include": "#storage-modifiers" + } + ] + }, + "2": { + "name": "storage.modifier.java" + }, + "3": { + "name": "entity.name.type.enum.java" + } + }, + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.section.enum.end.bracket.curly.java" + } + }, + "name": "meta.enum.java", "patterns": [ { - "begin": "\\w+", + "begin": "\\b(extends)\\b", "beginCaptures": { - "0": { - "name": "constant.other.enum.java" + "1": { + "name": "storage.modifier.extends.java" } }, - "end": "(?=,|;|})", - "name": "meta.enum.java", + "end": "(?={|\\bimplements\\b)", + "name": "meta.definition.class.inherited.classes.java", "patterns": [ { - "include": "#parens" + "include": "#object-types-inherited" }, { - "begin": "{", - "beginCaptures": { - "0": { - "name": "punctuation.section.enum.begin.java" - } - }, - "end": "}", - "endCaptures": { - "0": { - "name": "punctuation.section.enum.end.java" - } - }, + "include": "#comments" + } + ] + }, + { + "begin": "\\b(implements)\\b", + "beginCaptures": { + "1": { + "name": "storage.modifier.implements.java" + } + }, + "end": "(?={|\\bextends\\b)", + "name": "meta.definition.class.implemented.interfaces.java", + "patterns": [ + { + "include": "#object-types-inherited" + }, + { + "include": "#comments" + } + ] + }, + { + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.section.enum.begin.bracket.curly.java" + } + }, + "end": "(?=})", + "patterns": [ + { + "begin": "(?<={)", + "end": "(?=;|})", "patterns": [ { - "include": "#class-body" + "include": "#comments-javadoc" + }, + { + "include": "#comments" + }, + { + "begin": "\\b(\\w+)\\b", + "beginCaptures": { + "1": { + "name": "constant.other.enum.java" + } + }, + "end": "(,)|(?=;|})", + "endCaptures": { + "1": { + "name": "punctuation.separator.delimiter.java" + } + }, + "patterns": [ + { + "include": "#comments-javadoc" + }, + { + "include": "#comments" + }, + { + "begin": "\\(", + "beginCaptures": { + "0": { + "name": "punctuation.bracket.round.java" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.bracket.round.java" + } + }, + "patterns": [ + { + "include": "#code" + } + ] + }, + { + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.bracket.curly.java" + } + }, + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.bracket.curly.java" + } + }, + "patterns": [ + { + "include": "#class-body" + } + ] + } + ] } ] + }, + { + "include": "#class-body" } ] + } + ] + }, + "function-call": { + "begin": "([A-Za-z_$][\\w$]*)\\s*(\\()", + "beginCaptures": { + "1": { + "name": "entity.name.function.java" }, + "2": { + "name": "punctuation.definition.parameters.begin.bracket.round.java" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.definition.parameters.end.bracket.round.java" + } + }, + "name": "meta.function-call.java", + "patterns": [ { - "include": "#comments" + "include": "#code" + } + ] + }, + "generics": { + "begin": "<", + "beginCaptures": { + "0": { + "name": "punctuation.bracket.angle.java" + } + }, + "end": ">", + "endCaptures": { + "0": { + "name": "punctuation.bracket.angle.java" + } + }, + "patterns": [ + { + "match": "\\b(extends|super)\\b", + "name": "storage.modifier.$1.java" }, { - "include": "#annotations" + "match": "(?>>?|~|\\^)", @@ -643,37 +943,58 @@ "name": "keyword.operator.bitwise.java" }, { - "match": "(?<=\\S)\\.(?=\\S)", - "name": "keyword.operator.dereference.java" + "match": "\\b(const|goto)\\b", + "name": "keyword.reserved.java" + } + ] + }, + "lambda-expression": { + "patterns": [ + { + "match": "->", + "name": "storage.type.function.arrow.java" + } + ] + }, + "member-variables": { + "begin": "(?=private|protected|public|native|synchronized|abstract|threadsafe|transient|static|final)", + "end": "(?=\\=|;)", + "patterns": [ + { + "include": "#storage-modifiers" }, { - "match": ";", - "name": "punctuation.terminator.java" + "include": "#variables" + }, + { + "include": "#primitive-arrays" + }, + { + "include": "#object-types" } ] }, "method-call": { - "begin": "([\\w$]+)(\\()", + "begin": "(\\.)\\s*([A-Za-z_$][\\w$]*)\\s*(\\()", "beginCaptures": { "1": { - "name": "meta.method.java" + "name": "punctuation.separator.period.java" }, "2": { - "name": "punctuation.definition.method-parameters.begin.java" + "name": "entity.name.function.java" + }, + "3": { + "name": "punctuation.definition.parameters.begin.bracket.round.java" } }, "end": "\\)", "endCaptures": { "0": { - "name": "punctuation.definition.method-parameters.end.java" + "name": "punctuation.definition.parameters.end.bracket.round.java" } }, "name": "meta.method-call.java", "patterns": [ - { - "match": ",", - "name": "punctuation.definition.seperator.parameter.java" - }, { "include": "#code" } @@ -684,7 +1005,7 @@ "end": "(})|(?=;)", "endCaptures": { "1": { - "name": "punctuation.section.method.end.java" + "name": "punctuation.section.method.end.bracket.curly.java" } }, "name": "meta.method.java", @@ -693,47 +1014,48 @@ "include": "#storage-modifiers" }, { - "begin": "(\\w+)\\s*\\(", + "begin": "(\\w+)\\s*(\\()", "beginCaptures": { "1": { "name": "entity.name.function.java" + }, + "2": { + "name": "punctuation.definition.parameters.begin.bracket.round.java" } }, "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.definition.parameters.end.bracket.round.java" + } + }, "name": "meta.method.identifier.java", "patterns": [ { "include": "#parameters" }, + { + "include": "#parens" + }, { "include": "#comments" } ] }, { - "begin": "<", - "end": ">", - "name": "storage.type.token.java", - "patterns": [ - { - "include": "#object-types" - }, - { - "begin": "<", - "comment": "This is just to support <>'s with no actual type prefix", - "end": ">|[^\\w\\s,\\[\\]<]", - "name": "storage.type.generic.java" - } - ] + "include": "#generics" }, { "begin": "(?=\\w.*\\s+\\w+\\s*\\()", - "end": "(?=\\w+\\s*\\()", + "end": "(?=\\s+\\w+\\s*\\()", "name": "meta.method.return-type.java", "patterns": [ { "include": "#all-types" }, + { + "include": "#parens" + }, { "include": "#comments" } @@ -746,11 +1068,11 @@ "begin": "{", "beginCaptures": { "0": { - "name": "punctuation.section.method.begin.java" + "name": "punctuation.section.method.begin.bracket.curly.java" } }, "end": "(?=})", - "name": "meta.method.body.java", + "contentName": "meta.method.body.java", "patterns": [ { "include": "#code" @@ -762,136 +1084,466 @@ } ] }, - "object-types": { + "module": { + "begin": "((open)\\s)?(module)\\s+(\\w+)", + "end": "}", + "beginCaptures": { + "1": { + "name": "storage.modifier.java" + }, + "3": { + "name": "storage.modifier.java" + }, + "4": { + "name": "entity.name.type.module.java" + } + }, + "endCaptures": { + "0": { + "name": "punctuation.section.module.end.bracket.curly.java" + } + }, + "name": "meta.module.java", "patterns": [ { - "begin": "\\b((?:[a-z]\\w*\\.)*[A-Z]+\\w*)<", - "end": ">|[^\\w\\s,\\?<\\[\\]]", - "name": "storage.type.generic.java", + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.section.module.begin.bracket.curly.java" + } + }, + "end": "(?=})", + "contentName": "meta.module.body.java", "patterns": [ { - "include": "#object-types" - }, - { - "begin": "<", - "comment": "This is just to support <>'s with no actual type prefix", - "end": ">|[^\\w\\s,\\[\\]<]", - "name": "storage.type.generic.java" + "match": "\\b(requires|transitive|exports|opens|to|uses|provides|with)\\b", + "name": "keyword.module.java" } ] + } + ] + }, + "numbers": { + "patterns": [ + { + "match": "(?x)\n\\b(?|[^\\w\\s,<]", - "name": "entity.other.inherited-class.java", - "patterns": [ - { - "include": "#object-types" - }, - { - "begin": "<", - "comment": "This is just to support <>'s with no actual type prefix", - "end": ">|[^\\w\\s,<]", - "name": "storage.type.generic.java" - } - ] + "include": "#generics" }, { + "match": "\\b(?:[A-Z]\\w*\\s*(\\.)\\s*)*[A-Z]\\w*\\b", + "name": "entity.other.inherited-class.java", "captures": { "1": { - "name": "keyword.operator.dereference.java" + "name": "punctuation.separator.period.java" } - }, - "match": "\\b(?:[a-z]\\w*(\\.))*[A-Z]+\\w*", - "name": "entity.other.inherited-class.java" + } + }, + { + "match": ",", + "name": "punctuation.separator.delimiter.java" } ] }, + "objects": { + "match": "(?)?(\\()", + "beginCaptures": { + "1": { + "name": "storage.modifier.java" + }, + "2": { + "name": "entity.name.type.record.java" + }, + "3": { + "patterns": [ + { + "include": "#generics" + } + ] + }, + "4": { + "name": "punctuation.definition.parameters.begin.bracket.round.java" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.definition.parameters.end.bracket.round.java" + } + }, + "name": "meta.record.identifier.java", + "patterns": [ + { + "include": "#code" + } + ] + }, + { + "begin": "(implements)\\s", + "beginCaptures": { + "1": { + "name": "storage.modifier.implements.java" + } + }, + "end": "(?=\\s*\\{)", + "name": "meta.definition.class.implemented.interfaces.java", + "patterns": [ + { + "include": "#object-types-inherited" + }, + { + "include": "#comments" + } + ] + }, + { + "include": "#record-body" + } + ] + }, + "record-body": { + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.section.class.begin.bracket.curly.java" + } + }, + "end": "(?=})", + "name": "meta.record.body.java", + "patterns": [ + { + "include": "#record-constructor" + }, + { + "include": "#class-body" + } + ] + }, + "record-constructor": { + "begin": "(?!new)(?=[\\w<].*\\s+)(?=([^\\(=/]|/(?!/))+(?={))", + "end": "(})|(?=;)", + "endCaptures": { "1": { - "name": "storage.modifier.java" + "name": "punctuation.section.method.end.bracket.curly.java" } }, - "match": "\\b(public|private|protected|static|final|native|synchronized|volatile|abstract|threadsafe|transient|strictfp)\\b" + "name": "meta.method.java", + "patterns": [ + { + "include": "#storage-modifiers" + }, + { + "begin": "(\\w+)", + "beginCaptures": { + "1": { + "name": "entity.name.function.java" + } + }, + "end": "(?=\\s*{)", + "name": "meta.method.identifier.java", + "patterns": [ + { + "include": "#comments" + } + ] + }, + { + "include": "#comments" + }, + { + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.section.method.begin.bracket.curly.java" + } + }, + "end": "(?=})", + "contentName": "meta.method.body.java", + "patterns": [ + { + "include": "#code" + } + ] + } + ] + }, + "static-initializer": { + "patterns": [ + { + "include": "#anonymous-block-and-instance-initializer" + }, + { + "match": "static", + "name": "storage.modifier.java" + } + ] + }, + "storage-modifiers": { + "match": "\\b(public|private|protected|static|final|native|synchronized|abstract|threadsafe|transient|volatile|default|strictfp)\\b", + "name": "storage.modifier.java" }, "strings": { "patterns": [ @@ -950,81 +1602,230 @@ "name": "meta.throwables.java", "patterns": [ { - "include": "#object-types" - } - ] - }, - "values": { - "patterns": [ - { - "include": "#strings" - }, - { - "include": "#object-types" + "match": ",", + "name": "punctuation.separator.delimiter.java" }, { - "include": "#constants-and-special-vars" + "match": "[a-zA-Z$_][\\.a-zA-Z0-9$_]*", + "name": "storage.type.java" } ] }, - "variables": { - "applyEndPatternLast": 1, + "try-catch-finally": { "patterns": [ { - "begin": "(?x:(?=\n (?:\n (?:private|protected|public|native|synchronized|volatile|abstract|threadsafe|transient|static|final) # visibility/modifier\n |\n (?:def)\n |\n (?:void|boolean|byte|char|short|int|float|long|double)\n |\n (?:(?:[a-z]\\w*\\.)*[A-Z]+\\w*) # object type\n )\n \\s+\n (?!private|protected|public|native|synchronized|volatile|abstract|threadsafe|transient|static|final|def|void|boolean|byte|char|short|int|float|long|double)\n [\\w\\d_<>\\[\\],\\?][\\w\\d_<>\\[\\],\\? \\t]*\n (?:=|$)\n \n\t\t\t\t\t))", - "end": "(?=;)", - "name": "meta.definition.variable.java", + "begin": "\\btry\\b", + "beginCaptures": { + "0": { + "name": "keyword.control.try.java" + } + }, + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.section.try.end.bracket.curly.java" + } + }, + "name": "meta.try.java", "patterns": [ { - "match": "\\s" + "begin": "\\(", + "beginCaptures": { + "0": { + "name": "punctuation.section.try.resources.begin.bracket.round.java" + } + }, + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.section.try.resources.end.bracket.round.java" + } + }, + "name": "meta.try.resources.java", + "patterns": [ + { + "include": "#code" + } + ] }, { - "captures": { - "1": { - "name": "constant.other.variable.java" + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.section.try.begin.bracket.curly.java" } }, - "match": "([A-Z_0-9]+)\\s+(?=\\=)" + "end": "(?=})", + "contentName": "meta.try.body.java", + "patterns": [ + { + "include": "#code" + } + ] + } + ] + }, + { + "begin": "\\b(catch)\\b", + "beginCaptures": { + "1": { + "name": "keyword.control.catch.java" + } + }, + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.section.catch.end.bracket.curly.java" + } + }, + "name": "meta.catch.java", + "patterns": [ + { + "include": "#comments" }, { - "captures": { - "1": { - "name": "meta.definition.variable.name.java" + "begin": "\\(", + "beginCaptures": { + "0": { + "name": "punctuation.definition.parameters.begin.bracket.round.java" } }, - "match": "(\\w[^\\s,]*)\\s+(?=\\=)" + "end": "\\)", + "endCaptures": { + "0": { + "name": "punctuation.definition.parameters.end.bracket.round.java" + } + }, + "contentName": "meta.catch.parameters.java", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#storage-modifiers" + }, + { + "begin": "[a-zA-Z$_][\\.a-zA-Z0-9$_]*", + "beginCaptures": { + "0": { + "name": "storage.type.java" + } + }, + "end": "(\\|)|(?=\\))", + "endCaptures": { + "1": { + "name": "punctuation.catch.separator.java" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "match": "\\w+", + "captures": { + "0": { + "name": "variable.parameter.java" + } + } + } + ] + } + ] }, { - "begin": "=", + "begin": "{", "beginCaptures": { "0": { - "name": "keyword.operator.assignment.java" + "name": "punctuation.section.catch.begin.bracket.curly.java" } }, - "end": "(?=;)", + "end": "(?=})", + "contentName": "meta.catch.body.java", "patterns": [ { "include": "#code" } ] - }, + } + ] + }, + { + "begin": "\\bfinally\\b", + "beginCaptures": { + "0": { + "name": "keyword.control.finally.java" + } + }, + "end": "}", + "endCaptures": { + "0": { + "name": "punctuation.section.finally.end.bracket.curly.java" + } + }, + "name": "meta.finally.java", + "patterns": [ { - "captures": { - "1": { - "name": "meta.definition.variable.name.java" + "begin": "{", + "beginCaptures": { + "0": { + "name": "punctuation.section.finally.begin.bracket.curly.java" } }, - "match": "(\\w[^\\s=]*)(?=\\s*;)" - }, - { - "include": "#code" + "end": "(?=})", + "contentName": "meta.finally.body.java", + "patterns": [ + { + "include": "#code" + } + ] } ] } ] + }, + "variables": { + "begin": "(?x)\n(?=\n (\n \\b(void|boolean|byte|char|short|int|float|long|double)\\b\n |\n (?>(\\w+\\.)*[A-Z_]+\\w*) # e.g. `javax.ws.rs.Response`, or `String`\n )\n \\s*\n (\n <[\\w<>,\\.?\\s\\[\\]]*> # e.g. `HashMap`, or `List`\n )?\n \\s*\n (\n (\\[\\])* # int[][]\n )?\n \\s+\n [A-Za-z_$][\\w$]* # At least one identifier after space\n ([\\w\\[\\],$][\\w\\[\\],\\s]*)? # possibly primitive array or additional identifiers\n \\s*(=|:|;)\n)", + "end": "(?=\\=|:|;)", + "name": "meta.definition.variable.java", + "patterns": [ + { + "match": "([A-Za-z$_][\\w$]*)(?=\\s*(\\[\\])*\\s*(;|:|=|,))", + "captures": { + "1": { + "name": "variable.other.definition.java" + } + } + }, + { + "include": "#all-types" + }, + { + "include": "#code" + } + ] + }, + "variables-local": { + "begin": "(?=\\b(var)\\b\\s+[A-Za-z_$][\\w$]*\\s*(=|:|;))", + "end": "(?=\\=|:|;)", + "name": "meta.definition.variable.local.java", + "patterns": [ + { + "match": "\\bvar\\b", + "name": "storage.type.local.java" + }, + { + "match": "([A-Za-z$_][\\w$]*)(?=\\s*(\\[\\])*\\s*(=|:|;))", + "captures": { + "1": { + "name": "variable.other.definition.java" + } + } + }, + { + "include": "#code" + } + ] } - }, - "scopeName": "source.java", - "uuid": "2B449DF6-6B1D-11D9-94EC-000D93589AF6", - "version": "https://github.com/textmate/java.tmbundle/commit/faffa518d0b22b68b4e5e6b4c939722522b97d40" -} + } +} \ No newline at end of file