Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/scdoc.py: 55%
22 statements
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-18 06:13 +0000
« prev ^ index » next coverage.py v7.3.1, created at 2023-09-18 06:13 +0000
1"""
2 pygments.lexers.scdoc
3 ~~~~~~~~~~~~~~~~~~~~~
5 Lexer for scdoc, a simple man page generator.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11import re
13from pygments.lexer import RegexLexer, include, bygroups, using, this
14from pygments.token import Text, Comment, Keyword, String, Generic
16__all__ = ['ScdocLexer']
19class ScdocLexer(RegexLexer):
20 """
21 `scdoc` is a simple man page generator for POSIX systems written in C99.
23 .. versionadded:: 2.5
24 """
25 name = 'scdoc'
26 url = 'https://git.sr.ht/~sircmpwn/scdoc'
27 aliases = ['scdoc', 'scd']
28 filenames = ['*.scd', '*.scdoc']
29 flags = re.MULTILINE
31 tokens = {
32 'root': [
33 # comment
34 (r'^(;.+\n)', bygroups(Comment)),
36 # heading with pound prefix
37 (r'^(#)([^#].+\n)', bygroups(Generic.Heading, Text)),
38 (r'^(#{2})(.+\n)', bygroups(Generic.Subheading, Text)),
39 # bulleted lists
40 (r'^(\s*)([*-])(\s)(.+\n)',
41 bygroups(Text, Keyword, Text, using(this, state='inline'))),
42 # numbered lists
43 (r'^(\s*)(\.+\.)( .+\n)',
44 bygroups(Text, Keyword, using(this, state='inline'))),
45 # quote
46 (r'^(\s*>\s)(.+\n)', bygroups(Keyword, Generic.Emph)),
47 # text block
48 (r'^(```\n)([\w\W]*?)(^```$)', bygroups(String, Text, String)),
50 include('inline'),
51 ],
52 'inline': [
53 # escape
54 (r'\\.', Text),
55 # underlines
56 (r'(\s)(_[^_]+_)(\W|\n)', bygroups(Text, Generic.Emph, Text)),
57 # bold
58 (r'(\s)(\*[^*]+\*)(\W|\n)', bygroups(Text, Generic.Strong, Text)),
59 # inline code
60 (r'`[^`]+`', String.Backtick),
62 # general text, must come last!
63 (r'[^\\\s]+', Text),
64 (r'.', Text),
65 ],
66 }
68 def analyse_text(text):
69 """We checks for bold and underline text with * and _. Also
70 every scdoc file must start with a strictly defined first line."""
71 result = 0
73 if '*' in text:
74 result += 0.01
76 if '_' in text:
77 result += 0.01
79 # name(section) ["left_footer" ["center_header"]]
80 first_line = text.partition('\n')[0]
81 scdoc_preamble_pattern = r'^.*\([1-7]\)( "[^"]+"){0,2}$'
83 if re.search(scdoc_preamble_pattern, first_line):
84 result += 0.5
86 return result