Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit 3373f48

Browse files
committed
Added support for mixing of index and range
Solves #12. Solves #11.
1 parent 5d051e2 commit 3373f48

File tree

1 file changed

+79
-111
lines changed

1 file changed

+79
-111
lines changed

script.cs

Lines changed: 79 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,6 @@ function EventScript_fromScript(%script, %error)
610610
%indexTableLine[%indexTableCount] = %line;
611611
%indexTableIndex[%indexTableCount] = %list.count;
612612
%indexTableParam[%indexTableCount] = getFieldCount(%list.value[%list.count, "param"]);
613-
%indexTableType[%indexTableCount] = -1;
614613
%indexTableListCount[%indexTableCount] = 0;
615614

616615
%state = 4;
@@ -749,60 +748,57 @@ function EventScript_fromScript(%script, %error)
749748

750749
%data = trim(getSubStr(%script, %i, %n - %i));
751750

751+
%currentListCount = %indexTableListCount[%indexTableCount];
752+
%indexTableListLabel[%indexTableCount, %currentListCount] = %isLabel;
753+
%indexTableList[%indexTableCount, %currentListCount] = %data;
754+
%indexTableListCount[%indexTableCount]++;
755+
752756
%i = %n;
753757

754758
if (%c $= ",")
755759
{
756-
if (%indexTableType[%indexTableCount] == 1)
757-
{
758-
%n = -1;
759-
}
760-
else if (%data $= "")
760+
// Empty index
761+
if (%data $= ""
762+
&& (%indexTableListCount[%indexTableCount] == 0
763+
|| %indexTableType[%indexTableCount, %currentListCount - 1] == 0))
761764
{
762765
%n = -2;
763766
}
764767
else
765768
{
766-
%indexTableType[%indexTableCount] = 0;
767-
%indexTableListLabel[%indexTableCount, %indexTableListCount[%indexTableCount]] = %isLabel;
768-
%indexTableList[%indexTableCount, %indexTableListCount[%indexTableCount]] = %data;
769-
%indexTableListCount[%indexTableCount]++;
769+
%indexTableType[%indexTableCount, %currentListCount] = 0;
770770
}
771771

772+
%currentListCount++;
772773
}
773774
else if (%c $= ":")
774775
{
775-
if (%indexTableType[%indexTableCount] == 0)
776+
// Already got a range
777+
if (%currentListCount > 0
778+
&& %indexTableType[%indexTableCount, %currentListCount - 1] == 1)
776779
{
777-
%n = -1;
780+
%n = -3;
778781
}
779782
else
780783
{
781-
%indexTableType[%indexTableCount] = 1;
782-
%indexTableStartLabel[%indexTableCount] = %isLabel;
783-
%indexTableStart[%indexTableCount] = %data;
784+
%indexTableType[%indexTableCount, %currentListCount] = 1;
784785
}
786+
787+
%currentListCount++;
785788
}
786789
else if (%c $= "]")
787790
{
788-
if (%indexTableType[%indexTableCount] == -1 || (%indexTableType[%indexTableCount] != 1 && %data $= ""))
791+
// Empty index
792+
if (%data $= ""
793+
&& (%currentListCount == 0
794+
|| %indexTableType[%indexTableCount, %currentListCount - 1] == 0))
789795
{
790796
%n = -2;
791797
}
792-
else if (%indexTableType[%indexTableCount] == 0)
793-
{
794-
%indexTableListLabel[%indexTableCount, %indexTableListCount[%indexTableCount]] = %isLabel;
795-
%indexTableList[%indexTableCount, %indexTableListCount[%indexTableCount]] = %data;
796-
%indexTableListCount[%indexTableCount]++;
797-
}
798-
else if (%indexTableType[%indexTableCount] == 1)
798+
else
799799
{
800-
%indexTableEndLabel[%indexTableCount] = %isLabel;
801-
%indexTableEnd[%indexTableCount] = %data;
802-
}
800+
%indexTableType[%indexTableCount, %currentListCount] = 0;
803801

804-
if (%n >= 0)
805-
{
806802
// Finished, so lets find next and get out of here
807803
for (%n = %i + 1; %n < %len; %n++)
808804
{
@@ -823,20 +819,20 @@ function EventScript_fromScript(%script, %error)
823819
break;
824820
}
825821
}
826-
}
827822

828-
if (%c $= ",")
829-
{
830-
%state = 3;
831-
}
832-
else if (%c $= ")")
833-
{
834-
%state = 0;
835-
// Finished events
836-
%list.count++;
837-
}
823+
if (%c $= ",")
824+
{
825+
%state = 3;
826+
}
827+
else if (%c $= ")")
828+
{
829+
%state = 0;
830+
// Finished events
831+
%list.count++;
832+
}
838833

839-
%indexTableCount++;
834+
%indexTableCount++;
835+
}
840836
}
841837

842838
// Found errors
@@ -846,6 +842,8 @@ function EventScript_fromScript(%script, %error)
846842
call(%error, "Parse Error: Found illegal character " @ %c @ " on line " @ %line);
847843
else if (%n == -2)
848844
call(%error, "Parse Error: Empty index found on line " @ %line);
845+
else if (%n == -3)
846+
call(%error, "Parse Error: Ranges allow only two values on line " @ %line);
849847
%list.error = true;
850848
return %list;
851849
}
@@ -855,7 +853,7 @@ function EventScript_fromScript(%script, %error)
855853
%list.error = true;
856854
return %list;
857855
}
858-
856+
859857
%i = %n;
860858
}
861859
}
@@ -878,94 +876,64 @@ function EventScript_fromScript(%script, %error)
878876
%index = %indexTableIndex[%i];
879877
%param = %indexTableParam[%i];
880878

881-
switch (%indexTableType[%i])
879+
%params = "";
880+
881+
%l = -1;
882+
for (%n = 0; %n < %indexTableListCount[%i]; %n++)
882883
{
883-
// Indexing
884-
case 0:
884+
%var = %indexTableList[%i, %n];
885885

886-
%params = "";
887-
for (%n = 0; %n < %indexTableListCount[%i]; %n++)
886+
// Handle labels
887+
if (%indexTableListLabel[%i, %n])
888888
{
889-
%var = %indexTableList[%i, %n];
890-
891-
// Handle labels
892-
if (%indexTableListLabel[%i, %n])
889+
if (%labelTable[%var] $= "")
893890
{
894-
if (%labelTable[%var] !$= "")
895-
{
896-
%var = %labelTable[%var];
897-
}
898-
else
899-
{
900-
call(%error, "Parser Error: Label \"" @ %var @ "\" does not exist on line " @ %line);
901-
%list.error = true;
902-
return %list;
903-
}
891+
call(%error, "Parser Error: Label \"" @ %var @ "\" does not exist on line " @ %line);
892+
%list.error = true;
893+
return %list;
904894
}
905895

906-
%var = mClamp(%var, 0, %list.count - 1);
907-
%params = setWord(%params, %n, %var);
896+
%var = %labelTable[%var];
908897
}
909898

910-
%list.value[%index, "params"] = setField(%list.value[%index, "params"], %param, %params);
911-
912-
// Range
913-
case 1:
899+
// Default value
900+
if (%indexTableType[%i, %n] == 2 && %var $= "")
901+
%var = %list.count - 1;
902+
else if (%var $= "")
903+
%var = 0;
914904

915-
%start = %indexTableStart[%i];
916-
%end = %indexTableEnd[%i];
905+
%var = mClamp(%var, 0, %list.count - 1);
917906

918-
// Handle labels
919-
if (%indexTableStartLabel[%i])
920-
{
921-
if (%labelTable[%start] !$= "")
922-
{
923-
%start = %labelTable[%start];
924-
}
925-
else
926-
{
927-
call(%error, "Parser Error: Label \"" @ %start @ "\" does not exist on line " @ %line);
928-
%list.error = true;
929-
return %list;
930-
}
931-
}
932-
if (%indexTableEndLabel[%i])
907+
switch (%indexTableType[%i, %n])
933908
{
934-
if (%labelTable[%end] !$= "")
935-
{
936-
%end = %labelTable[%end];
937-
}
938-
else
909+
// Indexing
910+
case 0:
911+
912+
%params = setWord(%params, %l++, %var);
913+
914+
// Range start
915+
case 1:
916+
917+
%start = %var;
918+
%indexTableType[%i, %n+1] = 2;
919+
920+
// Range ends
921+
case 2:
922+
923+
// Incorrect indexing order
924+
if (%start > %var)
939925
{
940-
call(%error, "Parser Error: Label \"" @ %end @ "\" does not exist on line " @ %line);
926+
call(%error, "Logic Error: Invalid indexing values " @ %start @ ":" @ %var @ " on line " @ %line);
941927
%list.error = true;
942928
return %list;
943929
}
944-
}
945-
// Default values
946-
if (%start $= "")
947-
%start = 0;
948-
if (%end $= "")
949-
%end = %list.count - 1;
950-
951-
%start = mClamp(%start, 0, %list.count - 1);
952-
%end = mClamp(%end, 0, %list.count - 1);
953930

954-
// Incorrect indexing order
955-
if (%start > %end)
956-
{
957-
call(%error, "Logic Error: Invalid indexing values [" @ %start @ ":" @ %end @ "] on line " @ %line);
958-
%list.error = true;
959-
return %list;
931+
for (%m = %start; %m <= %var; %m++)
932+
%params = setWord(%params, %l++, %m);
960933
}
961-
962-
%params = "";
963-
%n = -1;
964-
for (%m = %start; %m <= %end; %m++)
965-
%params = setWord(%params, %n++, %m);
966-
967-
%list.value[%index, "params"] = setField(%list.value[%index, "params"], %param, %params);
968934
}
935+
936+
%list.value[%index, "params"] = setField(%list.value[%index, "params"], %param, %params);
969937
}
970938

971939
return %list;

0 commit comments

Comments
 (0)