Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Manpage syntax #1315

Merged
merged 4 commits into from
Oct 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

## Syntaxes

- Manpage syntax highlighting has been improved, see #1315 (@keith-hall)

## New themes

## `bat` as a library
Expand Down
148 changes: 124 additions & 24 deletions assets/syntaxes/02_Extra/Manpage.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,147 @@ file_extensions:
scope: source.man

variables:
section_heading: '^\S.*$'
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_\-]+)(\()([^)]+)(\))'
- match: '([A-Z0-9_\-]+)(\()([^)]+)(\))\s*'
captures:
1: meta.preprocessor
2: keyword.operator
3: string.quoted.other
4: keyword.operator
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: '$'
push: body

body:
- match: '^(SYNOPSIS|SYNTAX|SINTASSI|SKŁADNIA|СИНТАКСИС|書式)'
push: Packages/C/C.sublime-syntax
scope: markup.heading
with_prototype:
- match: '(?={{section_heading}})'
pop: true
# English, ..., ..., ..., Russian, ...

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

- match: '^\S.*$'
scope: markup.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}})'

- include: function-call

function-call:
- match: '\b([A-Za-z0-9_\-]+)(\()([^)]*)(\))'
captures:
1: entity.name.function
2: keyword.operator
3: constant.numeric
4: keyword.operator
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: '(?:[^a-zA-Z0-9_-]|^|\s)(--?[A-Za-z0-9][A-Za-z0-9-]*)(?:(=)?("?)([A-Za-z0-9]+)("?))?'
- 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

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: entity.name
2: keyword.operator
3: punctuation.definition.string.begin
4: variable.parameter
3: punctuation.definition.string.end
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

synopsis:
- match: '^(?=\s+(?:#include|/\*))'
push: scope:source.c
- 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: (?=-)
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
125 changes: 125 additions & 0 deletions assets/syntaxes/02_Extra/syntax_test_man.man
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# SYNTAX TEST "Manpage.sublime-syntax"
SOMETHING(8) System Manager's Manual SOMETHING(8)
# ^^^^^ meta.preprocessor
# ^^^^^^^^^^^^^^^^^^^^^^^ markup.heading.title
# ^^^^^^^ meta.preprocessor

NAME
#^^^ markup.heading.title
example - do something useful

SYNOPSIS
example [options] [--home DIR] [--shell SHELL] [--no-create-home]
# ^ punctuation.section.brackets.begin
# ^^^^^^ entity.name.command-line-option
# ^^^ variable.parameter
# ^ punctuation.section.brackets.end
# ^ punctuation.section.brackets.begin
# ^^^^^^^ entity.name.command-line-option
# ^^^^^ variable.parameter
# ^ punctuation.section.brackets.end
# ^ punctuation.section.brackets.begin
# ^^^^^^^^^^^^^^^^ entity.name.command-line-option
# ^ punctuation.section.brackets.end
[-u | --set-upstream] [-o <string> | --push-option=<string>]
# ^ punctuation.section.brackets.begin
# ^^ entity.name.command-line-option
# ^ keyword.operator.logical
# ^^^^^^^^^^^^^^ entity.name.command-line-option
# ^ punctuation.section.brackets.end
# ^^^^^^^^^^^^^ entity.name.command-line-option
[--force-with-lease[=<refname>[:<expect>]]]
# ^ punctuation.section.brackets.begin
# ^^^^^^^^^^^^^^^^^^ entity.name.command-line-option
# ^ punctuation.section.brackets.begin
# ^ keyword.operator
# ^^^^^^^ variable.parameter
# ^ punctuation.section.brackets.begin
# ^^^^^^ variable.parameter
# ^^^ punctuation.section.brackets.end

example --system [options]
# ^^^^^^^^ entity.name

COMMON OPTIONS
[--quiet] [--debug] [--help|-h] [--version] [--conf FILE]

/* According to POSIX.1-2001, POSIX.1-2008 */
# ^^ source comment.block punctuation.definition.comment
#include <sys/select.h>
# ^^^^^^^^ source meta.preprocessor.include keyword.control.import.include


DESCRIPTION
example does something useful in relation to the command line options
and configuration information in /etc/example.conf.

OPTIONS
--conf FILE
# ^^^^^^ entity.name.command-line-option
#^^^^^^ - variable - entity - markup
# ^^^^ variable.parameter
Use FILE instead of /etc/example.conf.
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - variable - entity

--disabled-login
Do not run passwd to set the password. The user won't be able
to use her account until the password is set.

--disabled-password
Like --disabled-login, but logins are still possible (for exam-
# ^^^^^^^^^^^^^^^^ entity.name
#^^^^^^^^^^^^^^^^^^ - entity - variable - markup
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - entity - variable - markup
ple using SSH RSA keys) but not using password authentication.

--help Display brief instructions.
# ^^^^^^ entity.name.command-line-option
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - variable.parameter

--home DIR
# ^^^^^^ entity.name.command-line-option
# ^^^ variable.parameter
# ^ - variable - entity - markup
Use DIR as the user's home directory, rather than the default
specified by the configuration file. If the directory does not
exist, it is created and skeleton files are copied.

--[no-]signed, --signed=(true|false|if-asked)
# ^^^^^^^^^^^^^ entity.name.command-line-option
# ^ punctuation.separator
# ^^^^^^^^ entity.name.command-line-option
# ^ keyword.operator
# ^ - variable
# ^^^^ variable.parameter
# ^ keyword.operator.logical
# ^^^^^ variable.parameter
# ^ keyword.operator.logical
# ^^^^^^^^ variable.parameter
# ^ - variable
--no-recurse-submodules, --recurse-submodules=check|on-demand|only|no
# ^^^^^^^^^^^^^^^^^^^^^^^ entity.name.command-line-option
# ^ punctuation.separator
# ^^^^^^^^^^^^^^^^^^^^ entity.name.command-line-option
# ^ keyword.operator
# ^^^^^ variable.parameter
# ^ keyword.operator.logical
# ^^^^^^^^^ variable.parameter
# ^ keyword.operator.logical
# ^^^^ variable.parameter
# ^ keyword.operator.logical
# ^^ variable.parameter
May be used to make sure all submodule commits used by the

-c, -C NUM, --context[=NUM]
# ^^ entity.name.command-line-option
# ^ punctuation.separator
# ^^ entity.name.command-line-option
# ^^^ variable.parameter
# ^ punctuation.separator
# ^^^^^^^^^ entity.name.command-line-option
# ^^^^^^^ - entity.name
# ^ keyword.operator
# ^^^ variable.parameter
# ^^ - variable
output NUM (default 3) lines of copied context
Loading