%YAML 1.2 --- # http://www.sublimetext.com/docs/3/syntax.html name: Java file_extensions: - java - bsh scope: source.java variables: primitives: \b(boolean|byte|char|short|int|float|long|double)\b primitives_with_void: \bvoid\b|{{primitives}} # source: http://stackoverflow.com/a/5205467/9815 id: '(?:[\p{L}_$][\p{L}\p{N}_$]*)' qualified_id: '(?:(?:{{id}}\.)*{{id}})' # utility lookaround within_generics: '(?:<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>)' # handles 3 levels nesting lambda_lookahead: '(\([^)]*\)|{{id}})\s*->' contexts: prototype: - include: comments main: - include: comments - include: package - include: import - include: annotations - include: code package: - match: '\bpackage\b' scope: keyword.other.package.java push: - meta_scope: meta.package.java - match: '[\w\.]+' scope: support.other.package.java - match: ; scope: punctuation.terminator.java pop: true - match: (?=\n) pop: true import: - match: \bimport\b scope: keyword.other.import.java push: - meta_scope: meta.import.java - match: \bstatic\b scope: storage.modifier.static.java push: - match: '[\w\.]+' scope: support.function.import.java - match: (?=;) pop: true - match: (?=\n) pop: true - match: '[\w\.]+' scope: support.class.import.java - match: ; scope: punctuation.terminator.java pop: true - match: (?=\n) pop: true all-types: - include: primitive-arrays - include: primitive-types annotations: - match: '(@)(?={{qualified_id}})' scope: meta.annotation.java punctuation.definition.annotation.java push: - match: '[ \t]+(?!$)' scope: meta.annotation.java - match: '({{id}})(\.)' scope: meta.annotation.identifier.java captures: 1: support.class.java 2: punctuation.accessor.dot.java - match: '({{id}})(\()' captures: 1: meta.annotation.identifier.java variable.annotation.java 2: meta.annotation.parameters.java punctuation.section.parens.begin.java set: - meta_content_scope: meta.annotation.parameters.java - match: \) scope: meta.annotation.parameters.java punctuation.section.parens.end.java pop: true - include: code - match: '{{id}}' scope: meta.annotation.identifier.java variable.annotation.java - match: (?=\S|$) pop: true anonymous-classes-and-new: - match: \bnew\b scope: keyword.control.new.java push: instantiation instantiation: - match: '{{primitives}}' scope: storage.type.primitive.java set: instantiation-arrays - match: '{{qualified_id}}' scope: support.class.java set: instantiation-generics - match: '(?=\S)' pop: true instantiation-generics: - match: '<' scope: punctuation.definition.generic.begin.java set: - meta_scope: meta.generic.java - match: '>' scope: punctuation.definition.generic.end.java set: instantiation-arrays - include: generic-instantiation - match: '(?=\S)' set: instantiation-arrays instantiation-arrays: - match: \[ scope: punctuation.section.brackets.begin.java set: - meta_scope: meta.brackets.java - match: \] scope: punctuation.section.brackets.end.java pop: true - include: code - match: \( scope: punctuation.section.parens.begin.java set: - meta_scope: meta.parens.java - match: \) scope: punctuation.section.parens.end.java set: instantiation-anon-class - include: code - match: '(?=\S)' pop: true instantiation-anon-class: - match: \{ scope: punctuation.section.braces.begin.java push: - meta_scope: meta.class.anonymous-inner-class.java - match: \} scope: punctuation.section.braces.end.java pop: true - include: class-body - match: (?=\S) pop: true functions: - match: '\b{{id}}(?=(\s*{{within_generics}})?\s*\()' scope: variable.function.java push: function-generics function-generics: - match: '<' scope: punctuation.definition.generic.begin.java push: - meta_scope: meta.generic.java - match: '>' scope: punctuation.definition.generic.end.java pop: true - include: generic-instantiation - match: '(?=\S)' pop: true fields: - match: '{{primitives}}(?=(\s*\[\s*\])?\s+{{id}})' scope: storage.type.primitive.java push: field-definition-arrays - match: '\b{{qualified_id}}(?=(\s*{{within_generics}})?(\s*\[\s*\])?\s+{{id}})' scope: support.class.java push: field-definition-generics field-definition-generics: - match: '<' scope: punctuation.definition.generic.begin.java set: - meta_scope: meta.generic.java - match: '>' scope: punctuation.definition.generic.end.java set: field-definition-arrays - include: generic-instantiation - match: '(?=\S)' set: field-definition-arrays field-definition-arrays: - match: \[ scope: punctuation.section.brackets.begin.java set: - match: \] scope: punctuation.section.brackets.end.java set: field-definition-name - match: '(?=\S)' set: field-definition-name field-definition-name: - match: '{{id}}' pop: true generic-instantiation: - match: '{{primitives}}' scope: invalid.illegal.primitive-instantiation.java - match: \? scope: keyword.operator.wildcard.java - match: \b(extends|super)\b scope: keyword.declaration.extends.java - match: '{{qualified_id}}' scope: support.type.java - match: '<' scope: punctuation.definition.generic.begin.java push: - match: '>' scope: punctuation.definition.generic.end.java pop: true - include: generic-instantiation assertions: - match: \b(assert)\b scope: keyword.control.assert.java push: - meta_scope: meta.declaration.assertion.java - match: $ pop: true - match: ":" scope: keyword.operator.assert.expression-separator.java - include: code class: - match: '(?=\w?[\w\s]*(?:class|(?:@)?interface|enum)(\s+\w+|\b))' push: class-declaration class-declaration: - meta_content_scope: meta.class.java - include: storage-modifiers - match: (\bclass|(?:@)?\binterface|\benum)(?:\s+|\b) captures: 1: storage.type.java set: - match: '\w+' scope: meta.class.identifier.java entity.name.class.java set: class-declaration - match: '' set: class-declaration - match: '<' scope: punctuation.definition.generic.begin.java push: - meta_scope: meta.generic.java - match: '>' scope: punctuation.definition.generic.end.java pop: true - include: generic-instantiation - match: (?=\bextends\b) set: - match: \bextends\b scope: keyword.declaration.extends.java set: - meta_scope: meta.class.extends.java - match: '(?=\s*{|\s*\bimplements\b)' set: class-declaration - include: object-types-inherited - match: (?=\bimplements\b) set: - match: \bimplements\b scope: keyword.declaration.implements.java set: - meta_scope: meta.class.implements.java - match: '(?=\s*\bextends\b|\s*\{)' set: class-declaration - include: object-types-inherited - match: '(?=\{)' set: - meta_scope: meta.class.body.java - match: '\}' scope: punctuation.section.class.end.java pop: true - match: '\{' scope: punctuation.section.class.begin.java push: - match: "(?=})" pop: true - include: class-body class-body: - include: class - include: enums - include: methods - include: annotations - include: storage-modifiers - include: code code: - include: class - match: "{" push: - match: "}" pop: true - match: "(?=%>)" pop: true - include: code - include: assertions - include: lambdas - include: parens - include: constants-and-special-vars - include: anonymous-classes-and-new - include: keywords - include: storage-modifiers - include: fields - include: functions - include: strings - include: all-types comments: - match: /\*\*/ scope: comment.block.empty.java punctuation.definition.comment.java - include: scope:text.html.javadoc - include: comments-inline comments-inline: - match: /\* scope: punctuation.definition.comment.java push: - meta_scope: comment.block.java - match: \*/ scope: punctuation.definition.comment.java pop: true - match: // scope: punctuation.definition.comment.java push: - meta_scope: comment.line.double-slash.java - match: $\n? pop: true - match: '(?=%>)' pop: true constants-and-special-vars: - match: \b(true|false|null)\b scope: constant.language.java - match: \b(this|super)\b scope: variable.language.java - match: '\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)([LlFfUuDd]|UL|ul)?\b' scope: constant.numeric.java - match: '(\.)?\b([A-Z][A-Z0-9_]+)(?!<|\.class|\s*\w+\s*=)\b' captures: 1: punctuation.accessor.dot.java 2: constant.other.java enums: - match: '^(?=\s*[A-Z0-9_]+\s*({|\(|,))' push: - match: "(?=;|})" pop: true - match: \w+ scope: constant.other.enum.java push: - meta_scope: meta.enum.java - match: "(?=,|;|})" pop: true - include: parens - match: "{" push: - match: "}" pop: true - include: class-body keywords: - match: '::' scope: punctuation.accessor.double-colon.java push: - match: '{{id}}' scope: variable.function.reference.java pop: true - match: (?=\S) pop: true - match: \b(goto|const)\b scope: invalid.illegal.java - match: \b(try|catch|finally|throw)\b scope: keyword.control.catch-exception.java - match: '\?|:' scope: keyword.control.java - match: \b(return|break|case|continue|default|do|while|for|switch|if|else)\b scope: keyword.control.java - match: \b(instanceof)\b scope: keyword.operator.java - match: (==|!=|<=|>=|<>|<|>) scope: keyword.operator.comparison.java - match: (=) scope: keyword.operator.assignment.java push: - meta_scope: meta.assignment.rhs.java - match: (?=(;|\))) pop: true - include: code - match: (\-\-|\+\+) scope: keyword.operator.increment-decrement.java - match: (\-|\+|\*|\/|%) scope: keyword.operator.arithmetic.java - match: (!|&&|\|\|) scope: keyword.operator.logical.java - match: (\.)(class\b)? captures: 1: punctuation.accessor.dot.java 2: support.variable.magic.java - match: ; scope: punctuation.terminator.java methods: - match: '(?=\w.*\s+)(?=[^=;]+\()' push: method-declaration - match: '(?={{within_generics}}\s+\w.*\s+)(?=[^=;]+\()' push: method-declaration method-declaration: - meta_scope: meta.method.java - match: "}|(?=;)" pop: true - include: storage-modifiers - match: '(?=\w+\s*\()' set: - match: (\w+)\s*(\() captures: 1: meta.method.identifier.java entity.name.function.java 2: meta.method.parameters.java punctuation.section.parens.begin.java push: - meta_content_scope: meta.method.parameters.java - include: method-parameters - match: '' set: method-declaration - match: '<' scope: punctuation.definition.generic.begin.java push: - meta_scope: meta.generic.java - match: '>' scope: punctuation.definition.generic.end.java pop: true - include: generic-instantiation - match: (?=\w.*\s+\w+\s*\() set: - meta_scope: meta.method.return-type.java - match: (?=\s*\w+\s*\() set: method-declaration - include: all-types - match: (?=\bthrows\b) set: throws - match: "{" push: - meta_scope: meta.method.body.java - match: "(?=})" pop: true - include: code - match: (?=\S) pop: true object-types-inherited: - match: '\b{{qualified_id}}\b(?=\s*<)' scope: entity.other.inherited-class.java push: - match: '<' scope: punctuation.definition.generic.begin.java set: - meta_scope: meta.generic.java - match: '>' scope: punctuation.definition.generic.end.java pop: true - include: generic-instantiation - match: '\b{{qualified_id}}\b' scope: entity.other.inherited-class.java method-parameters: - match: \bfinal\b scope: storage.modifier.java - match: '{{primitives}}' scope: storage.type.primitive.java set: method-parameter-after - match: '{{qualified_id}}' scope: support.class.java set: method-parameter-after - match: ',' scope: punctuation.separator.java - match: \) scope: meta.method.parameters.java punctuation.section.parens.end.java pop: true method-parameter-after: - meta_content_scope: meta.method.parameters.java - match: '<' scope: punctuation.definition.generic.begin.java push: - meta_scope: meta.generic.java - match: '>' scope: punctuation.definition.generic.end.java pop: true - include: generic-instantiation - match: '\.\.\.' scope: keyword.operator.varargs.java - match: '(\[)\s*(\])' captures: 1: punctuation.section.brackets.begin.java 2: punctuation.section.brackets.end.java - match: '{{id}}' scope: variable.parameter.java set: method-parameters - match: (?=\S) pop: true throws: - meta_scope: meta.method.throws.java - match: \bthrows\b scope: storage.modifier.java - match: (?=\s*\{|\s*;) set: method-declaration - match: '{{qualified_id}}' scope: support.class.java push: - match: '<' scope: punctuation.definition.generic.begin.java set: - meta_scope: meta.generic.java - match: '>' scope: punctuation.definition.generic.end.java pop: true - include: generic-instantiation - match: (?=\S) pop: true # duplicated due to the meta scope raw-parameters: - match: \bfinal\b scope: storage.modifier.java - match: '{{primitives}}' scope: storage.type.primitive.java set: raw-parameter-after - match: '{{qualified_id}}' scope: support.class.java set: raw-parameter-after - match: ',' scope: punctuation.separator.java - match: '(?=\))' pop: true raw-parameter-after: - match: '<' scope: punctuation.definition.generic.begin.java push: - meta_scope: meta.generic.java - match: '>' scope: punctuation.definition.generic.end.java pop: true - include: generic-instantiation - match: '\.\.\.' scope: keyword.operator.varargs.java - match: '(\[)\s*(\])' captures: 1: punctuation.section.brackets.begin.java 2: punctuation.section.brackets.end.java - match: '{{id}}' scope: variable.parameter.java set: raw-parameters - match: (?=\S) pop: true lambdas: - match: '(?={{lambda_lookahead}})' push: lambda-params lambda-params: - meta_scope: meta.lambda.parameters.java - match: \( scope: punctuation.section.parens.begin.java set: - meta_scope: meta.lambda.parameters.paren.java - match: \) scope: punctuation.section.parens.end.java set: lambda-arrow - match: (?=(\s*{{id}}\s*,)*\s*{{id}}\s*\)) push: lambda-params-simple - match: (?=\S) push: raw-parameters - match: '{{id}}' scope: variable.parameter.java set: lambda-arrow lambda-params-simple: - match: '{{id}}' scope: variable.parameter.java - match: ',' scope: punctuation.separator.java - match: (?=\S) pop: true lambda-arrow: - match: -> scope: storage.type.lambda.java set: - meta_scope: meta.lambda.body.java - match: (?=[)};]) pop: true - include: code parens: - match: \( push: - match: \) pop: true - include: code primitive-arrays: - match: '\b(?:void|boolean|byte|char|short|int|float|long|double)(\[\])*\b' scope: storage.type.primitive.array.java primitive-types: - match: '{{primitives}}' scope: storage.type.primitive.java storage-modifiers: - match: \b(public|private|protected|static|final|native|synchronized|strictfp|abstract|threadsafe|transient|default|volatile)\b scope: storage.modifier.java strings: - match: '"' scope: punctuation.definition.string.begin.java push: - meta_include_prototype: false - meta_scope: string.quoted.double.java - match: '"' scope: punctuation.definition.string.end.java pop: true - match: \\. scope: constant.character.escape.java - match: "'" scope: punctuation.definition.string.begin.java push: - meta_include_prototype: false - meta_scope: string.quoted.single.java - match: "'" scope: punctuation.definition.string.end.java pop: true - match: \\. scope: constant.character.escape.java values: - include: strings - include: constants-and-special-vars