4
4
SPDX-License-Identifier: BSD-2-Clause
5
5
*/
6
6
7
- import { ParsingOptions } from './opts' ;
7
+ import { ParsingOptions , PluginIdentifier } from './opts' ;
8
8
import { isFQCN } from './ansible' ;
9
9
10
10
export enum PartType {
@@ -18,6 +18,11 @@ export enum PartType {
18
18
RST_REF = 7 ,
19
19
URL = 8 ,
20
20
TEXT = 9 ,
21
+ ENV_VARIABLE = 10 ,
22
+ OPTION_NAME = 11 ,
23
+ OPTION_VALUE = 12 ,
24
+ PLUGIN = 13 ,
25
+ RETURN_VALUE = 14 ,
21
26
}
22
27
23
28
export interface Part {
@@ -44,6 +49,11 @@ export interface ModulePart extends Part {
44
49
fqcn : string ;
45
50
}
46
51
52
+ export interface PluginPart extends Part {
53
+ type : PartType . PLUGIN ;
54
+ plugin : PluginIdentifier ;
55
+ }
56
+
47
57
export interface URLPart extends Part {
48
58
type : PartType . URL ;
49
59
url : string ;
@@ -66,6 +76,34 @@ export interface CodePart extends Part {
66
76
text : string ;
67
77
}
68
78
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
+
69
107
export interface HorizontalLinePart extends Part {
70
108
type : PartType . HORIZONTAL_LINE ;
71
109
}
@@ -80,10 +118,15 @@ export type AnyPart =
80
118
| ItalicPart
81
119
| BoldPart
82
120
| ModulePart
121
+ | PluginPart
83
122
| URLPart
84
123
| LinkPart
85
124
| RSTRefPart
86
125
| CodePart
126
+ | OptionNamePart
127
+ | OptionValuePart
128
+ | EnvVariablePart
129
+ | ReturnValuePart
87
130
| HorizontalLinePart
88
131
| ErrorPart ;
89
132
@@ -92,6 +135,8 @@ export type Paragraph = AnyPart[];
92
135
interface CommandParser {
93
136
command : string ;
94
137
parameters : number ;
138
+ old_markup ?: boolean ;
139
+ escaped_arguments ?: boolean ;
95
140
process : ( args : string [ ] , opts : ParsingOptions ) => AnyPart ;
96
141
}
97
142
@@ -100,6 +145,7 @@ const PARSER: CommandParser[] = [
100
145
{
101
146
command : 'I' ,
102
147
parameters : 1 ,
148
+ old_markup : true ,
103
149
process : ( args ) => {
104
150
const text = args [ 0 ] as string ;
105
151
return < ItalicPart > { type : PartType . ITALIC , text : text } ;
@@ -108,6 +154,7 @@ const PARSER: CommandParser[] = [
108
154
{
109
155
command : 'B' ,
110
156
parameters : 1 ,
157
+ old_markup : true ,
111
158
process : ( args ) => {
112
159
const text = args [ 0 ] as string ;
113
160
return < BoldPart > { type : PartType . BOLD , text : text } ;
@@ -116,6 +163,7 @@ const PARSER: CommandParser[] = [
116
163
{
117
164
command : 'M' ,
118
165
parameters : 1 ,
166
+ old_markup : true ,
119
167
process : ( args ) => {
120
168
const fqcn = args [ 0 ] as string ;
121
169
if ( ! isFQCN ( fqcn ) ) {
@@ -127,6 +175,7 @@ const PARSER: CommandParser[] = [
127
175
{
128
176
command : 'U' ,
129
177
parameters : 1 ,
178
+ old_markup : true ,
130
179
process : ( args ) => {
131
180
const url = args [ 0 ] as string ;
132
181
return < URLPart > { type : PartType . URL , url : url } ;
@@ -135,6 +184,7 @@ const PARSER: CommandParser[] = [
135
184
{
136
185
command : 'L' ,
137
186
parameters : 2 ,
187
+ old_markup : true ,
138
188
process : ( args ) => {
139
189
const text = args [ 0 ] as string ;
140
190
const url = args [ 1 ] as string ;
@@ -144,6 +194,7 @@ const PARSER: CommandParser[] = [
144
194
{
145
195
command : 'R' ,
146
196
parameters : 2 ,
197
+ old_markup : true ,
147
198
process : ( args ) => {
148
199
const text = args [ 0 ] as string ;
149
200
const ref = args [ 1 ] as string ;
@@ -153,6 +204,7 @@ const PARSER: CommandParser[] = [
153
204
{
154
205
command : 'C' ,
155
206
parameters : 1 ,
207
+ old_markup : true ,
156
208
process : ( args ) => {
157
209
const text = args [ 0 ] as string ;
158
210
return < CodePart > { type : PartType . CODE , text : text } ;
@@ -166,6 +218,8 @@ const PARSER: CommandParser[] = [
166
218
return < HorizontalLinePart > { type : PartType . HORIZONTAL_LINE } ;
167
219
} ,
168
220
} ,
221
+ // Semantic Ansible docs markup:
222
+ // TODO
169
223
] ;
170
224
171
225
const PARSER_COMMANDS : Map < string , CommandParser > = ( ( ) => {
@@ -179,6 +233,14 @@ function commandRE(command: CommandParser): string {
179
233
}
180
234
181
235
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
+ ) ;
182
244
183
245
function lstripSpace ( input : string ) : string {
184
246
let index = 0 ;
@@ -198,6 +260,12 @@ function rstripSpace(input: string) {
198
260
return index < length ? input . slice ( 0 , index ) : input ;
199
261
}
200
262
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
+
201
269
function parseUnescapedArgs ( input : string , index : number , count : number ) : [ string [ ] , number , string | undefined ] {
202
270
const result : string [ ] = [ ] ;
203
271
let first = true ;
@@ -232,7 +300,7 @@ function parseUnescapedArgs(input: string, index: number, count: number): [strin
232
300
233
301
function parseString ( input : string , opts : ParsingOptions ) : Paragraph {
234
302
const result : AnyPart [ ] = [ ] ;
235
- const commandRE = COMMAND_RE ;
303
+ const commandRE = opts . only_classic_markup ? CLASSIC_COMMAND_RE : COMMAND_RE ;
236
304
const length = input . length ;
237
305
let index = 0 ;
238
306
while ( index < length ) {
@@ -267,6 +335,8 @@ function parseString(input: string, opts: ParsingOptions): Paragraph {
267
335
let error : string | undefined ;
268
336
if ( command . parameters === 0 ) {
269
337
args = [ ] ;
338
+ } else if ( command . escaped_arguments ) {
339
+ [ args , endIndex , error ] = parseEscapedArgs ( input , endIndex , command . parameters ) ;
270
340
} else {
271
341
[ args , endIndex , error ] = parseUnescapedArgs ( input , endIndex , command . parameters ) ;
272
342
}
0 commit comments