Skip to content

Commit 8215091

Browse files
authored
feat: add scdoc support (#1199)
the scdoc format is markdown-line manpage format. ref: https://git.sr.ht/~sircmpwn/scdoc Signed-off-by: oppiliappan <me@oppi.li>
1 parent 3fce7ab commit 8215091

3 files changed

Lines changed: 262 additions & 0 deletions

File tree

‎lexers/embedded/scdoc.xml‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<lexer>
2+
<config>
3+
<name>scdoc</name>
4+
<alias>scdoc</alias>
5+
<filename>*.scd</filename>
6+
<filename>*.scdoc</filename>
7+
</config>
8+
<rules>
9+
<state name="root">
10+
<rule pattern="(?m)^; .*$">
11+
<token type="Comment"/>
12+
</rule>
13+
<rule pattern="(?m)^([A-Z][A-Z0-9_-]*)(\()([0-9]+)(\))(.*)$">
14+
<bygroups>
15+
<token type="NameFunction"/>
16+
<token type="Punctuation"/>
17+
<token type="LiteralNumber"/>
18+
<token type="Punctuation"/>
19+
<token type="Text"/>
20+
</bygroups>
21+
</rule>
22+
<rule pattern="(?m)^(##)( +)(.+)$">
23+
<bygroups>
24+
<token type="GenericSubheading"/>
25+
<token type="Text"/>
26+
<token type="Text"/>
27+
</bygroups>
28+
</rule>
29+
<rule pattern="(?m)^(#)( +)(.+)$">
30+
<bygroups>
31+
<token type="GenericHeading"/>
32+
<token type="Text"/>
33+
<token type="GenericStrong"/>
34+
</bygroups>
35+
</rule>
36+
<rule pattern="(?m)^```$">
37+
<token type="LiteralStringBacktick"/>
38+
<push state="literal_block"/>
39+
</rule>
40+
<rule pattern="(?m)^(\s*)(- )(.*)$">
41+
<bygroups>
42+
<token type="Text"/>
43+
<token type="Keyword"/>
44+
<usingself state="inline"/>
45+
</bygroups>
46+
</rule>
47+
<rule pattern="(?m)^(\s*)(\. )(.*)$">
48+
<bygroups>
49+
<token type="Text"/>
50+
<token type="Keyword"/>
51+
<usingself state="inline"/>
52+
</bygroups>
53+
</rule>
54+
<rule pattern="(?m)^\t[^ \t].*$">
55+
<token type="LiteralStringBacktick"/>
56+
</rule>
57+
<rule pattern="(?m)^\t+$">
58+
<token type="LiteralStringBacktick"/>
59+
</rule>
60+
<rule pattern="(?m)^(\s*)([|:\[\]].*)$">
61+
<bygroups>
62+
<token type="Text"/>
63+
<token type="Punctuation"/>
64+
</bygroups>
65+
</rule>
66+
<rule pattern="(?m)^(.*)(\+\+)$">
67+
<bygroups>
68+
<usingself state="inline"/>
69+
<token type="Operator"/>
70+
</bygroups>
71+
</rule>
72+
<rule>
73+
<include state="inline"/>
74+
</rule>
75+
</state>
76+
<state name="literal_block">
77+
<rule pattern="(?m)^```$">
78+
<token type="LiteralStringBacktick"/>
79+
<pop depth="1"/>
80+
</rule>
81+
<rule pattern=".*\n?">
82+
<token type="LiteralStringBacktick"/>
83+
</rule>
84+
</state>
85+
<state name="inline">
86+
<rule pattern="\\.">
87+
<token type="LiteralStringEscape"/>
88+
</rule>
89+
<rule pattern="(\*)([^*\n]+)(\*)">
90+
<bygroups>
91+
<token type="Punctuation"/>
92+
<token type="GenericStrong"/>
93+
<token type="Punctuation"/>
94+
</bygroups>
95+
</rule>
96+
<rule pattern="(_)([^_\n]+?)(_)((?=\W|\n|$))">
97+
<bygroups>
98+
<token type="Punctuation"/>
99+
<token type="GenericUnderline"/>
100+
<token type="Punctuation"/>
101+
<token type="Text"/>
102+
</bygroups>
103+
</rule>
104+
<rule pattern="[^*_\\\n]+">
105+
<token type="Text"/>
106+
</rule>
107+
<rule pattern="\n">
108+
<token type="Text"/>
109+
</rule>
110+
<rule pattern=".">
111+
<token type="Text"/>
112+
</rule>
113+
</state>
114+
</rules>
115+
</lexer>

‎lexers/testdata/scdoc.actual‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
; Comment at the top
2+
MYPROGRAM(1) "User Manual"
3+
4+
# NAME
5+
6+
myprogram - does something useful
7+
8+
## SYNOPSIS
9+
10+
*myprogram* [_options_] _file_
11+
12+
# DESCRIPTION
13+
14+
This has *bold text* and _underlined text_.
15+
16+
Note that in_the_middle_of underscores are ignored.
17+
18+
Line breaks work++
19+
like this.
20+
21+
## OPTIONS
22+
23+
- *-h*, *--help*
24+
Show help
25+
- Nested item with tab
26+
- Deeply nested
27+
28+
. First item
29+
. Second item
30+
. Nested numbered item with continuation
31+
that spans multiple lines
32+
33+
# EXAMPLES
34+
35+
Literal block:
36+
37+
```
38+
code example
39+
```
40+
41+
Tab-indented:
42+
43+
literal text
44+
45+
# TABLE
46+
47+
| Row 1
48+
: Cell 1
49+
:- Cell 2
50+
51+
# ESCAPES
52+
53+
This is \*not bold\* and \_not underlined\_.

‎lexers/testdata/scdoc.expected‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[
2+
{"type":"Comment","value":"; Comment at the top"},
3+
{"type":"Text","value":"\n"},
4+
{"type":"NameFunction","value":"MYPROGRAM"},
5+
{"type":"Punctuation","value":"("},
6+
{"type":"LiteralNumber","value":"1"},
7+
{"type":"Punctuation","value":")"},
8+
{"type":"Text","value":" \"User Manual\"\n\n"},
9+
{"type":"GenericHeading","value":"#"},
10+
{"type":"Text","value":" "},
11+
{"type":"GenericStrong","value":"NAME"},
12+
{"type":"Text","value":"\n\nmyprogram - does something useful\n\n"},
13+
{"type":"GenericSubheading","value":"##"},
14+
{"type":"Text","value":" SYNOPSIS\n\n"},
15+
{"type":"Punctuation","value":"*"},
16+
{"type":"GenericStrong","value":"myprogram"},
17+
{"type":"Punctuation","value":"*"},
18+
{"type":"Text","value":" ["},
19+
{"type":"Punctuation","value":"_"},
20+
{"type":"GenericUnderline","value":"options"},
21+
{"type":"Punctuation","value":"_"},
22+
{"type":"Text","value":"] "},
23+
{"type":"Punctuation","value":"_"},
24+
{"type":"GenericUnderline","value":"file"},
25+
{"type":"Punctuation","value":"_"},
26+
{"type":"Text","value":"\n\n"},
27+
{"type":"GenericHeading","value":"#"},
28+
{"type":"Text","value":" "},
29+
{"type":"GenericStrong","value":"DESCRIPTION"},
30+
{"type":"Text","value":"\n\nThis has "},
31+
{"type":"Punctuation","value":"*"},
32+
{"type":"GenericStrong","value":"bold text"},
33+
{"type":"Punctuation","value":"*"},
34+
{"type":"Text","value":" and "},
35+
{"type":"Punctuation","value":"_"},
36+
{"type":"GenericUnderline","value":"underlined text"},
37+
{"type":"Punctuation","value":"_"},
38+
{"type":"Text","value":".\n\nNote that in_the_middle_of underscores are ignored.\n\nLine breaks work"},
39+
{"type":"Operator","value":"++"},
40+
{"type":"Text","value":"\nlike this.\n\n"},
41+
{"type":"GenericSubheading","value":"##"},
42+
{"type":"Text","value":" OPTIONS\n\n"},
43+
{"type":"Keyword","value":"- "},
44+
{"type":"Punctuation","value":"*"},
45+
{"type":"GenericStrong","value":"-h"},
46+
{"type":"Punctuation","value":"*"},
47+
{"type":"Text","value":", "},
48+
{"type":"Punctuation","value":"*"},
49+
{"type":"GenericStrong","value":"--help"},
50+
{"type":"Punctuation","value":"*"},
51+
{"type":"Text","value":"\n"},
52+
{"type":"LiteralStringBacktick","value":"\tShow help"},
53+
{"type":"Text","value":"\n\t"},
54+
{"type":"Keyword","value":"- "},
55+
{"type":"Text","value":"Nested item with tab\n\t\t"},
56+
{"type":"Keyword","value":"- "},
57+
{"type":"Text","value":"Deeply nested\n\n"},
58+
{"type":"Keyword","value":". "},
59+
{"type":"Text","value":"First item\n"},
60+
{"type":"Keyword","value":". "},
61+
{"type":"Text","value":"Second item\n\t"},
62+
{"type":"Keyword","value":". "},
63+
{"type":"Text","value":"Nested numbered item with continuation\n\t that spans multiple lines\n\n"},
64+
{"type":"GenericHeading","value":"#"},
65+
{"type":"Text","value":" "},
66+
{"type":"GenericStrong","value":"EXAMPLES"},
67+
{"type":"Text","value":"\n\nLiteral block:\n\n"},
68+
{"type":"LiteralStringBacktick","value":"```\ncode example\n```"},
69+
{"type":"Text","value":"\n\nTab-indented:\n\n"},
70+
{"type":"LiteralStringBacktick","value":"\tliteral text"},
71+
{"type":"Text","value":"\n\n"},
72+
{"type":"GenericHeading","value":"#"},
73+
{"type":"Text","value":" "},
74+
{"type":"GenericStrong","value":"TABLE"},
75+
{"type":"Text","value":"\n\n"},
76+
{"type":"Punctuation","value":"| Row 1"},
77+
{"type":"Text","value":"\n"},
78+
{"type":"Punctuation","value":": Cell 1"},
79+
{"type":"Text","value":"\n"},
80+
{"type":"Punctuation","value":":- Cell 2"},
81+
{"type":"Text","value":"\n\n"},
82+
{"type":"GenericHeading","value":"#"},
83+
{"type":"Text","value":" "},
84+
{"type":"GenericStrong","value":"ESCAPES"},
85+
{"type":"Text","value":"\n\nThis is "},
86+
{"type":"LiteralStringEscape","value":"\\*"},
87+
{"type":"Text","value":"not bold"},
88+
{"type":"LiteralStringEscape","value":"\\*"},
89+
{"type":"Text","value":" and "},
90+
{"type":"LiteralStringEscape","value":"\\_"},
91+
{"type":"Text","value":"not underlined"},
92+
{"type":"LiteralStringEscape","value":"\\_"},
93+
{"type":"Text","value":".\n"}
94+
]

0 commit comments

Comments
 (0)
⌂ 换网址