Skip to content

Commit 001bf15

Browse files
committed
Revert "Remove semantic markup definitions/options."
This reverts commit b5d3365.
1 parent 5dd2bcf commit 001bf15

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

src/opts.ts

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export interface PluginIdentifier {
2525
export interface ParsingOptions extends ErrorHandlingOptions {
2626
/** Should be provided if parsing documentation of a plugin/module/role. */
2727
current_plugin?: PluginIdentifier;
28+
29+
/** If set to 'true', only 'classic' Ansible docs markup is accepted. */
30+
only_classic_markup?: boolean;
2831
}
2932

3033
/* eslint-disable-next-line @typescript-eslint/no-empty-interface */

src/parser.ts

+72-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
SPDX-License-Identifier: BSD-2-Clause
55
*/
66

7-
import { ParsingOptions } from './opts';
7+
import { ParsingOptions, PluginIdentifier } from './opts';
88
import { isFQCN } from './ansible';
99

1010
export enum PartType {
@@ -18,6 +18,11 @@ export enum PartType {
1818
RST_REF = 7,
1919
URL = 8,
2020
TEXT = 9,
21+
ENV_VARIABLE = 10,
22+
OPTION_NAME = 11,
23+
OPTION_VALUE = 12,
24+
PLUGIN = 13,
25+
RETURN_VALUE = 14,
2126
}
2227

2328
export interface Part {
@@ -44,6 +49,11 @@ export interface ModulePart extends Part {
4449
fqcn: string;
4550
}
4651

52+
export interface PluginPart extends Part {
53+
type: PartType.PLUGIN;
54+
plugin: PluginIdentifier;
55+
}
56+
4757
export interface URLPart extends Part {
4858
type: PartType.URL;
4959
url: string;
@@ -66,6 +76,34 @@ export interface CodePart extends Part {
6676
text: string;
6777
}
6878

79+
export interface OptionNamePart extends Part {
80+
type: PartType.OPTION_NAME;
81+
ignore: boolean;
82+
plugin: PluginIdentifier | undefined;
83+
option_link: string;
84+
option: string;
85+
value: string | undefined;
86+
}
87+
88+
export interface OptionValuePart extends Part {
89+
type: PartType.OPTION_VALUE;
90+
value: string;
91+
}
92+
93+
export interface EnvVariablePart extends Part {
94+
type: PartType.ENV_VARIABLE;
95+
name: string;
96+
}
97+
98+
export interface ReturnValuePart extends Part {
99+
type: PartType.RETURN_VALUE;
100+
ignore: boolean;
101+
plugin: PluginIdentifier | undefined;
102+
return_value_link: string;
103+
return_value: string;
104+
value: string | undefined;
105+
}
106+
69107
export interface HorizontalLinePart extends Part {
70108
type: PartType.HORIZONTAL_LINE;
71109
}
@@ -80,10 +118,15 @@ export type AnyPart =
80118
| ItalicPart
81119
| BoldPart
82120
| ModulePart
121+
| PluginPart
83122
| URLPart
84123
| LinkPart
85124
| RSTRefPart
86125
| CodePart
126+
| OptionNamePart
127+
| OptionValuePart
128+
| EnvVariablePart
129+
| ReturnValuePart
87130
| HorizontalLinePart
88131
| ErrorPart;
89132

@@ -92,6 +135,8 @@ export type Paragraph = AnyPart[];
92135
interface CommandParser {
93136
command: string;
94137
parameters: number;
138+
old_markup?: boolean;
139+
escaped_arguments?: boolean;
95140
process: (args: string[], opts: ParsingOptions) => AnyPart;
96141
}
97142

@@ -100,6 +145,7 @@ const PARSER: CommandParser[] = [
100145
{
101146
command: 'I',
102147
parameters: 1,
148+
old_markup: true,
103149
process: (args) => {
104150
const text = args[0] as string;
105151
return <ItalicPart>{ type: PartType.ITALIC, text: text };
@@ -108,6 +154,7 @@ const PARSER: CommandParser[] = [
108154
{
109155
command: 'B',
110156
parameters: 1,
157+
old_markup: true,
111158
process: (args) => {
112159
const text = args[0] as string;
113160
return <BoldPart>{ type: PartType.BOLD, text: text };
@@ -116,6 +163,7 @@ const PARSER: CommandParser[] = [
116163
{
117164
command: 'M',
118165
parameters: 1,
166+
old_markup: true,
119167
process: (args) => {
120168
const fqcn = args[0] as string;
121169
if (!isFQCN(fqcn)) {
@@ -127,6 +175,7 @@ const PARSER: CommandParser[] = [
127175
{
128176
command: 'U',
129177
parameters: 1,
178+
old_markup: true,
130179
process: (args) => {
131180
const url = args[0] as string;
132181
return <URLPart>{ type: PartType.URL, url: url };
@@ -135,6 +184,7 @@ const PARSER: CommandParser[] = [
135184
{
136185
command: 'L',
137186
parameters: 2,
187+
old_markup: true,
138188
process: (args) => {
139189
const text = args[0] as string;
140190
const url = args[1] as string;
@@ -144,6 +194,7 @@ const PARSER: CommandParser[] = [
144194
{
145195
command: 'R',
146196
parameters: 2,
197+
old_markup: true,
147198
process: (args) => {
148199
const text = args[0] as string;
149200
const ref = args[1] as string;
@@ -153,6 +204,7 @@ const PARSER: CommandParser[] = [
153204
{
154205
command: 'C',
155206
parameters: 1,
207+
old_markup: true,
156208
process: (args) => {
157209
const text = args[0] as string;
158210
return <CodePart>{ type: PartType.CODE, text: text };
@@ -166,6 +218,8 @@ const PARSER: CommandParser[] = [
166218
return <HorizontalLinePart>{ type: PartType.HORIZONTAL_LINE };
167219
},
168220
},
221+
// Semantic Ansible docs markup:
222+
// TODO
169223
];
170224

171225
const PARSER_COMMANDS: Map<string, CommandParser> = (() => {
@@ -179,6 +233,14 @@ function commandRE(command: CommandParser): string {
179233
}
180234

181235
const COMMAND_RE = new RegExp('(' + PARSER.map(commandRE).join('|') + ')', 'g');
236+
const CLASSIC_COMMAND_RE = new RegExp(
237+
'(' +
238+
PARSER.filter((cmd) => cmd.old_markup)
239+
.map(commandRE)
240+
.join('|') +
241+
')',
242+
'g',
243+
);
182244

183245
function lstripSpace(input: string): string {
184246
let index = 0;
@@ -198,6 +260,12 @@ function rstripSpace(input: string) {
198260
return index < length ? input.slice(0, index) : input;
199261
}
200262

263+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
264+
function parseEscapedArgs(input: string, index: number, count: number): [string[], number, string | undefined] {
265+
// TODO
266+
return [[], index, 'Internal error: escaped arguments unsupported'];
267+
}
268+
201269
function parseUnescapedArgs(input: string, index: number, count: number): [string[], number, string | undefined] {
202270
const result: string[] = [];
203271
let first = true;
@@ -232,7 +300,7 @@ function parseUnescapedArgs(input: string, index: number, count: number): [strin
232300

233301
function parseString(input: string, opts: ParsingOptions): Paragraph {
234302
const result: AnyPart[] = [];
235-
const commandRE = COMMAND_RE;
303+
const commandRE = opts.only_classic_markup ? CLASSIC_COMMAND_RE : COMMAND_RE;
236304
const length = input.length;
237305
let index = 0;
238306
while (index < length) {
@@ -267,6 +335,8 @@ function parseString(input: string, opts: ParsingOptions): Paragraph {
267335
let error: string | undefined;
268336
if (command.parameters === 0) {
269337
args = [];
338+
} else if (command.escaped_arguments) {
339+
[args, endIndex, error] = parseEscapedArgs(input, endIndex, command.parameters);
270340
} else {
271341
[args, endIndex, error] = parseUnescapedArgs(input, endIndex, command.parameters);
272342
}

0 commit comments

Comments
 (0)