Skip to content

Commit

Permalink
Remove semantic markup definitions/options.
Browse files Browse the repository at this point in the history
This will get reverted later when adding semantic markup support.
  • Loading branch information
felixfontein committed Mar 6, 2023
1 parent 09371d0 commit b5d3365
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 75 deletions.
3 changes: 0 additions & 3 deletions src/opts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
74 changes: 2 additions & 72 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -118,15 +80,10 @@ export type AnyPart =
| ItalicPart
| BoldPart
| ModulePart
| PluginPart
| URLPart
| LinkPart
| RSTRefPart
| CodePart
| OptionNamePart
| OptionValuePart
| EnvVariablePart
| ReturnValuePart
| HorizontalLinePart
| ErrorPart;

Expand All @@ -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;
}

Expand All @@ -145,7 +100,6 @@ const PARSER: CommandParser[] = [
{
command: 'I',
parameters: 1,
old_markup: true,
process: (args) => {
const text = args[0] as string;
return <ItalicPart>{ type: PartType.ITALIC, text: text };
Expand All @@ -154,7 +108,6 @@ const PARSER: CommandParser[] = [
{
command: 'B',
parameters: 1,
old_markup: true,
process: (args) => {
const text = args[0] as string;
return <BoldPart>{ type: PartType.BOLD, text: text };
Expand All @@ -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)) {
Expand All @@ -175,7 +127,6 @@ const PARSER: CommandParser[] = [
{
command: 'U',
parameters: 1,
old_markup: true,
process: (args) => {
const url = args[0] as string;
return <URLPart>{ type: PartType.URL, url: url };
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -204,7 +153,6 @@ const PARSER: CommandParser[] = [
{
command: 'C',
parameters: 1,
old_markup: true,
process: (args) => {
const text = args[0] as string;
return <CodePart>{ type: PartType.CODE, text: text };
Expand All @@ -218,8 +166,6 @@ const PARSER: CommandParser[] = [
return <HorizontalLinePart>{ type: PartType.HORIZONTAL_LINE };
},
},
// Semantic Ansible docs markup:
// TODO
];

const PARSER_COMMANDS: Map<string, CommandParser> = (() => {
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b5d3365

Please sign in to comment.