| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-08-25 21:59:00 +0200 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-08-25 21:59:00 +0200 | 
| commit | f745cf10b898eafbe4fe781b05d243d5e32f72bc (patch) | |
| tree | c2d27ab1cdd475573db09add1d2d73d7bb211e1a /src/core | |
| parent | 9845105fca628a2d9edec520deba326c39584a8a (diff) | |
| parent | e620e366e5ffb90aa0ae321872e970c7de30b236 (diff) | |
Merge branch 'master' of dreamhost:~/repositories/git/tonkadur
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/src/tonkadur/Main.java | 12 | ||||
| -rw-r--r-- | src/core/src/tonkadur/RuntimeParameters.java | 140 | ||||
| -rw-r--r-- | src/core/src/tonkadur/TonkadurPlugin.java | 4 | ||||
| -rw-r--r-- | src/core/src/tonkadur/error/ErrorCategory.java | 20 | ||||
| -rw-r--r-- | src/core/src/tonkadur/fate/v1/Base.java | 11 | ||||
| -rw-r--r-- | src/core/src/tonkadur/fate/v1/error/ErrorCategory.java | 7 | ||||
| -rw-r--r-- | src/core/src/tonkadur/wyrd/v1/Base.java | 9 | 
7 files changed, 201 insertions, 2 deletions
| diff --git a/src/core/src/tonkadur/Main.java b/src/core/src/tonkadur/Main.java index de37ba8..abf59d0 100644 --- a/src/core/src/tonkadur/Main.java +++ b/src/core/src/tonkadur/Main.java @@ -21,15 +21,25 @@ public class Main        final tonkadur.wyrd.v1.lang.World wyrd_world;        final Context context; +      tonkadur.fate.v1.Base.initialize(); +      tonkadur.wyrd.v1.Base.initialize(); +        plugins = TonkadurPlugin.get_plugins(); +      if (!RuntimeParameters.parse_options(args)) +      { +         RuntimeParameters.print_usage(plugins); + +         return; +      } +        for (final TonkadurPlugin tp: plugins)        {           tp.initialize(args);        }        fate_world = new tonkadur.fate.v1.lang.World(); -      context = Context.build(args[0]); +      context = Context.build(RuntimeParameters.get_input_file());        for (final TonkadurPlugin tp: plugins)        { diff --git a/src/core/src/tonkadur/RuntimeParameters.java b/src/core/src/tonkadur/RuntimeParameters.java index 2c434d2..bf72b04 100644 --- a/src/core/src/tonkadur/RuntimeParameters.java +++ b/src/core/src/tonkadur/RuntimeParameters.java @@ -1,8 +1,10 @@  package tonkadur;  import java.util.ArrayList; +import java.util.Arrays;  import java.util.Collection;  import java.util.HashSet; +import java.util.Iterator;  import java.util.List;  import tonkadur.error.ErrorCategory; @@ -13,6 +15,7 @@ public class RuntimeParameters     protected static final Collection<ErrorCategory> disabled_errors;     protected static final Collection<ErrorCategory> tolerated_errors;     protected static boolean consider_warnings_as_errors; +   protected static String target_file;     static     { @@ -42,8 +45,145 @@ public class RuntimeParameters        return include_directories;     } +   public static String get_input_file () +   { +      return target_file; +   } +     public static void add_include_directory (final String name)     {        include_directories.add(name);     } + +   public static void print_usage +   ( +      final Collection<TonkadurPlugin> plugins +   ) +   { +      System.out.println("Usage: tonkadur [<options>] <file>"); +      System.out.println("Options:"); +      System.out.println +      ( +         " -i|--include <directory>\tAdds <directory> to the search path." +      ); +      System.out.println +      ( +         " -s|--strict\t\t\tWarnings are errors." +      ); +      System.out.println +      ( +         " -te|--tolerate-error <name>\tRelates <name> to a simple warning." +      ); +      System.out.println +      ( +         " -se|--silence-error <name>\tErrors of type <name> are ignored." +      ); + +      for (final TonkadurPlugin plugin: plugins) +      { +         plugin.print_options(); +      } + +      System.out.println(""); +      System.out.println("Home page: https://tonkadur.of.tacticians.online"); +   } + +   public static boolean parse_options (final String[] options) +   { +      final Iterator<String> options_it; + +      if (options.length == 0) +      { +         return false; +      } + +      target_file = options[options.length - 1]; + +      options_it = Arrays.stream(options).iterator(); + +      while (options_it.hasNext()) +      { +         final String option = options_it.next(); + +         if (option.equals("-i") || option.equals("--include")) +         { +            if (!options_it.hasNext()) +            { +               return false; +            } + +            include_directories.add(options_it.next()); +         } +         else if (option.equals("-s") || option.equals("--strict")) +         { +            consider_warnings_as_errors = true; +         } +         else if (option.equals("-te") || option.equals("--tolerate-error")) +         { +            final ErrorCategory er; +            final String er_name; + +            if (!options_it.hasNext()) +            { +               return false; +            } + +            er_name = options_it.next(); + +            er = ErrorCategory.get_error_category(er_name); + +            if (er == null) +            { +               System.err.println("Unknown error type \"" + er_name + "\"."); +               System.err.println("Available error types:"); + + +               for (final String er_type: ErrorCategory.get_error_categories()) +               { +                  System.err.println("- " + er_type); +               } + +               System.err.println(""); + +               return false; +            } + +            tolerated_errors.add(er); +         } +         else if (option.equals("-se") || option.equals("--silence-error")) +         { +            final ErrorCategory er; +            final String er_name; + +            if (!options_it.hasNext()) +            { +               return false; +            } + +            er_name = options_it.next(); + +            er = ErrorCategory.get_error_category(er_name); + +            if (er == null) +            { +               System.err.println("Unknown error type \"" + er_name + "\"."); +               System.err.println("Available error types:"); + + +               for (final String er_type: ErrorCategory.get_error_categories()) +               { +                  System.err.println("- " + er_type); +               } + +               System.err.println(""); + +               return false; +            } + +            disabled_errors.add(er); +         } +      } + +      return true; +   }  } diff --git a/src/core/src/tonkadur/TonkadurPlugin.java b/src/core/src/tonkadur/TonkadurPlugin.java index 2df21d0..42b3b90 100644 --- a/src/core/src/tonkadur/TonkadurPlugin.java +++ b/src/core/src/tonkadur/TonkadurPlugin.java @@ -126,4 +126,8 @@ public abstract class TonkadurPlugin     {     } + +   public void print_options () +   { +   }  } diff --git a/src/core/src/tonkadur/error/ErrorCategory.java b/src/core/src/tonkadur/error/ErrorCategory.java index 122cff3..9c9f552 100644 --- a/src/core/src/tonkadur/error/ErrorCategory.java +++ b/src/core/src/tonkadur/error/ErrorCategory.java @@ -1,23 +1,43 @@  package tonkadur.error; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +  public class ErrorCategory  { +   protected static final Map<String, ErrorCategory> by_name; +     public static final ErrorCategory INVALID_INPUT;     public static final ErrorCategory PROGRAMMING_ERROR;     public static final ErrorCategory FILE_ACCESS;     static     { +      by_name = new HashMap<String, ErrorCategory>(); +        INVALID_INPUT = new ErrorCategory("Invalid Input");        PROGRAMMING_ERROR = new ErrorCategory("Programming Error");        FILE_ACCESS = new ErrorCategory("File Access");     } +   public static ErrorCategory get_error_category (final String name) +   { +      return by_name.get(name); +   } + +   public static Collection<String> get_error_categories () +   { +      return by_name.keySet(); +   } +     protected final String name;     protected ErrorCategory (final String name)     {        this.name = name; + +      by_name.put(name, this);     }     @Override diff --git a/src/core/src/tonkadur/fate/v1/Base.java b/src/core/src/tonkadur/fate/v1/Base.java new file mode 100644 index 0000000..4dfa199 --- /dev/null +++ b/src/core/src/tonkadur/fate/v1/Base.java @@ -0,0 +1,11 @@ +package tonkadur.fate.v1; + +import tonkadur.fate.v1.error.ErrorCategory; + +public class Base +{ +   public static void initialize () +   { +      ErrorCategory.initialize(); +   } +} diff --git a/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java b/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java index 35f4b94..20fac02 100644 --- a/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java +++ b/src/core/src/tonkadur/fate/v1/error/ErrorCategory.java @@ -1,6 +1,6 @@  package tonkadur.fate.v1.error; -class ErrorCategory extends tonkadur.error.ErrorCategory +public class ErrorCategory extends tonkadur.error.ErrorCategory  {     public static final ErrorCategory CONFLICTING;     public static final ErrorCategory DUPLICATE_DECLARATION; @@ -21,6 +21,11 @@ class ErrorCategory extends tonkadur.error.ErrorCategory        UNKNOWN = new ErrorCategory("unknown");     } +   public static void initialize () +   { +      /* Ensures class is loaded. */ +   } +     private ErrorCategory (final String name)     {        super(name); diff --git a/src/core/src/tonkadur/wyrd/v1/Base.java b/src/core/src/tonkadur/wyrd/v1/Base.java new file mode 100644 index 0000000..2d3538b --- /dev/null +++ b/src/core/src/tonkadur/wyrd/v1/Base.java @@ -0,0 +1,9 @@ +package tonkadur.wyrd.v1; + +public class Base +{ +   public static void initialize () +   { +      /* Nothing to do. */ +   } +} | 


