%YAML 1.2 --- # http://www.sublimetext.com/docs/3/syntax.html name: R file_extensions: - R - r - Rprofile scope: source.r variables: exponent: (?:[eE][-+]?\d+) var: '(?:[a-zA-Z._][a-zA-Z0-9._]*|`[^`]+`)' contexts: main: - include: roxygen - include: codesection - include: comments - include: constants - include: accessor - include: operators - include: keywords - include: storage-types - include: strings - include: brackets - include: function-declarations - include: lambda-functions - include: builtin-functions - include: function-calls - include: general-variables codesection: - match: ^\s*((\#+)\s*(.+?)\s*(?:-{4,}|={4,}|#{4,})[ \t]*$\n?) captures: 1: comment.line.number-sign.r 2: punctuation.definition.comment.r 3: entity.name.section.r comments: - match: \#+ scope: punctuation.definition.comment.r push: - meta_scope: comment.line.number-sign.r - match: \n pop: true constants: - match: \b(pi|letters|LETTERS|month\.abb|month\.name)\b scope: support.constant.misc.r - match: \b(TRUE|FALSE|NULL|NA|NA_integer_|NA_real_|NA_complex_|NA_character_|Inf|NaN)\b scope: constant.language.r # complex imaginary - match: \b(0[xX])\h+(?:(i)|(I))\b scope: constant.numeric.imaginary.hexadecimal.r captures: 1: punctuation.definition.numeric.hexadecimal.r 2: storage.type.numeric.r 3: invalid.illegal.numeric.r - match: (?:(\.)\d+|\b\d+(\.)?\d*){{exponent}}?(?:(i)|(I))\b scope: constant.numeric.imaginary.decimal.r captures: 1: punctuation.separator.decimal.r 2: punctuation.separator.decimal.r 3: storage.type.numeric.r 4: invalid.illegal.numeric.r # integers - match: \b(0[xX])\h+(?:(L)|(l))\b scope: constant.numeric.integer.hexadecimal.r captures: 1: punctuation.definition.numeric.hexadecimal.r 2: storage.type.numeric.r 3: invalid.illegal.numeric.r - match: \b\d+(\.)?\d*(?:(L)|(l))\b scope: constant.numeric.integer.decimal.r captures: 1: punctuation.separator.decimal.r 2: storage.type.numeric.r 3: invalid.illegal.numeric.r # floats - match: \b(0[xX])\h+\b scope: constant.numeric.float.hexadecimal.r captures: 1: punctuation.definition.numeric.hexadecimal.r - match: |- (?x: # 1., 1.1, 1.1e1, 1.1e-1, 1.e1, 1.e-1 | 1, 1e1, 1e-1 \b\d+ (?: (\.) (?: \d* {{exponent}}? \b )? | {{exponent}}? \b ) # .1, .1e1, .1e-1 | (\.) \d+ {{exponent}}? \b ) scope: constant.numeric.float.decimal.r captures: 1: punctuation.separator.decimal.r 2: punctuation.separator.decimal.r general-variables: - match: '{{var}}' keywords: - match: \bif\b(?=\s*\() scope: keyword.control.conditional.if.r - match: \belse\b scope: keyword.control.conditional.else.r - match: \bbreak\b scope: keyword.control.flow.break.r - match: \bnext\b scope: keyword.control.flow.continue.r - match: \breturn(?=\s*\() scope: keyword.control.flow.return.r - match: \brepeat\b scope: keyword.control.loop.repeat.r - match: \bfor\b(?=\s*\() scope: keyword.control.loop.for.r - match: \bwhile\b(?=\s*\() scope: keyword.control.loop.while.r - match: \bin\b scope: keyword.operator.word.r accessor: - match: '\$' scope: keyword.accessor.dollar.r push: - include: function-calls - include: general-variables - match: '' pop: true operators: # NOTE: sorted by length to ensure not to break ligatures # operators with 3+ characters - match: '%[*/ox]%' scope: keyword.operator.arithmetic.r - match: (<<-|->>) scope: keyword.operator.assignment.r - match: '%(between|chin|do|dopar|in|like|\+replace|\+|:|T>|<>|>|\$)%' scope: keyword.operator.other.r - match: \.\.\. scope: keyword.other.r - match: :::? scope: punctuation.accessor.colons.r # operators with 2 characters - match: (%%|\*\*) scope: keyword.operator.arithmetic.r - match: (<-|->) scope: keyword.operator.assignment.r - match: (==|!=|<=|>=|<>|&&|\|\|) scope: keyword.operator.logical.r - match: := scope: keyword.operator.other.r # operators with 1 characters - match: '[-+*/^]' scope: keyword.operator.arithmetic.r - match: = scope: keyword.operator.assignment.r - match: '[!&|<>]' scope: keyword.operator.logical.r - match: '[:~@]' scope: keyword.other.r - match: ; scope: punctuation.terminator.semicolon.r storage-types: - match: \b(character|complex|double|expression|integer|list|logical|numeric|single|raw)\s*(?=\() scope: meta.function-call.name.r captures: 1: storage.type.r push: function-call-arguments strings: - match: '"' scope: punctuation.definition.string.begin.r push: - meta_scope: string.quoted.double.r - match: \\. scope: constant.character.escape.r - match: '"' scope: punctuation.definition.string.end.r pop: true - match: "'" scope: punctuation.definition.string.begin.r push: - meta_scope: string.quoted.single.r - match: \\. scope: constant.character.escape.r - match: "'" scope: punctuation.definition.string.end.r pop: true brackets: - match: \( scope: punctuation.section.parens.begin.r push: - match: \) scope: punctuation.section.parens.end.r pop: true - include: main - match: \[(?!\[) scope: meta.item-access.r punctuation.section.brackets.single.begin.r push: - meta_content_scope: meta.item-access.r meta.item-access.arguments.r - match: \] scope: meta.item-access.r punctuation.section.brackets.single.end.r pop: true - match: ',' scope: punctuation.separator.parameters.r - include: main - match: \[\[ scope: meta.item-access.r punctuation.section.brackets.double.begin.r push: - meta_content_scope: meta.item-access.r meta.item-access.arguments.r - match: \]\] scope: meta.item-access.r punctuation.section.brackets.double.end.r pop: true - match: ',' scope: punctuation.separator.parameters.r - include: main - match: \{ scope: punctuation.section.braces.begin.r push: - match: \} scope: punctuation.section.braces.end.r pop: true - include: main function-declarations: - match: (({{var}})\s*)((<