summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2021-05-01 20:58:23 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2021-05-01 20:58:23 +0200
commit034153205de05ef2a4facf7aded9912ce8dfb6b5 (patch)
tree963eaad7baedcea998e6a41b62e3cedd7d8c6ba9 /src/core
parenta5ddb05e399929e778f501c864c894b32da3c354 (diff)
Suffixes imperative stuff with '!', adds ({set,list} ... ) shorthands.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateLexer.g434
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateParser.g4110
2 files changed, 115 insertions, 29 deletions
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4 b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
index c9283c7..7accac5 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateLexer.g4
@@ -25,13 +25,13 @@ IMP_ADD_AT_KW: L_PAREN 'add'(US'element')?US'at!' SEP+;
ADD_ALL_KW: L_PAREN 'add'US'all'(US'elements')? SEP+;
IMP_ADD_ALL_KW: L_PAREN 'add'US'all'(US'elements')?'!' SEP+;
AND_KW: L_PAREN ('and'|'/\\') SEP+;
-ASSERT_KW: L_PAREN 'assert' SEP+;
+IMP_ASSERT_KW: L_PAREN 'assert!' SEP+;
AT_KW: L_PAREN 'at' SEP+;
-BREAK_KW: L_PAREN 'break)';
+IMP_BREAK_KW: L_PAREN 'break'('!'?) SEP* R_PAREN;
CAR_KW: L_PAREN 'car' SEP+;
CAST_KW: L_PAREN 'cast' SEP+;
CDR_KW: L_PAREN 'cdr' SEP+;
-CLEAR_KW: L_PAREN 'clear' SEP+;
+IMP_CLEAR_KW: L_PAREN 'clear!' SEP+;
COND_KW: L_PAREN 'cond' SEP+;
CONS_KW: L_PAREN 'cons' SEP+;
COUNT_KW: L_PAREN 'count' SEP+;
@@ -51,14 +51,15 @@ DEFINE_SEQUENCE_KW: L_PAREN ('declare'|'define'|'def')US(('seq'('uence')?)|('pro
DIVIDE_KW: L_PAREN ('divide'|'/'|'div') SEP+;
DO_WHILE_KW: L_PAREN ('do'US'while') SEP+;
ENABLE_TEXT_EFFECT_KW: L_PAREN 'text'US'effect' SEP+;
-END_KW: L_PAREN 'end)';
+END_KW: L_PAREN 'end'('!'?) SEP* R_PAREN;
EQUALS_KW: L_PAREN ('equals'|'='|'=='|'eq') SEP+;
EXTENSION_FIRST_LEVEL_KW: L_PAREN '@';
EXTRA_INSTRUCTION_KW: L_PAREN '#';
JOIN_KW: L_PAREN ('text'US)? 'join' SEP+;
EXTRA_COMPUTATION_KW: L_PAREN '$';
-FALSE_KW: L_PAREN 'false)';
+FALSE_KW: L_PAREN 'false' SEP* R_PAREN;
IGNORE_ERROR_KW: L_PAREN 'ignore'US('error'|'warning') SEP+;
+IMP_IGNORE_ERROR_KW: L_PAREN 'ignore'US('error'|'warning')'!' SEP+;
FATE_VERSION_KW: L_PAREN 'fate'US'version' SEP+;
FIELD_KW: L_PAREN 'field' SEP+;
FIELD_ACCESS_KW: L_PAREN (('get'US'field')|('field'US'access')) SEP+;
@@ -70,7 +71,7 @@ FOR_EACH_KW: L_PAREN ('for'US'each') SEP+;
FOR_KW: L_PAREN 'for' SEP+;
FOLDR_KW: L_PAREN 'foldr' SEP+;
FOLDL_KW: L_PAREN 'foldl' SEP+;
-FREE_KW: L_PAREN ('free'|'release'|'destroy') SEP+;
+FREE_KW: L_PAREN ('free!'|'release!'|'destroy!') SEP+;
GREATER_EQUAL_THAN_KW: L_PAREN ('greater'US'equal'US'than'|'>='|'ge') SEP+;
GREATER_THAN_KW: L_PAREN ('greater'US'than'|'>'|'gt') SEP+;
IF_ELSE_KW: L_PAREN ('if'US'else') SEP+;
@@ -107,8 +108,8 @@ SAFE_INDEXED_MERGE_TO_LIST_KW : L_PAREN (('safe'US'indexed')|('indexed'US'safe')
SAFE_INDEXED_MERGE_TO_SET_KW : L_PAREN (('safe'US'indexed')|('indexed'US'safe'))US'merge'US'to'US'set' SEP+;
SAFE_IMP_MERGE_KW : L_PAREN 'safe'US'merge!' SEP+;
SAFE_IMP_INDEXED_MERGE_KW : L_PAREN (('indexed'US'safe')|('safe'US'indexed'))US'merge!' SEP+;
-NEWLINE_KW: L_PAREN 'newline)';
-ALLOCATE_KW: L_PAREN (('alloc''ate'?)|'malloc'|'new')'!'? SEP+;
+NEWLINE_KW: L_PAREN 'newline' SEP* R_PAREN;
+ALLOCATE_KW: L_PAREN (('alloc''ate'?)|'malloc'|'new')'!' SEP+;
NOT_KW: L_PAREN ('not'|'~'|'!') SEP+;
ONE_IN_KW: L_PAREN ('exactly'US)?'one'(US'in')? SEP+;
OR_KW: L_PAREN ('or'|'\\/') SEP+;
@@ -132,7 +133,7 @@ PLUS_KW: L_PAREN ('plus'|'+') SEP+;
POWER_KW: L_PAREN ('power'|'^'|'**'|'pow') SEP+;
RANGE_KW: L_PAREN 'range' SEP+;
RANDOM_KW: L_PAREN ('random'|'rand'|'rnd') SEP+;
-REF_KW: L_PAREN (((('ref'('erence'?))|'ptr'|'pointer')(US'to')?)|('address'(US'of'))) SEP+;
+REF_KW: L_PAREN (((('ref'('erence'?))|'ptr'|'pointer')(US'to')?)|('addr'('ess'?)(US'of')?)) SEP+;
REMOVE_ALL_KW: L_PAREN 'remove'US'all' SEP+;
IMP_REMOVE_ALL_KW: L_PAREN 'remove'US'all!' SEP+;
REVERSE_KW: L_PAREN 'reverse'(US'list')? SEP+;
@@ -143,15 +144,15 @@ REMOVE_AT_KW: L_PAREN ('remove'US('elem'('ent')?US)?'at') SEP+;
IMP_REMOVE_AT_KW: L_PAREN ('remove'US('elem'('ent')?US)?'at!') SEP+;
REQUIRE_EXTENSION_KW: L_PAREN 'require'US'extension' SEP+;
REQUIRE_KW: L_PAREN 'require' SEP+;
-PROMPT_STRING_KW: L_PAREN 'prompt_string' SEP+;
-PROMPT_INTEGER_KW: L_PAREN 'prompt_int'('eger'?) SEP+;
+PROMPT_STRING_KW: L_PAREN 'prompt_string!' SEP+;
+PROMPT_INTEGER_KW: L_PAREN 'prompt_int'('eger'?)'!' SEP+;
SHUFFLE_KW: L_PAREN 'shuffle' SEP+;
IMP_SHUFFLE_KW: L_PAREN 'shuffle!' SEP+;
SORT_KW: L_PAREN 'sort' SEP+;
IMP_SORT_KW: L_PAREN 'sort!' SEP+;
SET_FIELDS_KW: L_PAREN 'set'US'fields' SEP+;
IMP_SET_FIELDS_KW: L_PAREN 'set'US'fields!' SEP+;
-SET_KW: L_PAREN 'set'(US(('val''ue'?)|('var''iable'?)))?'!'? SEP+;
+IMP_SET_KW: L_PAREN 'set'(US(('val''ue'?)|('var''iable'?)))?'!' SEP+;
SUB_LIST_KW: L_PAREN 'sub'US'list' SEP+;
IMP_SUB_LIST_KW: L_PAREN 'sub'US'list!' SEP+;
LIST_KW: L_PAREN 'list' SEP+;
@@ -159,11 +160,12 @@ SIZE_KW: L_PAREN 'size' SEP+;
SEQUENCE_KW: L_PAREN ('seq'|'sequence') SEP+;
SWITCH_KW: L_PAREN 'switch' SEP+;
TIMES_KW: L_PAREN ('times'|'*') SEP+;
-TRUE_KW: L_PAREN 'true)';
-DONE_KW: L_PAREN 'done)';
+TRUE_KW: L_PAREN 'true' SEP* R_PAREN;
+DONE_KW: L_PAREN 'done''!'? SEP* R_PAREN;
+SET_KW: L_PAREN 'set' SEP+;
VARIABLE_KW: L_PAREN ('variable'|'var') SEP+;
-VISIT_KW: L_PAREN ('call'|'visit')(US(('seq'('uence'?))|('proc'('edure'?))))? SEP+;
-CONTINUE_AS_KW: L_PAREN (('continue'US('as'|'to'|'with'))|('jump'(US'to')?)|('go'US'to')|'exec')(US(('seq'('uence'?))|('proc'('edure'?))))? SEP+;
+VISIT_KW: L_PAREN ('call'|'visit')(US(('seq'('uence'?))|('proc'('edure'?))))?'!' SEP+;
+CONTINUE_AS_KW: L_PAREN (('continue'US('as'|'to'|'with'))|('jump'(US'to')?)|('go'US'to')|'exec')(US(('seq'('uence'?))|('proc'('edure'?))))?'!' SEP+;
WHILE_KW: L_PAREN 'while' SEP+;
WORD: ((~([ \t\r\n()]))|'(lp)'|'(rp)'|'(sp)')+
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
index 7736318..43b970c 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
@@ -32,6 +32,7 @@ options
import tonkadur.fate.v1.error.DuplicateLocalVariableException;
import tonkadur.fate.v1.error.IllegalReferenceNameException;
+ import tonkadur.fate.v1.error.InvalidArityException;
import tonkadur.fate.v1.error.InvalidTypeException;
import tonkadur.fate.v1.error.UpdatingIllegalVariableFromChoiceException;
import tonkadur.fate.v1.error.UnknownExtensionContentException;
@@ -810,7 +811,7 @@ returns [Instruction result]
);
}
- | IGNORE_ERROR_KW WORD WS+ general_fate_instr WS* R_PAREN
+ | IMP_IGNORE_ERROR_KW WORD WS+ general_fate_instr WS* R_PAREN
{
/* TODO: temporarily disable an compiler error category */
$result = ($general_fate_instr.result);
@@ -870,15 +871,15 @@ returns [Instruction result]
);
}
- | CLEAR_KW value_reference WS* R_PAREN
+ | IMP_CLEAR_KW value_reference WS* R_PAREN
{
$result =
Clear.build
(
CONTEXT.get_origin_at
(
- ($CLEAR_KW.getLine()),
- ($CLEAR_KW.getCharPositionInLine())
+ ($IMP_CLEAR_KW.getLine()),
+ ($IMP_CLEAR_KW.getCharPositionInLine())
),
($value_reference.result)
);
@@ -1447,15 +1448,15 @@ returns [Instruction result]
);
}
- | SET_KW value_reference WS+ value WS* R_PAREN
+ | IMP_SET_KW value_reference WS+ value WS* R_PAREN
{
$result =
SetValue.build
(
CONTEXT.get_origin_at
(
- ($SET_KW.getLine()),
- ($SET_KW.getCharPositionInLine())
+ ($IMP_SET_KW.getLine()),
+ ($IMP_SET_KW.getCharPositionInLine())
),
($value.result),
($value_reference.result)
@@ -1597,15 +1598,15 @@ returns [Instruction result]
);
}
- | {BREAKABLE_LEVELS > 0}? BREAK_KW
+ | {BREAKABLE_LEVELS > 0}? IMP_BREAK_KW
{
$result =
new Break
(
CONTEXT.get_origin_at
(
- ($BREAK_KW.getLine()),
- ($BREAK_KW.getCharPositionInLine())
+ ($IMP_BREAK_KW.getLine()),
+ ($IMP_BREAK_KW.getCharPositionInLine())
)
);
}
@@ -1953,15 +1954,15 @@ returns [Instruction result]
);
}
- | ASSERT_KW non_text_value WS+ paragraph WS* R_PAREN
+ | IMP_ASSERT_KW non_text_value WS+ paragraph WS* R_PAREN
{
$result =
Assert.build
(
CONTEXT.get_origin_at
(
- ($ASSERT_KW.getLine()),
- ($ASSERT_KW.getCharPositionInLine())
+ ($IMP_ASSERT_KW.getLine()),
+ ($IMP_ASSERT_KW.getCharPositionInLine())
),
($non_text_value.result),
($paragraph.result)
@@ -4206,6 +4207,89 @@ returns [Computation result]
);
}
+ | LIST_KW value_list WS* R_PAREN
+ {
+ final Origin origin;
+
+ origin =
+ CONTEXT.get_origin_at
+ (
+ ($LIST_KW.getLine()),
+ ($LIST_KW.getCharPositionInLine())
+ );
+
+ if ($value_list.result.size() == 0)
+ {
+ ErrorManager.handle(new InvalidArityException(origin, 0, 1, -1));
+ }
+
+
+ $result =
+ new Default
+ (
+ origin,
+ CollectionType.build
+ (
+ origin,
+ ($value_list.result).get(0).get_type(),
+ false,
+ "Autogenerated List Type"
+ )
+ );
+
+ for (final Computation val: $value_list.result)
+ {
+ $result =
+ AddElementComputation.build
+ (
+ origin,
+ val,
+ $result
+ );
+ }
+ }
+
+ | SET_KW value_list WS* R_PAREN
+ {
+ final Origin origin;
+
+ origin =
+ CONTEXT.get_origin_at
+ (
+ ($SET_KW.getLine()),
+ ($SET_KW.getCharPositionInLine())
+ );
+
+ if ($value_list.result.size() == 0)
+ {
+ ErrorManager.handle(new InvalidArityException(origin, 0, 1, -1));
+ }
+
+ $result =
+ new Default
+ (
+ origin,
+ CollectionType.build
+ (
+ origin,
+ ($value_list.result).get(0).get_type(),
+ true,
+ "Autogenerated Set Type"
+ )
+ );
+
+ for (final Computation val: $value_list.result)
+ {
+ $result =
+ AddElementComputation.build
+ (
+ origin,
+ val,
+ $result
+ );
+ }
+ }
+
| RANGE_KW
vstart=non_text_value WS+
vend=non_text_value WS+