-
Notifications
You must be signed in to change notification settings - Fork 0
/
Types.ts
113 lines (87 loc) · 4.24 KB
/
Types.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/********************************************************************************
** Types
This module contains type and class declarations for parse results
and interpretations.
You don't have to edit this file (unless you add things to the grammar).
********************************************************************************/
export class ShrdliteResult {
constructor(
public input : string,
public parse : Command,
public interpretation? : DNFFormula,
public plan? : string[],
) {}
}
//////////////////////////////////////////////////////////////////////
// Parse results
export type Command = TakeCommand | DropCommand | MoveCommand | WhereisCommand;
export class TakeCommand {
constructor(public entity : Entity) {}
toString() : string {return `TakeCommand(${this.entity.toString()})`};
clone() : TakeCommand {return new TakeCommand(this.entity.clone())};
}
export class DropCommand {
constructor(public location:Location) {}
toString() : string {return `DropCommand(${this.location.toString()})`};
clone() : DropCommand {return new DropCommand(this.location.clone())};
}
export class MoveCommand {
constructor(public entity:Entity,
public location:Location) {}
toString() : string {return `MoveCommand(${this.entity.toString()}, ${this.location.toString()})`};
clone() : MoveCommand {return new MoveCommand(this.entity.clone(), this.location.clone())};
}
export class WhereisCommand {
constructor(public entity : Entity) {}
toString() : string {return `WhereisCommand(${this.entity.toString()})`};
clone() : WhereisCommand {return new WhereisCommand(this.entity.clone())};
}
export class Location {
constructor(public relation:string,
public entity:Entity) {}
toString() : string {return `Location(${this.relation}, ${this.entity.toString()})`}
clone() : Location {return new Location(this.relation, this.entity.clone())};
}
export class Entity {
constructor(public quantifier:string,
public object:Object) {}
toString() : string {return `Entity(${this.quantifier}, ${this.object.toString()})`};
clone() : Entity {return new Entity(this.quantifier, this.object.clone())};
}
export type Object = RelativeObject | SimpleObject;
export class RelativeObject {
constructor(public object:Object,
public location:Location) {}
toString() : string {return `RelativeObject(${this.object.toString()}, ${this.location.toString()})`};
clone() : RelativeObject {return new RelativeObject(this.object.clone(), this.location.clone())};
}
export class SimpleObject {
constructor(public size:Size,
public color:Color,
public form:Form) {}
toString() : string {return `SimpleObject(${this.size}, ${this.color}, ${this.form})`};
toStringAdv() : string {return `${this.size} ${this.color} ${this.form}`};
clone() : SimpleObject {return new SimpleObject(this.size, this.color, this.form)};
}
type Size = "small" | "large";
type Color = "red" | "black" | "blue" | "green" | "yellow" | "white";
type Form = "anyform" | "brick" | "plank" | "ball" | "pyramid" | "box" | "table" | "cup" | "floor"; // added floor for physical laws
//////////////////////////////////////////////////////////////////////
// Interpretations
export class DNFFormula {
constructor(public conjuncts : Conjunction[] = []) {}
toString() : string {return this.conjuncts.map((conj) => conj.toString()).join(" | ")};
}
export class Conjunction {
constructor(public literals : Literal[] = []) {}
toString() : string {return this.literals.map((lit) => lit.toString()).join(" & ")};
}
// A Literal represents a relation that is intended to hold among some objects.
export class Literal {
constructor(
public relation : string, // The name of the relation in question
public args : string[], // The arguments to the relation
public polarity : boolean = true, // Whether the literal is positive (true) or negative (false)
) {}
toString() : string {return (this.polarity ? "" : "-") + this.relation + "(" + this.args.join(",") + ")"};
}