summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2020-07-11 15:37:46 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2020-07-11 15:37:46 +0200
commite9f9708a43fa6030a943478f203f08fc37aa28ec (patch)
tree2136140a155362e33b60cb4bfcfa358a0de5b358
parent88657c6dba477efeb42dd1b94d7636f5633b38d4 (diff)
...
-rw-r--r--data/examples/the_thief/include/characters.fate61
-rw-r--r--data/examples/the_thief/include/locations.fate2
-rw-r--r--data/examples/the_thief/include/type/character.fate12
-rw-r--r--data/examples/the_thief/include/type/location.fate3
-rw-r--r--data/examples/the_thief/include/type/stat.fate3
-rw-r--r--data/examples/the_thief/main.fate47
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/RefOperator.java44
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/RefType.java91
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/Type.java3
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateLexer.g43
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateParser.g424
11 files changed, 293 insertions, 0 deletions
diff --git a/data/examples/the_thief/include/characters.fate b/data/examples/the_thief/include/characters.fate
new file mode 100644
index 0000000..4c36a8e
--- /dev/null
+++ b/data/examples/the_thief/include/characters.fate
@@ -0,0 +1,61 @@
+(fate_version 1)
+
+(require include/type/character.fate)
+
+(declare_variable local character oscar)
+(declare_variable local character carla)
+(declare_variable local character simon)
+(declare_variable local character julie)
+(declare_variable local character statue)
+
+(require include/locations.fate)
+
+(set_fields
+ (name Oscar)
+ (agility 50)
+ (perception 50)
+ (money 20)
+ (location room0)
+ (variable oscar)
+)
+
+(set_fields
+ (name Carla)
+ (agility 75)
+ (perception 35)
+ (money 7)
+ (location room1)
+ (variable carla)
+)
+
+(set_fields
+ (name Simon)
+ (agility 35)
+ (perception 75)
+ (money 80)
+ (location room1)
+ (variable simon)
+)
+
+(set_fields
+ (name Julie)
+ (agility 60)
+ (perception 60)
+ (money 90)
+ (location room2)
+ (variable julie)
+)
+
+(set_fields
+ (name ( A oddly human shaped statue, with clothes adorned ))
+ (agility 0)
+ (perception 0)
+ (money 30)
+ (location corridor)
+ (variable statue)
+)
+
+;; Alright, but we clearly need to be able to point to variables using a type.
+;; like (pointer (variable carla)) -> pointer to variable of type character
+;; (a string, really) resolves to (variable carla), but allows characters to be
+;; put in a set, for example.
diff --git a/data/examples/the_thief/include/locations.fate b/data/examples/the_thief/include/locations.fate
new file mode 100644
index 0000000..d7beb18
--- /dev/null
+++ b/data/examples/the_thief/include/locations.fate
@@ -0,0 +1,2 @@
+(fate_version 1)
+
diff --git a/data/examples/the_thief/include/type/character.fate b/data/examples/the_thief/include/type/character.fate
new file mode 100644
index 0000000..e3b1b7b
--- /dev/null
+++ b/data/examples/the_thief/include/type/character.fate
@@ -0,0 +1,12 @@
+(fate_version 1)
+
+(require include/type/stat.fate)
+(require include/type/location.fate)
+
+(declare_dict_type character
+ (string name)
+ (stat agility)
+ (stat perception)
+ (int money)
+ (location location)
+)
diff --git a/data/examples/the_thief/include/type/location.fate b/data/examples/the_thief/include/type/location.fate
new file mode 100644
index 0000000..faec74a
--- /dev/null
+++ b/data/examples/the_thief/include/type/location.fate
@@ -0,0 +1,3 @@
+(fate_version 1)
+
+(declare_set_type string location)
diff --git a/data/examples/the_thief/include/type/stat.fate b/data/examples/the_thief/include/type/stat.fate
new file mode 100644
index 0000000..c2e0feb
--- /dev/null
+++ b/data/examples/the_thief/include/type/stat.fate
@@ -0,0 +1,3 @@
+(fate_version 1)
+
+(declare_subtype int stat)
diff --git a/data/examples/the_thief/main.fate b/data/examples/the_thief/main.fate
new file mode 100644
index 0000000..66773c2
--- /dev/null
+++ b/data/examples/the_thief/main.fate
@@ -0,0 +1,47 @@
+(fate_version 1)
+
+(require include/text_effects.fate)
+(require include/characters.fate)
+(require include/chapters.fate)
+
+(text_effect narrator
+ As the last lights of the day vanish, you bid farewell to a sun you hope
+ will not recognize you next morning, for tonight is the time of your
+ transformation. Tonight, you put an end to the hunger. Tonight, you put an
+ end to the cold. Tonight, surely, you get to claim the luck you were denied
+ all this time.
+ (newline)
+ As you gaze upon the magnificent Tarmock manor, any trace of hesitation
+ disappears. The plan is simple: your forged letter of introduction will get
+ you through the door, and your lifelong skills through their purses.
+)
+
+(sequence standing_before_the_manor)
+
+(cond
+ ((= 3 (variable oscar.money)) ...don't...)
+ ((> 3 (variable carla.agility)) ...might...)
+ ((> 3 (variable carla.perception)) ...surely...)
+)
+
+(= lol
+ (cond
+ ((= 3 (variable oscar.money)) ...don't...)
+ ((> 3 (variable carla.agility)) ...might...)
+ ((> 3 (variable carla.perception)) ...surely...)
+ )
+)
+Tonight's the night... (newline)
+Tonight, we become rich... (newline)
+Tonight, we...
+
+(player_choice
+ (
+ ( ...get in through the window! )
+ (sequence through_the_window)
+ )
+ (
+ ( ...knock at the door! )
+ (sequence knocking_on_door)
+ )
+)
diff --git a/src/core/src/tonkadur/fate/v1/lang/RefOperator.java b/src/core/src/tonkadur/fate/v1/lang/RefOperator.java
new file mode 100644
index 0000000..f55be22
--- /dev/null
+++ b/src/core/src/tonkadur/fate/v1/lang/RefOperator.java
@@ -0,0 +1,44 @@
+package tonkadur.fate.v1.lang;
+
+import tonkadur.parser.Origin;
+
+import tonkadur.fate.v1.lang.meta.ValueNode;
+
+public class RefOperator extends ValueNode
+{
+ /***************************************************************************/
+ /**** MEMBERS **************************************************************/
+ /***************************************************************************/
+ protected final Variable variable;
+
+ /***************************************************************************/
+ /**** PROTECTED ************************************************************/
+ /***************************************************************************/
+ /**** Constructors *********************************************************/
+ public RefOperator (final Origin origin, final Variable variable)
+ {
+ super(origin, new RefType(origin, variable.get_type(), "auto generated"));
+ this.variable = variable;
+ }
+
+ /***************************************************************************/
+ /**** PUBLIC ***************************************************************/
+ /***************************************************************************/
+ /**** Constructors *********************************************************/
+
+ /**** Accessors ************************************************************/
+
+ /**** Misc. ****************************************************************/
+ @Override
+ public String toString ()
+ {
+ final StringBuilder sb = new StringBuilder();
+
+ sb.append(origin.toString());
+ sb.append("(Ref ");
+ sb.append(variable.get_name());
+ sb.append(") ");
+
+ return sb.toString();
+ }
+}
diff --git a/src/core/src/tonkadur/fate/v1/lang/RefType.java b/src/core/src/tonkadur/fate/v1/lang/RefType.java
new file mode 100644
index 0000000..4d0429e
--- /dev/null
+++ b/src/core/src/tonkadur/fate/v1/lang/RefType.java
@@ -0,0 +1,91 @@
+package tonkadur.fate.v1.lang;
+
+import tonkadur.parser.Origin;
+
+import tonkadur.fate.v1.lang.meta.DeclaredEntity;
+
+public class RefType extends Type
+{
+ /***************************************************************************/
+ /**** MEMBERS **************************************************************/
+ /***************************************************************************/
+ protected final Type referenced_type;
+
+ /***************************************************************************/
+ /**** PUBLIC ***************************************************************/
+ /***************************************************************************/
+
+ /**** Constructors *********************************************************/
+ public RefType
+ (
+ final Origin origin,
+ final Type referenced_type,
+ final String name
+ )
+ {
+ super(origin, Type.REF, name);
+
+ this.referenced_type = referenced_type;
+ }
+
+ /**** Accessors ************************************************************/
+ public referenced_type get_referenced_type ()
+ {
+ return referenced_type;
+ }
+
+ /**** Compatibility ********************************************************/
+ @Override
+ public boolean can_be_used_as (final Type t)
+ {
+ if (t instanceof RefType)
+ {
+ final RefType dt;
+
+ dt = (RefType) t;
+
+ return referenced_type.can_be_used_as(dt.referenced_type);
+ }
+
+ return false;
+ }
+
+ /*
+ * This is for the very special case where a type is used despite not being
+ * even a sub-type of the expected one. Using this rather expensive function,
+ * the most restrictive shared type will be returned. If no such type exists,
+ * the ANY time is returned.
+ */
+ @Override
+ public DeclaredEntity generate_comparable_to (final DeclaredEntity de)
+ {
+ final Type resulting_referenced_type;
+ final RefType dt;
+
+ if (!(de instanceof RefType))
+ {
+ return Type.ANY;
+ }
+
+ dt = (RefType) de;
+ resulting_referenced_type =
+ (Type) referenced_type.generate_comparable_to(de.referenced_type);
+
+ return new RefType(get_origin(), resulting_referenced_type, name);
+ }
+
+
+ /**** Misc. ****************************************************************/
+ @Override
+ public String toString ()
+ {
+ final StringBuilder sb = new StringBuilder();
+
+ sb.append("(Ref to ");
+ sb.append(resulting_referenced_type.toString())
+ sb.append(")::");
+ sb.append(name);
+
+ return sb.toString();
+ }
+}
diff --git a/src/core/src/tonkadur/fate/v1/lang/Type.java b/src/core/src/tonkadur/fate/v1/lang/Type.java
index d08b699..129f08b 100644
--- a/src/core/src/tonkadur/fate/v1/lang/Type.java
+++ b/src/core/src/tonkadur/fate/v1/lang/Type.java
@@ -26,6 +26,7 @@ public class Type extends DeclaredEntity
public static final Type INT;
public static final Type LIST;
public static final Type SET;
+ public static final Type REF;
public static final Type STRING;
public static final Set<Type> NUMBER_TYPES;
@@ -48,6 +49,7 @@ public class Type extends DeclaredEntity
INT = new Type(base, null, "int");
LIST = new Type(base, null, "list");
SET = new Type(base, null, "set");
+ REF = new Type(base, null, "ref");
STRING = new Type(base, null, "string");
NUMBER_TYPES = new HashSet<Type>();
@@ -60,6 +62,7 @@ public class Type extends DeclaredEntity
SIMPLE_BASE_TYPES.add(INT);
SIMPLE_BASE_TYPES.add(STRING);
SIMPLE_BASE_TYPES.add(BOOLEAN);
+ SIMPLE_BASE_TYPES.add(REF);
}
public static Type value_on_missing ()
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
index 6042ebc..f8fe10f 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
@@ -24,6 +24,7 @@ DECLARE_ALIAS_TYPE_KW: L_PAREN 'declare_subtype';
DECLARE_DICT_TYPE_KW: L_PAREN 'declare_dict_type';
DECLARE_EVENT_TYPE_KW: L_PAREN 'declare_event_type';
DECLARE_LIST_TYPE_KW: L_PAREN 'declare_list_type';
+DECLARE_REF_TYPE_KW: L_PAREN 'declare_ref_type';
DECLARE_SET_TYPE_KW: L_PAREN 'declare_set_type';
DECLARE_TEXT_EFFECT_KW: L_PAREN 'declare_text_effect';
DECLARE_VARIABLE_KW: L_PAREN 'declare_variable';
@@ -58,6 +59,7 @@ PLAYER_CHOICE_KW: L_PAREN ('choice'|'user_choice'|'player_choice');
PLUS_KW: L_PAREN ('plus'|'+');
POWER_KW: L_PAREN ('power'|'^'|'**');
RANDOM_KW: L_PAREN ('random'|'rand');
+REF_KW: L_PAREN 'ref';
REMOVE_ALL_KW: L_PAREN 'remove_all';
REMOVE_ONE_KW: L_PAREN 'remove_one';
REQUIRE_EXTENSION_KW: L_PAREN 'require_extension';
@@ -68,6 +70,7 @@ SET_FIELDS_KW: L_PAREN 'set_fields';
SET_KW: L_PAREN 'set';
TIMES_KW: L_PAREN ('times'|'*');
TRUE_KW: L_PAREN 'true)';
+VAL_KW: L_PAREN 'val';
VARIABLE_KW: L_PAREN 'variable';
WORD: (~([ \t\r\n()])|'\\)'|'\\(')+;
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
index 12981cb..cc33b07 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
@@ -249,6 +249,30 @@ first_level_fate_instr:
WORLD.types().add(new_type);
}
+ | DECLARE_REF_TYPE_KW WS+ parent=type WS+ new_reference_name WS* R_PAREN
+ {
+ final Origin start_origin;
+ final Type new_type;
+
+ start_origin =
+ CONTEXT.get_origin_at
+ (
+ ($DECLARE_LIST_TYPE_KW.getLine()),
+ ($DECLARE_LIST_TYPE_KW.getCharPositionInLine())
+ );
+
+ new_type =
+ new RefType
+ (
+ start_origin,
+ ($parent.result),
+ false,
+ ($new_reference_name.result)
+ );
+
+ WORLD.types().add(new_type);
+ }
+
| DECLARE_DICT_TYPE_KW
WS+
new_reference_name