summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2021-09-10 21:54:31 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2021-09-10 21:54:31 +0200
commit5320374c4e1340cc0cbfa6b2ec12523f38ace254 (patch)
tree7045aee9226e8c0b40cd992e3ea744f8a32e6025 /src
parent5474a765749d523b053a9dc6d7c15589a3fad8fc (diff)
Warning on dangerously named user content. (Blackjack example updated)
Diffstat (limited to 'src')
-rw-r--r--src/core/src/tonkadur/fate/v1/error/DangerouslyNamedUserContentException.java49
-rw-r--r--src/core/src/tonkadur/fate/v1/error/ErrorCategory.java2
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/meta/RecurrentChecks.java17
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateLexer.g410
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateParser.g430
-rw-r--r--src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java2
6 files changed, 107 insertions, 3 deletions
diff --git a/src/core/src/tonkadur/fate/v1/error/DangerouslyNamedUserContentException.java b/src/core/src/tonkadur/fate/v1/error/DangerouslyNamedUserContentException.java
new file mode 100644
index 0000000..91ac13a
--- /dev/null
+++ b/src/core/src/tonkadur/fate/v1/error/DangerouslyNamedUserContentException.java
@@ -0,0 +1,49 @@
+package tonkadur.fate.v1.error;
+
+import tonkadur.error.ErrorLevel;
+
+import tonkadur.parser.Origin;
+import tonkadur.parser.ParsingError;
+
+public class DangerouslyNamedUserContentException extends ParsingError
+{
+ /***************************************************************************/
+ /**** MEMBERS **************************************************************/
+ /***************************************************************************/
+ protected final String name;
+
+ /***************************************************************************/
+ /**** PUBLIC ***************************************************************/
+ /***************************************************************************/
+ public DangerouslyNamedUserContentException
+ (
+ final Origin origin,
+ final String name
+ )
+ {
+ super(ErrorLevel.WARNING, ErrorCategory.RECOMMENDATION, origin);
+
+ this.name = name;
+ }
+
+ @Override
+ public String toString ()
+ {
+ final StringBuilder sb = new StringBuilder();
+
+ sb.append(origin.toString());
+ sb.append(" ");
+ sb.append(error_category.toString());
+ sb.append(System.lineSeparator());
+
+ sb.append("In order to ensure support in future Fate versions, user");
+ sb.append("-created types, computations, and instructions should be");
+ sb.append(" prefixed by '#'.");
+ sb.append(System.lineSeparator());
+ sb.append("The name \"");
+ sb.append(name);
+ sb.append("\" is thus not recommended.");
+
+ return sb.toString();
+ }
+}
diff --git a/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java b/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java
index 20fac02..7bf80f8 100644
--- a/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java
+++ b/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java
@@ -8,6 +8,7 @@ public class ErrorCategory extends tonkadur.error.ErrorCategory
public static final ErrorCategory INCOMPATIBLE;
public static final ErrorCategory INVALID_USE;
public static final ErrorCategory MISSING_DECLARATION;
+ public static final ErrorCategory RECOMMENDATION;
public static final ErrorCategory UNKNOWN;
static
@@ -18,6 +19,7 @@ public class ErrorCategory extends tonkadur.error.ErrorCategory
INCOMPATIBLE = new ErrorCategory("incompatible");
INVALID_USE = new ErrorCategory("invalid_use");
MISSING_DECLARATION = new ErrorCategory("missing_declaration");
+ RECOMMENDATION = new ErrorCategory("recommendation");
UNKNOWN = new ErrorCategory("unknown");
}
diff --git a/src/core/src/tonkadur/fate/v1/lang/meta/RecurrentChecks.java b/src/core/src/tonkadur/fate/v1/lang/meta/RecurrentChecks.java
index 36513bf..4c701ab 100644
--- a/src/core/src/tonkadur/fate/v1/lang/meta/RecurrentChecks.java
+++ b/src/core/src/tonkadur/fate/v1/lang/meta/RecurrentChecks.java
@@ -16,6 +16,7 @@ import tonkadur.fate.v1.error.InvalidTypeException;
import tonkadur.fate.v1.error.InvalidArityException;
import tonkadur.fate.v1.error.SignatureTypeMismatchException;
import tonkadur.fate.v1.error.IncorrectReturnTypeException;
+import tonkadur.fate.v1.error.DangerouslyNamedUserContentException;
import tonkadur.fate.v1.lang.type.CollectionType;
import tonkadur.fate.v1.lang.type.LambdaType;
@@ -37,6 +38,22 @@ public class RecurrentChecks
return assert_can_be_used_as(a.get_origin(), a.get_type(), b.get_type());
}
+ public static void assert_has_user_content_prefix
+ (
+ final Origin origin,
+ final String name
+ )
+ throws ParsingError
+ {
+ if (!name.startsWith("#"))
+ {
+ ErrorManager.handle
+ (
+ new DangerouslyNamedUserContentException(origin, name)
+ );
+ }
+ }
+
public static Type assert_can_be_used_as
(
final Computation a,
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
index 42feda0..685c11f 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
@@ -37,6 +37,10 @@ DECLARE_TEXT_EFFECT_KW:
L_PAREN ('declare'|('def''ine'?))US'text'US'effect' SEP+;
DECLARE_GLOBAL_VARIABLE_KW: L_PAREN 'global' SEP+;
DECLARE_EXTERNAL_VARIABLE_KW: L_PAREN 'extern'('al'?) SEP+;
+DECLARE_INSTRUCTION_KW:
+ L_PAREN ('declare'|('def''ine'?))US'instruction' SEP+;
+DECLARE_COMPUTATION_KW:
+ L_PAREN ('declare'|('def''ine'?))US'computation' SEP+;
DEFINE_SEQUENCE_KW:
L_PAREN
@@ -144,7 +148,7 @@ fragment IDENTIFIER_FRAG: ~([ \t\r\n()]|'!');
IDENTIFIER_KW: IDENTIFIER_FRAG+;
-WORD: (IDENTIFIER_FRAG|'!'|'(lp)'|'(rp)'|'(sp)')+
+WORD: (IDENTIFIER_FRAG|'!'|'(lp)'|'(rp)'|'(sp)'|'(2;)')+
{
setText
(
@@ -160,6 +164,10 @@ WORD: (IDENTIFIER_FRAG|'!'|'(lp)'|'(rp)'|'(sp)')+
(
"\\(rp\\)",
")"
+ ).replaceAll
+ (
+ "\\(2;\\)",
+ ";;"
)
);
};
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
index 2aa2695..62de7e0 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
@@ -128,6 +128,12 @@ first_level_instruction
);
PARSER.get_world().types().add(new_type);
+
+ RecurrentChecks.assert_has_user_content_prefix
+ (
+ start_origin,
+ ($identifier.result)
+ );
}
| DECLARE_STRUCT_TYPE_KW identifier WS* variable_list WS* R_PAREN
@@ -159,6 +165,12 @@ first_level_instruction
);
PARSER.get_world().types().add(new_type);
+
+ RecurrentChecks.assert_has_user_content_prefix
+ (
+ start_origin,
+ ($identifier.result)
+ );
}
| DECLARE_EXTRA_INSTRUCTION_KW identifier maybe_type_list WS* R_PAREN
@@ -182,6 +194,12 @@ first_level_instruction
);
PARSER.get_world().extra_instructions().add(extra_instruction);
+
+ RecurrentChecks.assert_has_user_content_prefix
+ (
+ start_origin,
+ ($identifier.result)
+ );
}
| DECLARE_EXTRA_COMPUTATION_KW
@@ -210,6 +228,12 @@ first_level_instruction
);
PARSER.get_world().extra_computations().add(extra_computation);
+
+ RecurrentChecks.assert_has_user_content_prefix
+ (
+ start_origin,
+ ($identifier.result)
+ );
}
| DECLARE_EXTRA_TYPE_KW identifier WS+ argc=word WS+ comp=word WS* R_PAREN
@@ -299,6 +323,12 @@ first_level_instruction
{
Type.COMPARABLE_TYPES.add(new_type);
}
+
+ RecurrentChecks.assert_has_user_content_prefix
+ (
+ start_origin,
+ ($identifier.result)
+ );
}
| DECLARE_EVENT_TYPE_KW identifier maybe_type_list WS* R_PAREN
diff --git a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java
index 7d293cf..4c166ca 100644
--- a/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java
+++ b/src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java
@@ -49,8 +49,6 @@ public class TypeCompiler
if (fate_type instanceof tonkadur.fate.v1.lang.type.PointerType)
{
- System.out.println("Pointer type: " + fate_type.toString());
-
return
new PointerType
(