Skip to content

Commit

Permalink
#5589: Fix a problem when reparsing complex map expressions due to in…
Browse files Browse the repository at this point in the history
…consistent tokeniser delimiters.
  • Loading branch information
codereader committed Apr 15, 2021
1 parent eec691d commit 590886e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libs/parser/DefTokeniser.h
Expand Up @@ -347,7 +347,7 @@ class DefTokeniserFunc
}
};

const char* const WHITESPACE = " \t\n\v\r";
constexpr const char* const WHITESPACE = " \t\n\v\r";

/**
* DefTokeniser abstract base class. This class provides a unified interface to
Expand Down
9 changes: 7 additions & 2 deletions radiantcore/shaders/MapExpression.cpp
Expand Up @@ -16,6 +16,7 @@
#include "textures/HeightmapCreator.h"
#include "textures/TextureManipulator.h"
#include "string/predicate.h"
#include "ShaderTemplate.h"

/* CONSTANTS */
namespace
Expand Down Expand Up @@ -96,8 +97,12 @@ MapExpressionPtr MapExpression::createForString(const std::string& str)
{
try
{
parser::BasicDefTokeniser<std::string> token(str);
return createForToken(token);
parser::BasicDefTokeniser<std::string> tokeniser(
str,
ShaderTemplate::DiscardedDelimiters, // delimiters (whitespace)
ShaderTemplate::KeptDelimiters
);
return createForToken(tokeniser);
}
catch (const parser::ParseException&)
{
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/shaders/ShaderTemplate.cpp
Expand Up @@ -1187,8 +1187,8 @@ void ShaderTemplate::parseDefinition()
// Construct a local deftokeniser to parse the unparsed block
parser::BasicDefTokeniser<std::string> tokeniser(
_blockContents,
parser::WHITESPACE, // delimiters (whitespace)
"{}()," // add the comma character to the kept delimiters
DiscardedDelimiters, // delimiters (whitespace)
KeptDelimiters
);

_parsed = true; // we're parsed from now on
Expand Down
4 changes: 4 additions & 0 deletions radiantcore/shaders/ShaderTemplate.h
Expand Up @@ -36,6 +36,10 @@ class ShaderTemplate final

public:

// Shared parsing constants
constexpr static const char* DiscardedDelimiters = parser::WHITESPACE;
constexpr static const char* KeptDelimiters = "{}(),"; // add the comma character to the kept delimiters

// Vector of LayerTemplates representing each stage in the material
std::vector<Doom3ShaderLayer::Ptr> _layers;

Expand Down

0 comments on commit 590886e

Please sign in to comment.