Skip to content

Commit

Permalink
Implement array-style dictionary access.
Browse files Browse the repository at this point in the history
  • Loading branch information
c-lipka committed Sep 17, 2016
1 parent 535bac5 commit 0b5ac83
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion source/base/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#define OFFICIAL_VERSION_STRING "3.7.1"
#define OFFICIAL_VERSION_NUMBER 371

#define POV_RAY_PRERELEASE "x.dictionary.8790824"
#define POV_RAY_PRERELEASE "x.dictionary.8790989"

#if (POV_RAY_IS_AUTOBUILD == 1) && ((POV_RAY_IS_OFFICIAL == 1) || (POV_RAY_IS_SEMI_OFFICIAL == 1))
#ifdef POV_RAY_PRERELEASE
Expand Down
1 change: 1 addition & 0 deletions source/parser/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class Parser : public SceneTask
SYM_TABLE *table; ///< table or dictionary the token references an element of
bool is_array_elem : 1; ///< true if token is actually an array element reference
bool is_dictionary_elem : 1; ///< true if token is actually a dictionary element reference
bool freeString : 1; ///< true if Token_String must be freed before being assigned a new value
};

struct LValue
Expand Down
55 changes: 39 additions & 16 deletions source/parser/parser_tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void Parser::pre_init_tokenizer ()
Token.Token_File_Pos.offset = 0;
Token.Token_Col_No = 0;
Token.Token_String = NULL;
Token.freeString = false;
Token.Unget_Token = false;
Token.End_Of_File = false;
Token.Data = NULL;
Expand Down Expand Up @@ -1053,8 +1054,6 @@ void Parser::Read_String_Literal()
End_String();

Write_Token(STRING_LITERAL_TOKEN, col);

Token.Token_String = String;
}


Expand Down Expand Up @@ -1277,6 +1276,7 @@ void Parser::Read_Symbol()
POV_PARAM *Par;
DBL val;
SYM_TABLE *table;
char *dictIndex = NULL;

Begin_String_Fast();

Expand Down Expand Up @@ -1372,6 +1372,8 @@ void Parser::Read_Symbol()
bool breakLoop = false;
while (!breakLoop)
{
dictIndex = NULL;

switch (Token.Token_Id)
{
case ARRAY_ID_TOKEN:
Expand Down Expand Up @@ -1427,24 +1429,35 @@ void Parser::Read_Symbol()
c = Echo_getc();
Echo_ungetc(c);

if (c!='.')
{
breakLoop = true;
break;
}

dictIndex = NULL;
table = reinterpret_cast<SYM_TABLE *>(*(Token.DataPtr));

GET (PERIOD_TOKEN)
bool oldParseRawIdentifiers = parseRawIdentifiers;
parseRawIdentifiers = true;
Get_Token ();
parseRawIdentifiers = oldParseRawIdentifiers;
if (c =='.')
{
GET (PERIOD_TOKEN)
bool oldParseRawIdentifiers = parseRawIdentifiers;
parseRawIdentifiers = true;
Get_Token ();
parseRawIdentifiers = oldParseRawIdentifiers;

if (Token.Token_Id != IDENTIFIER_TOKEN)
Expectation_Error ("dictionary element identifier");

if (Token.Token_Id != IDENTIFIER_TOKEN)
Expectation_Error ("dictionary element identifier");
Temp_Entry = Find_Symbol (table, Token.Token_String);
}
else if (c == '[')
{
GET(LEFT_SQUARE_TOKEN)
dictIndex = Parse_C_String();
GET (RIGHT_SQUARE_TOKEN);

Temp_Entry = Find_Symbol (table, Token.Token_String);
Temp_Entry = Find_Symbol (table, dictIndex);
}
else
{
breakLoop = true;
break;
}

if (Temp_Entry)
{
Expand Down Expand Up @@ -1493,10 +1506,20 @@ void Parser::Read_Symbol()
}

Write_Token (IDENTIFIER_TOKEN, Token.Token_Col_No);
if (dictIndex != NULL)
{
Token.Token_String = dictIndex;
Token.freeString = true;
}
}

inline void Parser::Write_Token (TOKEN Token_Id, int col, SYM_TABLE *table)
{
if (Token.freeString)
{
POV_FREE (Token.Token_String);
Token.freeString = false;
}
Token.Token_File_Pos = Input_File->In_File->tellg();
Token.Token_Col_No = col;
Token.FileHandle = Input_File->In_File;
Expand Down
2 changes: 1 addition & 1 deletion unix/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7.1-x.dictionary.8790824
3.7.1-x.dictionary.8790989

0 comments on commit 0b5ac83

Please sign in to comment.