Skip to content

Commit

Permalink
Merge pull request #21 from superfaceai/feature/call-foreach
Browse files Browse the repository at this point in the history
feat: add iteration atom node
  • Loading branch information
lukas-valenta authored Feb 4, 2021
2 parents 1905153 + 5f7a855 commit 31717d7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## [Unreleased]

### Added
* Added `IterationAtomNode`
* Added `IterationAtomNode` to `CallStatementNode` and `InlineCallNode`
* Added `ConditionAtomNode` to `InlineCallNode`

### Changed
* Renamed `StatementConditionNode` to `ConditionAtomNode`

## [0.0.20] - 2021-01-11

### Added
Expand Down
32 changes: 23 additions & 9 deletions src/interfaces/ast/map-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export type MapNodeKind =
| 'JessieExpression'
| 'InlineCall'
| 'Assignment'
| 'StatementCondition'
| 'ConditionAtom'
| 'IterationAtom'
// STATEMENTS
| 'SetStatement'
| 'OutcomeStatement'
Expand Down Expand Up @@ -55,10 +56,12 @@ export interface JessieExpressionNode extends MapASTNodeBase {
}

/**
* Inline call, can appear on rhs in assignment.
* Inline call, can appear on rhs in assignment: `call <?iteration> <op>(<...args>) <?condition>`
*/
export interface InlineCallNode extends MapASTNodeBase {
kind: 'InlineCall';
condition?: ConditionAtomNode;
iteration?: IterationAtomNode;
operationName: string;
arguments: AssignmentNode[];
}
Expand All @@ -81,11 +84,20 @@ export interface AssignmentNode extends MapASTNodeBase {
/**
* Statement condition atom: `if (<jessie>)`
*/
export interface StatementConditionNode extends MapASTNodeBase {
kind: 'StatementCondition';
export interface ConditionAtomNode extends MapASTNodeBase {
kind: 'ConditionAtom';
expression: JessieExpressionNode;
}

/**
* Iteration atom: `foreach (<iterationVariable> of <iterable>)`
*/
export interface IterationAtomNode extends MapASTNodeBase {
kind: 'IterationAtom';
iterationVariable: string;
iterable: JessieExpressionNode;
}

// STATEMENTS

/**
Expand All @@ -95,7 +107,7 @@ export interface StatementConditionNode extends MapASTNodeBase {
*/
export interface OutcomeStatementNode extends MapASTNodeBase {
kind: 'OutcomeStatement';
condition?: StatementConditionNode;
condition?: ConditionAtomNode;
isError: boolean;
terminateFlow: boolean;
value: LiteralNode;
Expand All @@ -108,16 +120,17 @@ export interface OutcomeStatementNode extends MapASTNodeBase {
*/
export interface SetStatementNode extends MapASTNodeBase {
kind: 'SetStatement';
condition?: StatementConditionNode;
condition?: ConditionAtomNode;
assignments: AssignmentNode[];
}

/**
* Call statement, possibly with a condition: `call <op>(<...args>) <?condition> { <...statements> }`
* Call statement, possibly with a condition and iteration: `call <?iteration> <op>(<...args>) <?condition> { <...statements> }`
*/
export interface CallStatementNode extends MapASTNodeBase {
kind: 'CallStatement';
condition?: StatementConditionNode;
iteration?: IterationAtomNode;
condition?: ConditionAtomNode;
operationName: string;
arguments: AssignmentNode[];
statements: (SetStatementNode | OutcomeStatementNode)[];
Expand Down Expand Up @@ -211,7 +224,8 @@ export type MapASTNode =
| ObjectLiteralNode
| JessieExpressionNode
| AssignmentNode
| StatementConditionNode
| ConditionAtomNode
| IterationAtomNode
| SetStatementNode
| OutcomeStatementNode
| CallStatementNode
Expand Down
15 changes: 11 additions & 4 deletions src/interfaces/ast/map-ast.utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {
AssignmentNode,
CallStatementNode,
ConditionAtomNode,
HttpCallStatementNode,
HttpRequestNode,
HttpResponseHandlerNode,
InlineCallNode,
IterationAtomNode,
JessieExpressionNode,
MapASTNode,
MapDefinitionNode,
Expand All @@ -15,7 +17,6 @@ import {
OutcomeStatementNode,
PrimitiveLiteralNode,
SetStatementNode,
StatementConditionNode,
} from './map-ast';

export function isOutcomeStatementNode(
Expand Down Expand Up @@ -70,10 +71,16 @@ export function isAssignmentNode(node: MapASTNode): node is AssignmentNode {
return node.kind === 'Assignment';
}

export function isStatementConditionNode(
export function isConditionAtomNode(
node: MapASTNode
): node is StatementConditionNode {
return node.kind === 'StatementCondition';
): node is ConditionAtomNode {
return node.kind === 'ConditionAtom';
}

export function isIterationAtomNode(
node: MapASTNode
): node is IterationAtomNode {
return node.kind === 'IterationAtom';
}

export function isCallStatementNode(
Expand Down

0 comments on commit 31717d7

Please sign in to comment.