Skip to content

Commit 1578980

Browse files
authored
Merge pull request #180 from sugarlabs/editor-yaml
Editor: Use YAML to represent instructions
2 parents b935f38 + ccb1358 commit 1578980

File tree

10 files changed

+515
-258
lines changed

10 files changed

+515
-258
lines changed

package-lock.json

Lines changed: 16 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@types/jest": "^27.4.0",
2323
"@types/jquery": "^3.5.8",
2424
"@types/jqueryui": "^1.12.16",
25+
"@types/js-yaml": "^4.0.5",
2526
"@types/node": "^16.11.21",
2627
"@types/p5": "^1.3.3",
2728
"@types/react": "^17.0.38",
@@ -47,6 +48,7 @@
4748
"dependencies": {
4849
"@sugarlabs/musicblocks-v4-lib": "^0.2.0",
4950
"jquery": "^3.6.0",
51+
"js-yaml": "^3.14.1",
5052
"p5": "^1.4.0",
5153
"react": "^17.0.2",
5254
"react-dom": "^17.0.2",

src/components/editor/@types/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** Reresents a literal code argument. */
2+
export type ICodeArgumentLiteral = boolean | number | string;
3+
4+
/** Represents the interface for a code argument snapshot object. */
5+
export interface ICodeArgumentObj {
6+
[key: string]: ICodeArgumentLiteral | ICodeArgumentObj;
7+
}
8+
9+
/** Represents the interface for a code argument element. */
10+
export type ICodeArgument = ICodeArgumentLiteral | ICodeArgumentObj;
11+
12+
/** Represents the interface for a code instruction element object. */
13+
export interface ICodeInstructionObj {
14+
[instruction: string]: ICodeArgument;
15+
}
16+
17+
/** Represents the interface for a code instruction element. */
18+
export type ICodeInstruction = string | ICodeInstructionObj;

src/components/editor/core/dummy.ts

Lines changed: 0 additions & 156 deletions
This file was deleted.

src/components/editor/core/errors.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
abstract class SyntaxError extends Error {
2+
private _name: string;
3+
private _message: string;
4+
5+
constructor(name: string, message: string) {
6+
super(message);
7+
this._name = name;
8+
this._message = message;
9+
}
10+
11+
public toString(): string {
12+
return `${this._name}: ${this._message}`;
13+
}
14+
15+
public get type(): string {
16+
return this._name;
17+
}
18+
}
19+
20+
export class InvalidInstructionError extends SyntaxError {
21+
constructor(message: string) {
22+
super('InvalidInstructionError', message);
23+
}
24+
}
25+
26+
export class InvalidArgumentError extends SyntaxError {
27+
constructor(message: string) {
28+
super('InvalidArgumentError', message);
29+
}
30+
}

0 commit comments

Comments
 (0)