summaryrefslogtreecommitdiffstats
path: root/assets/syntaxes/02_Extra/Manpage.sublime-syntax
blob: d92eea227c8c65dd9edc74df9526476060fe1dcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: Manpage
file_extensions:
  - man
scope: source.man

variables:
  section_heading: '^(?!#)\S.*$'
  command_line_option: '(--?[A-Za-z0-9][_A-Za-z0-9-]*)'

contexts:
  prototype:
    # ignore syntax test lines
    - match: '^#'
      push:
        - meta_scope: comment.syntax-test.man
        - match: $\n?
          pop: true
  main:
    - match: ^
      push: first_line

  first_line:
    - match: '([A-Z0-9_\-]+)(\()([^)]+)(\))\s*'
      captures:
        1: meta.preprocessor.man
        2: keyword.operator.man
        3: string.quoted.other.man
        4: keyword.operator.man
      push:
        - match: (?:[\w'-]+|\s(?!\s))
          scope: markup.heading.title.man
        - match: \s\s
          pop: true
        - match: '(?=\S|$)'
          pop: true

    - match: '$'
      set: body

  body:
    # English, ..., ..., ..., Russian, ...

    - match: '^(?:SYNOPSIS|SYNTAX|SINTASSI|SKŁADNIA|СИНТАКСИС|書式)'
      scope: markup.heading.synopsis.man
      embed: synopsis
      escape: '(?={{section_heading}})'

    - match: '^(?:USAGE)'
      scope: markup.heading.synopsis.man
      embed: synopsis
      escape: '(?={{section_heading}})'

    - match: '{{section_heading}}'
      scope: markup.heading.other.man
      embed: options # some man pages put command line options under the description heading
      escape: '(?={{section_heading}})'

  function-call:
    - match: '\b([A-Za-z0-9_\-]+)(\()([^)]*)(\))'
      captures:
        1: entity.name.function.man
        2: keyword.operator.man
        3: constant.numeric.man
        4: keyword.operator.man

  options:
    # command-line options like --option=value, --some-flag, or -x
    - match: '^[ ]{7}(?=-)'
      push: expect-command-line-option
    - match: '(?:[^a-zA-Z0-9_-]|^|\s){{command_line_option}}'
      captures:
        1: entity.name.command-line-option
      push:
        - match: '='
          scope: keyword.operator.man
          set:
            - match: '[^],.() ]+'
              scope: variable.parameter.man
              pop: true
            - match: $
              pop: true
        - match: ''
          pop: true
    - include: function-call
    - include: c-code

  expect-command-line-option:
    - match: '[A-Za-z0-9-]+'
      scope: entity.name.command-line-option.man
    - match: '(\[)(=)'
      captures:
        1: punctuation.section.brackets.begin.man
        2: keyword.operator.man
      push: [command-line-option-or-pipe, expect-parameter]
    - match: '\['
      push:
        - meta_scope: entity.name.command-line-option.man
        - match: '\]'
          pop: true
    - match: '='
      scope: keyword.operator.man
      push: expect-parameter
    - match: (?=.*\.)
      pop: true
    - match: '\s'
      push: expect-parameter
    - match: '(,)\s*'
      captures:
        1: punctuation.separator.man
    - match: $|(?=\])
      pop: true

  expect-parameter:
    - match: '[A-Za-z0-9-]+'
      scope: variable.parameter.man
    - match: (?=\s+\|)
      pop: true
    - match: \|
      scope: keyword.operator.logical.man
    - match: '\['
      scope: punctuation.section.brackets.begin.man
      push:
        - match: '\]'
          scope: punctuation.section.brackets.end.man
          pop: true
        - include: expect-parameter
    - match: '$|(?=[],]|{{command_line_option}})'
      pop: true

  c-code:
    - match: '^(?=\s+(?:#include\b|#define\b|/\*|struct\s+(\w+\s*)?\{))'
      embed: scope:source.c
      #embed_scope: source.c.embedded.man
      #escape: ^(?!#|\1|\s*(?:$|/\*|#include\b|#define\b))
      escape: ^(?=\s*(?:\(.*\.\)\s*$|[A-Z](?![A-Z])))

  synopsis:
    - include: c-code
    - match: \[
      scope: punctuation.section.brackets.begin.man
      push: command-line-option-or-pipe
    - include: options

  command-line-option-or-pipe:
    - match: (\|)\s*
      captures:
        1: keyword.operator.logical.man
    #- match: (?={{command_line_option}})
    - match: \w+-\w+
    - match: (?=-)
      push:
        - match: (?=\s*\|)
          pop: true
        - include: expect-command-line-option
    - match: \]
      scope: punctuation.section.brackets.end.man
      pop: true
    - match: \[
      scope: punctuation.section.brackets.begin.man
      push: command-line-option-or-pipe