-
Notifications
You must be signed in to change notification settings - Fork 0
/
prsAction.ts
39 lines (38 loc) · 1.3 KB
/
prsAction.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import {AP, ProPAP, PAP, ParsedActionStatement, Arg, ForInstruction} from './types';
import {ElTypes} from 'be-linked/types';
import {RegExpOrRegExpExt} from 'be-enhanced/types';
import {arr, tryParse} from 'be-enhanced/cpu.js';
const reActionStatement: RegExpOrRegExpExt<ParsedActionStatement>[] = [
{
regExp: new RegExp(String.raw `^triggeredBy(?<dependencies>.*)`),
defaultVals: {}
}
]
export function prsAction(self: AP) : PAP {
//be careful about making this asynchronous due to args getting out of sync
let {Action, instructions} = self;
if(instructions === undefined) instructions = [];
const args: Array<Arg> = [];
const instruction: ForInstruction = {
args,
isAction: true
};
instructions.push(instruction);
const act0 = Action![0];
const test = tryParse(act0, reActionStatement) as ParsedActionStatement;
if(test === null) throw 'PE'; //Parse Error
const {dependencies} = test;
const splitDependencies = dependencies!.split(',').map(x => x.trim());
for(const dependency of splitDependencies){
const type = dependency[0] as ElTypes;
const prop = dependency.substring(1);
const arg: Arg = {
type,
prop
};
args.push(arg);
}
return {
instructions
};
}