| summaryrefslogtreecommitdiff |
diff options
| -rw-r--r-- | data/examples/blackjack/cards.fate | 12 | ||||
| -rw-r--r-- | data/examples/blackjack/global.fate | 2 | ||||
| -rw-r--r-- | data/examples/blackjack/play.fate | 10 | ||||
| -rw-r--r-- | data/examples/blackjack/player.fate | 4 | ||||
| -rw-r--r-- | src/core/src/tonkadur/fate/v1/error/DangerouslyNamedUserContentException.java | 49 | ||||
| -rw-r--r-- | src/core/src/tonkadur/fate/v1/error/ErrorCategory.java | 2 | ||||
| -rw-r--r-- | src/core/src/tonkadur/fate/v1/lang/meta/RecurrentChecks.java | 17 | ||||
| -rw-r--r-- | src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 | 10 | ||||
| -rw-r--r-- | src/core/src/tonkadur/fate/v1/parser/FateParser.g4 | 30 | ||||
| -rw-r--r-- | src/core/src/tonkadur/wyrd/v1/compiler/fate/v1/TypeCompiler.java | 2 |
10 files changed, 120 insertions, 18 deletions
diff --git a/data/examples/blackjack/cards.fate b/data/examples/blackjack/cards.fate index f9c734f..b4fa384 100644 --- a/data/examples/blackjack/cards.fate +++ b/data/examples/blackjack/cards.fate @@ -1,12 +1,12 @@ (fate_version 1) -(declare_structure card +(declare_structure #card (text name) (int number) (int score) ) -(local (lambda (list card) (string)) card_generator) +(local (lambda (list #card) (string)) card_generator) (set! card_generator (lambda ( (string family) ) @@ -16,7 +16,7 @@ (int number) (string family) ) - (struct:set_fields (default card) + (struct:set_fields (default #card) (number (var number)) (name (text @@ -39,7 +39,7 @@ ) ) -(global (list card) deck_template) +(global (list #card) deck_template) (list:add_all! (eval card_generator Hearts) @@ -49,9 +49,7 @@ deck_template ) - - -(define_sequence compute_score (((ptr (list card)) deck) ((ptr int) result)) +(define_sequence compute_score (((ptr (list #card)) deck) ((ptr int) result)) (local int aces_count 0) (local int maybe_better_score 0) diff --git a/data/examples/blackjack/global.fate b/data/examples/blackjack/global.fate index 760e48a..8365c6f 100644 --- a/data/examples/blackjack/global.fate +++ b/data/examples/blackjack/global.fate @@ -2,7 +2,7 @@ (require player.fate) -(global player player) +(global #player player) (global (lambda text (int)) coins_word (lambda ((int i)) diff --git a/data/examples/blackjack/play.fate b/data/examples/blackjack/play.fate index 76b9e2b..749ca54 100644 --- a/data/examples/blackjack/play.fate +++ b/data/examples/blackjack/play.fate @@ -5,13 +5,13 @@ (require cards.fate) (global bool has_played (false)) -(global (list card) current_deck) -(global (list card) dealer_hand) +(global (list #card) current_deck) +(global (list #card) dealer_hand) (global int bet) (global bool has_doubled) (define_sequence play_a_game () - (local card new_card) + (local #card new_card) (if (not has_played) (text_effect action_description @@ -171,7 +171,7 @@ ) (define_sequence acquire_card () - (local card new_card) + (local #card new_card) (local int player_score) (list:pop_left! current_deck new_card) @@ -248,7 +248,7 @@ (newline) (while (< dealer_score 17) - (local card new_card) + (local #card new_card) (list:pop_left! current_deck new_card) (list:add! (var new_card) dealer_hand) diff --git a/data/examples/blackjack/player.fate b/data/examples/blackjack/player.fate index 7d8b947..2eec757 100644 --- a/data/examples/blackjack/player.fate +++ b/data/examples/blackjack/player.fate @@ -2,8 +2,8 @@ (require cards.fate) -(define_structure player +(define_structure #player (string name) (int money) - ((list card) hand) + ((list #card) hand) ) 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 ( |


