Comparing version 1.0.6 to 1.0.7
@@ -181,4 +181,5 @@ /** | ||
private static flattenListNode; | ||
private static flattenPipelineNode; | ||
} | ||
export default AST; | ||
//# sourceMappingURL=ast.d.ts.map |
@@ -501,2 +501,5 @@ "use strict"; | ||
} | ||
else if (AST.isPipeline(node)) { | ||
return AST.flattenPipelineNode(node); | ||
} | ||
return []; | ||
@@ -511,3 +514,4 @@ } | ||
AST.isOption(part) || | ||
AST.isArgument(part)) { | ||
AST.isArgument(part) || | ||
AST.isRedirect(part)) { | ||
flat = [...flat, part]; | ||
@@ -522,5 +526,15 @@ } | ||
static flattenListNode(node) { | ||
if (!node.parts) { | ||
return []; | ||
let flat = []; | ||
for (const part of node.parts) { | ||
if (AST.isCommand(part)) { | ||
const flatCommandNode = AST.flattenCommandNode(part); | ||
flat = [...flat, ...flatCommandNode]; | ||
} | ||
else if (AST.isOperator(part)) { | ||
flat = [...flat, part]; | ||
} | ||
} | ||
return flat; | ||
} | ||
static flattenPipelineNode(node) { | ||
let flat = []; | ||
@@ -532,3 +546,3 @@ for (const part of node.parts) { | ||
} | ||
if (AST.isOperator(part)) { | ||
else if (AST.isPipe(part)) { | ||
flat = [...flat, part]; | ||
@@ -535,0 +549,0 @@ } |
@@ -140,2 +140,4 @@ import { ProgramSchema, OptionSchema } from "kmdr-parser/src/interfaces"; | ||
} | ||
export interface PipelineLeafNodes extends Array<ProgramNode | SubcommandNode | AssignmentNode | OptionNode | ArgumentNode | PipeNode> { | ||
} | ||
export interface ASTInstance { | ||
@@ -142,0 +144,0 @@ assignmentHasValue(node: AssignmentNode, name: string, value: string): boolean; |
{ | ||
"name": "kmdr-ast", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Traverse the AST of an explanation by kmdr", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -21,4 +21,7 @@ /** | ||
CommandLeafNodes, | ||
ListLeafNodes | ||
ListLeafNodes, | ||
PipelineLeafNodes, | ||
FlatAST | ||
} from "./interfaces"; | ||
import { PipelineNode } from "."; | ||
@@ -635,2 +638,4 @@ class AST { | ||
return AST.flattenListNode(node as ListNode); | ||
} else if (AST.isPipeline(node)) { | ||
return AST.flattenPipelineNode(node as PipelineNode); | ||
} | ||
@@ -641,4 +646,4 @@ | ||
private static flattenCommandNode(node: CommandNode): CommandLeafNodes { | ||
let flat: CommandLeafNodes = []; | ||
private static flattenCommandNode(node: CommandNode): FlatAST { | ||
let flat: FlatAST = []; | ||
@@ -651,3 +656,4 @@ for (const part of node.parts) { | ||
AST.isOption(part) || | ||
AST.isArgument(part) | ||
AST.isArgument(part) || | ||
AST.isRedirect(part) | ||
) { | ||
@@ -663,11 +669,20 @@ flat = [...flat, part]; | ||
private static flattenListNode(node: ListNode): ListLeafNodes { | ||
if (!node.parts) { | ||
return []; | ||
private static flattenListNode(node: ListNode): FlatAST { | ||
let flat: FlatAST = []; | ||
for (const part of node.parts) { | ||
if (AST.isCommand(part)) { | ||
const flatCommandNode = AST.flattenCommandNode(part as CommandNode); | ||
flat = [...flat, ...flatCommandNode]; | ||
} else if (AST.isOperator(part)) { | ||
flat = [...flat, part]; | ||
} | ||
} | ||
let flat: Array< | ||
ProgramNode | AssignmentNode | OptionNode | ArgumentNode | OperatorNode | ||
> = []; | ||
return flat; | ||
} | ||
private static flattenPipelineNode(node: PipelineNode): FlatAST { | ||
let flat: FlatAST = []; | ||
for (const part of node.parts) { | ||
@@ -677,4 +692,19 @@ if (AST.isCommand(part)) { | ||
flat = [...flat, ...flatCommandNode]; | ||
} else if (AST.isPipe(part)) { | ||
flat = [...flat, part]; | ||
} | ||
if (AST.isOperator(part)) { | ||
} | ||
return flat; | ||
} | ||
/* | ||
private static flattenRedirectNode(node: RedirectNode): FlatAST { | ||
let flat: FlatAST = []; | ||
for (const part of node.parts) { | ||
if (AST.isCommand(part)) { | ||
const flatCommandNode = AST.flattenCommandNode(part as CommandNode); | ||
flat = [...flat, ...flatCommandNode]; | ||
} else if (AST.isPipe(part)) { | ||
flat = [...flat, part]; | ||
@@ -686,4 +716,5 @@ } | ||
} | ||
*/ | ||
} | ||
export default AST; |
@@ -182,2 +182,12 @@ import { ProgramSchema, OptionSchema } from "kmdr-parser/src/interfaces"; | ||
export interface PipelineLeafNodes | ||
extends Array< | ||
| ProgramNode | ||
| SubcommandNode | ||
| AssignmentNode | ||
| OptionNode | ||
| ArgumentNode | ||
| PipeNode | ||
> {} | ||
export interface ASTInstance { | ||
@@ -184,0 +194,0 @@ assignmentHasValue( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77265
1798