|
| 1 | +# source: https://github.com/sharkdp/bat/blob/v0.25.0/assets/syntaxes/02_Extra/Manpage.sublime-syntax |
| 2 | +# Copyright (c) 2018-2023 bat-developers (https://github.com/sharkdp/bat). |
| 3 | + |
| 4 | +%YAML 1.2 |
| 5 | +--- |
| 6 | +# http://www.sublimetext.com/docs/3/syntax.html |
| 7 | +name: Manpage |
| 8 | +file_extensions: |
| 9 | + - man |
| 10 | +scope: source.man |
| 11 | + |
| 12 | +variables: |
| 13 | + section_heading: '^(?!#)\S.*$' |
| 14 | + command_line_option: '(--?[A-Za-z0-9][_A-Za-z0-9-]*)' |
| 15 | + |
| 16 | +contexts: |
| 17 | + prototype: |
| 18 | + # ignore syntax test lines |
| 19 | + - match: '^#' |
| 20 | + push: |
| 21 | + - meta_scope: comment.syntax-test.man |
| 22 | + - match: $\n? |
| 23 | + pop: true |
| 24 | + main: |
| 25 | + - match: ^ |
| 26 | + push: first_line |
| 27 | + |
| 28 | + first_line: |
| 29 | + - match: '([A-Z0-9_\-]+)(\()([^)]+)(\))\s*' |
| 30 | + captures: |
| 31 | + 1: meta.preprocessor.man |
| 32 | + 2: keyword.operator.man |
| 33 | + 3: string.quoted.other.man |
| 34 | + 4: keyword.operator.man |
| 35 | + push: |
| 36 | + - match: (?:[\w'-]+|\s(?!\s)) |
| 37 | + scope: markup.heading.title.man |
| 38 | + - match: \s\s |
| 39 | + pop: true |
| 40 | + - match: '(?=\S|$)' |
| 41 | + pop: true |
| 42 | + |
| 43 | + - match: '$' |
| 44 | + set: body |
| 45 | + |
| 46 | + body: |
| 47 | + # English, ..., ..., ..., Russian, ... |
| 48 | + |
| 49 | + - match: '^(?:SYNOPSIS|SYNTAX|SINTASSI|SKŁADNIA|СИНТАКСИС|書式)' |
| 50 | + scope: markup.heading.synopsis.man |
| 51 | + embed: synopsis |
| 52 | + escape: '(?={{section_heading}})' |
| 53 | + |
| 54 | + - match: '^(?:USAGE)' |
| 55 | + scope: markup.heading.synopsis.man |
| 56 | + embed: synopsis |
| 57 | + escape: '(?={{section_heading}})' |
| 58 | + |
| 59 | + - match: '^(?:COMMANDS)\b' |
| 60 | + scope: markup.heading.commands.man |
| 61 | + embed: commands-start |
| 62 | + escape: '(?={{section_heading}})' |
| 63 | + |
| 64 | + - match: '^(?:ENVIRONMENT\s+VARIABLES)' |
| 65 | + scope: markup.heading.env.man |
| 66 | + embed: environment-variables |
| 67 | + escape: '(?={{section_heading}})' |
| 68 | + |
| 69 | + - match: '{{section_heading}}' |
| 70 | + scope: markup.heading.other.man |
| 71 | + embed: options # some man pages put command line options under the description heading |
| 72 | + escape: '(?={{section_heading}})' |
| 73 | + |
| 74 | + function-call: |
| 75 | + - match: '\b([A-Za-z0-9_\-]+\.)?([A-Za-z0-9_\-]+)(\()([^)]*)(\))' |
| 76 | + captures: |
| 77 | + 1: entity.name.function.man |
| 78 | + 2: entity.name.function.man |
| 79 | + 3: keyword.operator.man |
| 80 | + 4: constant.numeric.man |
| 81 | + 5: keyword.operator.man |
| 82 | + |
| 83 | + env-var: |
| 84 | + - match: '(\$)(?!\d)(\w+)\b' |
| 85 | + captures: |
| 86 | + 1: punctuation.definition.variable.man |
| 87 | + 2: constant.other.man |
| 88 | + |
| 89 | + options: |
| 90 | + # command-line options like --option=value, --some-flag, or -x |
| 91 | + - match: '^[ ]{7}(-)(?=\s)' |
| 92 | + captures: |
| 93 | + 1: entity.name.command-line-option.man |
| 94 | + - match: '^[ ]{7}(?=-|\+)' |
| 95 | + push: expect-command-line-option |
| 96 | + - match: '(?:[^a-zA-Z0-9_-]|^|\s){{command_line_option}}' |
| 97 | + captures: |
| 98 | + 1: entity.name.command-line-option |
| 99 | + push: |
| 100 | + - match: '=' |
| 101 | + scope: keyword.operator.man |
| 102 | + set: |
| 103 | + - match: '[^],.() ]+' |
| 104 | + scope: variable.parameter.man |
| 105 | + pop: true |
| 106 | + - match: $ |
| 107 | + pop: true |
| 108 | + - match: '' |
| 109 | + pop: true |
| 110 | + - include: function-call |
| 111 | + - include: c-code |
| 112 | + - include: env-var |
| 113 | + |
| 114 | + expect-command-line-option: |
| 115 | + - match: '[A-Za-z0-9-\.\?:#\$\+]+' |
| 116 | + scope: entity.name.command-line-option.man |
| 117 | + - match: '(\[)(=)' |
| 118 | + captures: |
| 119 | + 1: punctuation.section.brackets.begin.man |
| 120 | + 2: keyword.operator.man |
| 121 | + push: [command-line-option-or-pipe, expect-parameter] |
| 122 | + - match: '\[' |
| 123 | + push: |
| 124 | + - meta_scope: entity.name.command-line-option.man |
| 125 | + - match: '\]' |
| 126 | + pop: true |
| 127 | + - match: '=' |
| 128 | + scope: keyword.operator.man |
| 129 | + push: expect-parameter |
| 130 | + - match: (?=.*\.) |
| 131 | + pop: true |
| 132 | + - match: '\s' |
| 133 | + push: expect-parameter |
| 134 | + - match: '(,)\s*' |
| 135 | + captures: |
| 136 | + 1: punctuation.separator.man |
| 137 | + - match: $|(?=\]) |
| 138 | + pop: true |
| 139 | + |
| 140 | + expect-parameter: |
| 141 | + - match: '[A-Za-z0-9-_]+' |
| 142 | + scope: variable.parameter.man |
| 143 | + - match: (?=\s+\|) |
| 144 | + pop: true |
| 145 | + - match: \| |
| 146 | + scope: keyword.operator.logical.man |
| 147 | + - match: '\[' |
| 148 | + scope: punctuation.section.brackets.begin.man |
| 149 | + push: |
| 150 | + - match: '\]' |
| 151 | + scope: punctuation.section.brackets.end.man |
| 152 | + pop: true |
| 153 | + - include: expect-parameter |
| 154 | + - match: '<' |
| 155 | + scope: punctuation.definition.generic.begin.man |
| 156 | + - match: '>' |
| 157 | + scope: punctuation.definition.generic.end.man |
| 158 | + - match: '$|(?=[],]|{{command_line_option}})' |
| 159 | + pop: true |
| 160 | + |
| 161 | + c-code: |
| 162 | + - match: '^(?=\s+(?:#include\b|#define\b|/\*|struct\s+(\w+\s*)?\{))' |
| 163 | + embed: scope:source.c |
| 164 | + #embed_scope: source.c.embedded.man |
| 165 | + #escape: ^(?!#|\1|\s*(?:$|/\*|#include\b|#define\b)) |
| 166 | + escape: ^(?=\s*(?:\(.*\.\)\s*$|[A-Z](?![A-Z]))) |
| 167 | + |
| 168 | + synopsis: |
| 169 | + - include: c-code |
| 170 | + - match: \[ |
| 171 | + scope: punctuation.section.brackets.begin.man |
| 172 | + push: command-line-option-or-pipe |
| 173 | + - include: options |
| 174 | + |
| 175 | + command-line-option-or-pipe: |
| 176 | + - match: (\|)\s* |
| 177 | + captures: |
| 178 | + 1: keyword.operator.logical.man |
| 179 | + #- match: (?={{command_line_option}}) |
| 180 | + - match: \w+-\w+ |
| 181 | + - match: (?=-) |
| 182 | + push: |
| 183 | + - match: (?=\s*\|) |
| 184 | + pop: true |
| 185 | + - include: expect-command-line-option |
| 186 | + - match: \] |
| 187 | + scope: punctuation.section.brackets.end.man |
| 188 | + pop: true |
| 189 | + - match: \[ |
| 190 | + scope: punctuation.section.brackets.begin.man |
| 191 | + push: command-line-option-or-pipe |
| 192 | + |
| 193 | + commands-start: |
| 194 | + - match: (?=^[ ]{7}.*(?:[ ]<|[|])) |
| 195 | + push: commands |
| 196 | + |
| 197 | + commands: |
| 198 | + - match: '^[ ]{7}([a-z_\-]+)(?=[ ]|$)' |
| 199 | + captures: |
| 200 | + 1: entity.name.command.man |
| 201 | + push: expect-parameter |
| 202 | + - match: '^[ ]{7}(?=[\[<]|\w+[|\]])' |
| 203 | + push: expect-parameter |
| 204 | + |
| 205 | + environment-variables: |
| 206 | + - match: '^[ ]{7}([A-Z_]+)\b' |
| 207 | + captures: |
| 208 | + 1: support.constant.environment-variable.man |
0 commit comments