summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/src/tonkadur/RuntimeParameters.java35
-rw-r--r--src/core/src/tonkadur/error/Error.java (renamed from src/core/src/tonkadur/fate/v1/error/InputException.java)37
-rw-r--r--src/core/src/tonkadur/error/ErrorCategory.java28
-rw-r--r--src/core/src/tonkadur/error/ErrorLevel.java6
-rw-r--r--src/core/src/tonkadur/error/ErrorManager.java58
-rw-r--r--src/core/src/tonkadur/fate/v1/error/ErrorCategory.java26
-rw-r--r--src/core/src/tonkadur/fate/v1/error/TypeAlreadyDeclaredException.java14
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/Type.java128
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/World.java60
-rw-r--r--src/core/src/tonkadur/parser/Context.java (renamed from src/core/src/tonkadur/fate/v1/parser/Context.java)58
-rw-r--r--src/core/src/tonkadur/parser/ContextCycleException.java (renamed from src/core/src/tonkadur/fate/v1/error/ContextCycleException.java)14
-rw-r--r--src/core/src/tonkadur/parser/Location.java (renamed from src/core/src/tonkadur/fate/v1/parser/Location.java)2
-rw-r--r--src/core/src/tonkadur/parser/Origin.java (renamed from src/core/src/tonkadur/fate/v1/parser/Origin.java)2
-rw-r--r--src/core/src/tonkadur/parser/ParsingError.java21
14 files changed, 427 insertions, 62 deletions
diff --git a/src/core/src/tonkadur/RuntimeParameters.java b/src/core/src/tonkadur/RuntimeParameters.java
new file mode 100644
index 0000000..28a7416
--- /dev/null
+++ b/src/core/src/tonkadur/RuntimeParameters.java
@@ -0,0 +1,35 @@
+package tonkadur;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import tonkadur.error.ErrorCategory;
+
+public class RuntimeParameters
+{
+ protected static final Collection<ErrorCategory> disabled_errors;
+ protected static final Collection<ErrorCategory> tolerated_errors;
+ protected static boolean consider_warnings_as_errors;
+
+ static
+ {
+ disabled_errors = new HashSet<ErrorCategory>();
+ tolerated_errors = new HashSet<ErrorCategory>();
+ consider_warnings_as_errors = false;
+ }
+
+ public static boolean error_is_disabled (final ErrorCategory category)
+ {
+ return disabled_errors.contains(category);
+ }
+
+ public static boolean error_is_tolerated (final ErrorCategory category)
+ {
+ return tolerated_errors.contains(category);
+ }
+
+ public static boolean warnings_are_errors ()
+ {
+ return consider_warnings_as_errors;
+ }
+}
diff --git a/src/core/src/tonkadur/fate/v1/error/InputException.java b/src/core/src/tonkadur/error/Error.java
index 71b1878..103e428 100644
--- a/src/core/src/tonkadur/fate/v1/error/InputException.java
+++ b/src/core/src/tonkadur/error/Error.java
@@ -1,9 +1,6 @@
-package tonkadur.fate.v1.error;
+package tonkadur.error;
-import tonkadur.fate.v1.parser.Context;
-import tonkadur.fate.v1.parser.Origin;
-
-abstract class InputException extends Throwable
+public abstract class Error extends Throwable
{
/***************************************************************************/
/**** STATIC MEMBERS *******************************************************/
@@ -13,28 +10,32 @@ abstract class InputException extends Throwable
/***************************************************************************/
/**** MEMBERS **************************************************************/
/***************************************************************************/
- protected Origin origin;
+ protected final ErrorLevel error_level;
+ protected final ErrorCategory error_category;
/***************************************************************************/
- /**** PUBLIC ***************************************************************/
+ /**** PRIVATE **************************************************************/
/***************************************************************************/
- public void set_origin (final Origin origin)
+ protected Error
+ (
+ final ErrorLevel error_level,
+ final ErrorCategory error_category
+ )
{
- this.origin = origin;
+ this.error_level = error_level;
+ this.error_category = error_category;
}
- public void set_origin
- (
- final Context context,
- final int line,
- final int column
- )
+ /***************************************************************************/
+ /**** PUBLIC ***************************************************************/
+ /***************************************************************************/
+ public ErrorLevel get_error_level ()
{
- origin = context.get_origin_at(line, column);
+ return error_level;
}
- public Origin get_origin ()
+ public ErrorCategory get_error_category ()
{
- return origin;
+ return error_category;
}
}
diff --git a/src/core/src/tonkadur/error/ErrorCategory.java b/src/core/src/tonkadur/error/ErrorCategory.java
new file mode 100644
index 0000000..122cff3
--- /dev/null
+++ b/src/core/src/tonkadur/error/ErrorCategory.java
@@ -0,0 +1,28 @@
+package tonkadur.error;
+
+public class ErrorCategory
+{
+ public static final ErrorCategory INVALID_INPUT;
+ public static final ErrorCategory PROGRAMMING_ERROR;
+ public static final ErrorCategory FILE_ACCESS;
+
+ static
+ {
+ INVALID_INPUT = new ErrorCategory("Invalid Input");
+ PROGRAMMING_ERROR = new ErrorCategory("Programming Error");
+ FILE_ACCESS = new ErrorCategory("File Access");
+ }
+
+ protected final String name;
+
+ protected ErrorCategory (final String name)
+ {
+ this.name = name;
+ }
+
+ @Override
+ public String toString()
+ {
+ return name;
+ }
+}
diff --git a/src/core/src/tonkadur/error/ErrorLevel.java b/src/core/src/tonkadur/error/ErrorLevel.java
new file mode 100644
index 0000000..0cddaae
--- /dev/null
+++ b/src/core/src/tonkadur/error/ErrorLevel.java
@@ -0,0 +1,6 @@
+package tonkadur.error;
+
+public enum ErrorLevel
+{
+ WARNING, ERROR, FATAL
+}
diff --git a/src/core/src/tonkadur/error/ErrorManager.java b/src/core/src/tonkadur/error/ErrorManager.java
new file mode 100644
index 0000000..13c9c3f
--- /dev/null
+++ b/src/core/src/tonkadur/error/ErrorManager.java
@@ -0,0 +1,58 @@
+package tonkadur.error;
+
+import tonkadur.RuntimeParameters;
+
+public class ErrorManager
+{
+ /* Utility class */
+ private ErrorManager () {};
+
+ public static <CustomError extends Error>
+ void handle (final CustomError error)
+ throws CustomError
+ {
+ final ErrorCategory error_category;
+ ErrorLevel error_level;
+
+ error_category = error.get_error_category();
+
+ if (RuntimeParameters.error_is_disabled(error_category))
+ {
+ return;
+ }
+
+ error_level = error.get_error_level();
+
+ if
+ (
+ (error_level == ErrorLevel.WARNING)
+ && RuntimeParameters.warnings_are_errors()
+ )
+ {
+ error_level = ErrorLevel.ERROR;
+ }
+
+ if
+ (
+ (error_level == ErrorLevel.ERROR)
+ && RuntimeParameters.error_is_tolerated(error_category)
+ )
+ {
+ error_level = ErrorLevel.WARNING;
+ }
+
+ switch (error_level)
+ {
+ case WARNING:
+ System.err.println(error.toString());
+ break;
+
+ case ERROR:
+ throw error;
+
+ case FATAL:
+ System.err.println(error.toString());
+ System.exit(-1);
+ }
+ }
+}
diff --git a/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java b/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java
new file mode 100644
index 0000000..f56b6d5
--- /dev/null
+++ b/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java
@@ -0,0 +1,26 @@
+package tonkadur.fate.v1.error;
+
+class ErrorCategory extends tonkadur.error.ErrorCategory
+{
+ public static final ErrorCategory DUPLICATE_DECLARATION;
+ public static final ErrorCategory CONFLICTING_DECLARATION;
+ public static final ErrorCategory UNDECLARED;
+ public static final ErrorCategory UNKNOWN_SEQUENCE;
+ public static final ErrorCategory INCORRECT_TYPE;
+ public static final ErrorCategory INCOMPATIBLE_TYPE;
+
+ static
+ {
+ DUPLICATE_DECLARATION = new ErrorCategory("duplicate_declaration");
+ CONFLICTING_DECLARATION = new ErrorCategory("conflicting_declaration");
+ UNDECLARED = new ErrorCategory("undeclared");
+ UNKNOWN_SEQUENCE = new ErrorCategory("unknown_sequence");
+ INCORRECT_TYPE = new ErrorCategory("incorrect_type");
+ INCOMPATIBLE_TYPE = new ErrorCategory("incompatible_type");
+ }
+
+ private ErrorCategory (final String name)
+ {
+ super(name);
+ }
+}
diff --git a/src/core/src/tonkadur/fate/v1/error/TypeAlreadyDeclaredException.java b/src/core/src/tonkadur/fate/v1/error/TypeAlreadyDeclaredException.java
index b028127..4050d1e 100644
--- a/src/core/src/tonkadur/fate/v1/error/TypeAlreadyDeclaredException.java
+++ b/src/core/src/tonkadur/fate/v1/error/TypeAlreadyDeclaredException.java
@@ -1,8 +1,13 @@
package tonkadur.fate.v1.error;
+import tonkadur.error.ErrorLevel;
+
+import tonkadur.parser.Origin;
+import tonkadur.parser.ParsingError;
+
import tonkadur.fate.v1.lang.Type;
-public class TypeAlreadyDeclaredException extends InputException
+public class TypeAlreadyDeclaredException extends ParsingError
{
/***************************************************************************/
/**** MEMBERS **************************************************************/
@@ -12,8 +17,13 @@ public class TypeAlreadyDeclaredException extends InputException
/***************************************************************************/
/**** PUBLIC ***************************************************************/
/***************************************************************************/
- public TypeAlreadyDeclaredException (final Type original_type)
+ public TypeAlreadyDeclaredException
+ (
+ final Origin origin,
+ final Type original_type
+ )
{
+ super(ErrorLevel.WARNING, ErrorCategory.DUPLICATE_DECLARATION, origin);
this.original_type = original_type;
}
diff --git a/src/core/src/tonkadur/fate/v1/lang/Type.java b/src/core/src/tonkadur/fate/v1/lang/Type.java
new file mode 100644
index 0000000..2990dc0
--- /dev/null
+++ b/src/core/src/tonkadur/fate/v1/lang/Type.java
@@ -0,0 +1,128 @@
+package tonkadur.fate.v1.lang;
+
+import tonkadur.parser.Origin;
+
+public class Type
+{
+ /***************************************************************************/
+ /**** MEMBERS **************************************************************/
+ /***************************************************************************/
+ protected final Origin origin;
+ protected final String name;
+ protected final Type true_type;
+ protected final Type parent;
+
+ /***************************************************************************/
+ /**** PUBLIC ***************************************************************/
+ /***************************************************************************/
+
+ /**** Constructors *********************************************************/
+ public Type
+ (
+ final Origin origin,
+ final Type parent,
+ final String name
+ )
+ {
+ if (parent == null)
+ {
+ true_type = this;
+ }
+ else
+ {
+ true_type = parent.true_type;
+ }
+
+ this.origin = origin;
+ this.parent = parent;
+ this.name = name;
+ }
+
+ /**** Accessors ************************************************************/
+ public String get_name ()
+ {
+ return name;
+ }
+
+ public Origin get_origin ()
+ {
+ return origin;
+ }
+
+ public Type get_true_type ()
+ {
+ return true_type;
+ }
+
+ public boolean is_base_type ()
+ {
+ return (parent == null);
+ }
+
+ /**** Compatibility ********************************************************/
+ public boolean can_be_used_as (final Type t)
+ {
+ if (!true_type.equals(t.true_type))
+ {
+ return false;
+ }
+
+ return this_or_parent_equals(t);
+ }
+
+ /**** Misc. ****************************************************************/
+ @Override
+ public boolean equals (final Object o)
+ {
+ if (o instanceof Type)
+ {
+ final Type t;
+
+ t = (Type) o;
+
+ return name.equals(t.name);
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode ()
+ {
+ return name.hashCode();
+ }
+
+ @Override
+ public String toString ()
+ {
+ final StringBuilder sb = new StringBuilder();
+
+ if (parent != null)
+ {
+ sb.append(parent.toString());
+ sb.append("::");
+ }
+
+ sb.append(name);
+
+ return sb.toString();
+ }
+
+ /***************************************************************************/
+ /**** PROTECTED ************************************************************/
+ /***************************************************************************/
+ protected boolean this_or_parent_equals (final Type t)
+ {
+ if (equals(t))
+ {
+ return true;
+ }
+
+ if (parent == null)
+ {
+ return false;
+ }
+
+ return parent.this_or_parent_equals(t);
+ }
+}
diff --git a/src/core/src/tonkadur/fate/v1/lang/World.java b/src/core/src/tonkadur/fate/v1/lang/World.java
index fb0f0fe..cd42f55 100644
--- a/src/core/src/tonkadur/fate/v1/lang/World.java
+++ b/src/core/src/tonkadur/fate/v1/lang/World.java
@@ -11,10 +11,10 @@ public class World
/**** MEMBERS **************************************************************/
/***************************************************************************/
protected final Collection<String> loaded_files;
- protected final Collection<String> text_effects;
protected final Map<String, Event> events;
protected final Map<String, Macro> macros;
protected final Map<String, Sequence> sequences;
+ protected final Map<String, TextEffect> text_effects;
protected final Map<String, Type> types;
protected final Map<String, Variable> variables;
@@ -26,18 +26,15 @@ public class World
public World ()
{
loaded_files = new HashSet<String>();
- text_effects = new HashSet<String>();
events = new HashMap<String, Event>();
macros = new HashMap<String, Macro>();
sequences = new HashMap<String, Sequence>();
+ text_effects = new HashMap<String, TextEffect>();
types = new HashMap<String, Type>();
variables = new HashMap<String, Variable>();
- for (final Type t: Type.BASE_TYPES)
- {
- types.add(t.get_name(), t);
- }
+ add_base_types();
}
/**** Accessors ************************************************************/
@@ -57,23 +54,6 @@ public class World
loaded_files.add(name);
}
- /**** Text Effects ****/
- public Collection<String> get_text_effects ()
- {
- return text_effects.clone();
- }
-
- public boolean has_text_effect (final String name)
- {
- return text_effects.contains(name);
- }
-
- public void add_text_effect (final String name)
- throws TextEffectAlreadyDeclaredException
- {
- text_effects.add(name);
- }
-
/**** Events ****/
public Collection<Event> get_events ()
{
@@ -85,15 +65,43 @@ public class World
return events.containsKey(name);
}
- public void add_event (final String name, final List<Type> parameter_types)
+ public void add_event
+ (
+ final Origin origin,
+ final String name,
+ final List<Type> parameter_types
+ )
throws EventAlreadyDeclaredException, UnknownTypeException
{
-
+ if (has_event(name))
+ {
+
+ }
+ for (final Type t: parameter_types)
+ {
+ if (!has_type(t))
+ {
+ throw new UnknownTypeException()
+ }
+ }
}
/**** Misc. ****************************************************************/
/***************************************************************************/
- /**** PRIVATE **************************************************************/
+ /**** PROTECTED ************************************************************/
/***************************************************************************/
+ protected void add_base_types ()
+ {
+ final Origin base;
+
+ base = new Origin(new Context(""), Location.BASE_LANGUAGE);
+
+ add_type(base, null, "dict");
+ add_type(base, null, "float");
+ add_type(base, null, "int");
+ add_type(base, null, "list");
+ add_type(base, null, "set");
+ add_type(base, null, "string");
+ }
}
diff --git a/src/core/src/tonkadur/fate/v1/parser/Context.java b/src/core/src/tonkadur/parser/Context.java
index 3ad958d..f579318 100644
--- a/src/core/src/tonkadur/fate/v1/parser/Context.java
+++ b/src/core/src/tonkadur/parser/Context.java
@@ -1,15 +1,12 @@
-package tonkadur.fate.v1.parser;
+package tonkadur.parser;
import java.util.Stack;
-import tonkadur.fate.v1.error.ContextCycleException;
-
public class Context
{
/***************************************************************************/
/**** MEMBERS **************************************************************/
/***************************************************************************/
- protected final boolean locked;
protected final Stack<Location> source;
protected String current_file;
@@ -20,7 +17,6 @@ public class Context
/**** Constructors *********************************************************/
public Context (final String filename)
{
- locked = false;
source = new Stack<Location>();
current_file = filename;
}
@@ -29,7 +25,7 @@ public class Context
public void push (final Location location, final String new_file)
throws ContextCycleException
{
- throw_exception_on_cycle(new_file);
+ throw_exception_on_cycle(location, new_file);
current_file = new_file;
@@ -45,7 +41,12 @@ public class Context
/**** Utils ****************************************************************/
public Origin get_origin_at (final int line, final int column)
{
- return new Origin(this, new Location(current_file, line, column));
+ return new Origin(clone(), new Location(current_file, line, column));
+ }
+
+ public Origin get_origin_at (final Location location)
+ {
+ return new Origin(clone(), location);
}
/**** Misc. ****************************************************************/
@@ -94,10 +95,35 @@ public class Context
return (source.hashCode() + current_file.hashCode());
}
+ @Override
+ public Context clone ()
+ {
+ final Context result;
+
+ result = new Context("");
+
+ /*
+ * That's in FIFO order, as we want it to be, due to arguable design
+ * decisions in Java.
+ */
+ for (final Location location: source)
+ {
+ result.source.push(location);
+ }
+
+ result.current_file = current_file;
+
+ return result;
+ }
+
/***************************************************************************/
/**** PROTECTED ************************************************************/
/***************************************************************************/
- protected void throw_exception_on_cycle (final String new_file)
+ protected void throw_exception_on_cycle
+ (
+ final Location declared_at,
+ final String new_file
+ )
throws ContextCycleException
{
Location previous_import;
@@ -112,7 +138,13 @@ public class Context
{
if (location.get_filename().equals(new_file))
{
- throw new ContextCycleException(previous_import, new_file);
+ throw
+ new ContextCycleException
+ (
+ get_origin_at(declared_at),
+ previous_import,
+ new_file
+ );
}
previous_import = location;
@@ -120,7 +152,13 @@ public class Context
if (current_file.equals(new_file))
{
- throw new ContextCycleException(previous_import, new_file);
+ throw
+ new ContextCycleException
+ (
+ get_origin_at(declared_at),
+ previous_import,
+ new_file
+ );
}
}
}
diff --git a/src/core/src/tonkadur/fate/v1/error/ContextCycleException.java b/src/core/src/tonkadur/parser/ContextCycleException.java
index c5a2434..a7f6314 100644
--- a/src/core/src/tonkadur/fate/v1/error/ContextCycleException.java
+++ b/src/core/src/tonkadur/parser/ContextCycleException.java
@@ -1,9 +1,12 @@
-package tonkadur.fate.v1.error;
+package tonkadur.parser;
-import tonkadur.fate.v1.parser.Location;
-import tonkadur.fate.v1.parser.Origin;
+import tonkadur.parser.Location;
+import tonkadur.parser.Origin;
-public class ContextCycleException extends InputException
+import tonkadur.error.ErrorCategory;
+import tonkadur.error.ErrorLevel;
+
+class ContextCycleException extends ParsingError
{
/***************************************************************************/
/**** MEMBERS **************************************************************/
@@ -20,10 +23,13 @@ public class ContextCycleException extends InputException
/***************************************************************************/
public ContextCycleException
(
+ final Origin origin,
final Location original_require_location,
final String filename
)
{
+ super(ErrorLevel.FATAL, ErrorCategory.INVALID_INPUT, origin);
+
this.original_require_location = original_require_location;
this.filename = filename;
}
diff --git a/src/core/src/tonkadur/fate/v1/parser/Location.java b/src/core/src/tonkadur/parser/Location.java
index 98f407d..ea6989b 100644
--- a/src/core/src/tonkadur/fate/v1/parser/Location.java
+++ b/src/core/src/tonkadur/parser/Location.java
@@ -1,4 +1,4 @@
-package tonkadur.fate.v1.parser;
+package tonkadur.parser;
public class Location
{
diff --git a/src/core/src/tonkadur/fate/v1/parser/Origin.java b/src/core/src/tonkadur/parser/Origin.java
index cd4b784..9fa7939 100644
--- a/src/core/src/tonkadur/fate/v1/parser/Origin.java
+++ b/src/core/src/tonkadur/parser/Origin.java
@@ -1,4 +1,4 @@
-package tonkadur.fate.v1.parser;
+package tonkadur.parser;
public class Origin
{
diff --git a/src/core/src/tonkadur/parser/ParsingError.java b/src/core/src/tonkadur/parser/ParsingError.java
new file mode 100644
index 0000000..5d8bbe5
--- /dev/null
+++ b/src/core/src/tonkadur/parser/ParsingError.java
@@ -0,0 +1,21 @@
+package tonkadur.parser;
+
+import tonkadur.error.Error;
+import tonkadur.error.ErrorCategory;
+import tonkadur.error.ErrorLevel;
+
+public abstract class ParsingError extends Error
+{
+ protected final Origin origin;
+
+ protected ParsingError
+ (
+ final ErrorLevel error_level,
+ final ErrorCategory error_category,
+ final Origin origin
+ )
+ {
+ super(error_level, error_category);
+ this.origin = origin;
+ }
+}