From b5d336574946d38647d2bf6783b8f5638ea24b3d Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Mon, 6 Mar 2023 21:29:02 +0100 Subject: [PATCH] Remove semantic markup definitions/options. This will get reverted later when adding semantic markup support. --- src/opts.ts | 3 --- src/parser.ts | 74 ++------------------------------------------------- 2 files changed, 2 insertions(+), 75 deletions(-) diff --git a/src/opts.ts b/src/opts.ts index f59a25c..a0bf3e3 100644 --- a/src/opts.ts +++ b/src/opts.ts @@ -25,9 +25,6 @@ export interface PluginIdentifier { export interface ParsingOptions extends ErrorHandlingOptions { /** Should be provided if parsing documentation of a plugin/module/role. */ current_plugin?: PluginIdentifier; - - /** If set to 'true', only 'classic' Ansible docs markup is accepted. */ - only_classic_markup?: boolean; } /* eslint-disable-next-line @typescript-eslint/no-empty-interface */ diff --git a/src/parser.ts b/src/parser.ts index 019e6b6..aededd1 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -4,7 +4,7 @@ SPDX-License-Identifier: BSD-2-Clause */ -import { ParsingOptions, PluginIdentifier } from './opts'; +import { ParsingOptions } from './opts'; import { isFQCN } from './ansible'; export enum PartType { @@ -18,11 +18,6 @@ export enum PartType { RST_REF = 7, URL = 8, TEXT = 9, - ENV_VARIABLE = 10, - OPTION_NAME = 11, - OPTION_VALUE = 12, - PLUGIN = 13, - RETURN_VALUE = 14, } export interface Part { @@ -49,11 +44,6 @@ export interface ModulePart extends Part { fqcn: string; } -export interface PluginPart extends Part { - type: PartType.PLUGIN; - plugin: PluginIdentifier; -} - export interface URLPart extends Part { type: PartType.URL; url: string; @@ -76,34 +66,6 @@ export interface CodePart extends Part { text: string; } -export interface OptionNamePart extends Part { - type: PartType.OPTION_NAME; - ignore: boolean; - plugin: PluginIdentifier | undefined; - option_link: string; - option: string; - value: string | undefined; -} - -export interface OptionValuePart extends Part { - type: PartType.OPTION_VALUE; - value: string; -} - -export interface EnvVariablePart extends Part { - type: PartType.ENV_VARIABLE; - name: string; -} - -export interface ReturnValuePart extends Part { - type: PartType.RETURN_VALUE; - ignore: boolean; - plugin: PluginIdentifier | undefined; - return_value_link: string; - return_value: string; - value: string | undefined; -} - export interface HorizontalLinePart extends Part { type: PartType.HORIZONTAL_LINE; } @@ -118,15 +80,10 @@ export type AnyPart = | ItalicPart | BoldPart | ModulePart - | PluginPart | URLPart | LinkPart | RSTRefPart | CodePart - | OptionNamePart - | OptionValuePart - | EnvVariablePart - | ReturnValuePart | HorizontalLinePart | ErrorPart; @@ -135,8 +92,6 @@ export type Paragraph = AnyPart[]; interface CommandParser { command: string; parameters: number; - old_markup?: boolean; - escaped_arguments?: boolean; process: (args: string[], opts: ParsingOptions) => AnyPart; } @@ -145,7 +100,6 @@ const PARSER: CommandParser[] = [ { command: 'I', parameters: 1, - old_markup: true, process: (args) => { const text = args[0] as string; return { type: PartType.ITALIC, text: text }; @@ -154,7 +108,6 @@ const PARSER: CommandParser[] = [ { command: 'B', parameters: 1, - old_markup: true, process: (args) => { const text = args[0] as string; return { type: PartType.BOLD, text: text }; @@ -163,7 +116,6 @@ const PARSER: CommandParser[] = [ { command: 'M', parameters: 1, - old_markup: true, process: (args) => { const fqcn = args[0] as string; if (!isFQCN(fqcn)) { @@ -175,7 +127,6 @@ const PARSER: CommandParser[] = [ { command: 'U', parameters: 1, - old_markup: true, process: (args) => { const url = args[0] as string; return { type: PartType.URL, url: url }; @@ -184,7 +135,6 @@ const PARSER: CommandParser[] = [ { command: 'L', parameters: 2, - old_markup: true, process: (args) => { const text = args[0] as string; const url = args[1] as string; @@ -194,7 +144,6 @@ const PARSER: CommandParser[] = [ { command: 'R', parameters: 2, - old_markup: true, process: (args) => { const text = args[0] as string; const ref = args[1] as string; @@ -204,7 +153,6 @@ const PARSER: CommandParser[] = [ { command: 'C', parameters: 1, - old_markup: true, process: (args) => { const text = args[0] as string; return { type: PartType.CODE, text: text }; @@ -218,8 +166,6 @@ const PARSER: CommandParser[] = [ return { type: PartType.HORIZONTAL_LINE }; }, }, - // Semantic Ansible docs markup: - // TODO ]; const PARSER_COMMANDS: Map = (() => { @@ -233,14 +179,6 @@ function commandRE(command: CommandParser): string { } const COMMAND_RE = new RegExp('(' + PARSER.map(commandRE).join('|') + ')', 'g'); -const CLASSIC_COMMAND_RE = new RegExp( - '(' + - PARSER.filter((cmd) => cmd.old_markup) - .map(commandRE) - .join('|') + - ')', - 'g', -); function lstripSpace(input: string): string { let index = 0; @@ -260,12 +198,6 @@ function rstripSpace(input: string) { return index < length ? input.slice(0, index) : input; } -/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ -function parseEscapedArgs(input: string, index: number, count: number): [string[], number, string | undefined] { - // TODO - return [[], index, 'Internal error: escaped arguments unsupported']; -} - function parseUnescapedArgs(input: string, index: number, count: number): [string[], number, string | undefined] { const result: string[] = []; let first = true; @@ -300,7 +232,7 @@ function parseUnescapedArgs(input: string, index: number, count: number): [strin function parseString(input: string, opts: ParsingOptions): Paragraph { const result: AnyPart[] = []; - const commandRE = opts.only_classic_markup ? CLASSIC_COMMAND_RE : COMMAND_RE; + const commandRE = COMMAND_RE; const length = input.length; let index = 0; while (index < length) { @@ -335,8 +267,6 @@ function parseString(input: string, opts: ParsingOptions): Paragraph { let error: string | undefined; if (command.parameters === 0) { args = []; - } else if (command.escaped_arguments) { - [args, endIndex, error] = parseEscapedArgs(input, endIndex, command.parameters); } else { [args, endIndex, error] = parseUnescapedArgs(input, endIndex, command.parameters); }