summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2021-03-30 08:38:33 -0700
committerGitHub <noreply@github.com>2021-03-30 08:38:33 -0700
commit488e7cd8d02bf9e1d37b3e76fad6cb5ced6d8878 (patch)
tree28a0d5a8502199541ec2e7ff1d9d798c5fe011e0 /source
parent129faf8c4af4a57b7f1c71749f45b31aebfab038 (diff)
Add a streamlined syntax for TEST_INPUT lines (#1768)
This change allows the `TEST_INPUT` syntax used by `render-test` to support aggregate values with a single input line more easily. The test writer can now use a syntax like: ``` //TEST_INPUT:set someVar = 3.0 ``` Input lines that start with the `set` keyword will now use a simpler `dst = src` format (instead of `dst:name=src` as the existing syntax used). The right-hand side expression can include: * Numeric literals, both integer and floating-point (currently only supporting 32-bit scalar types; we could fix this later) * Arrays, consisting of zero or more comma-separated expressions inside `[]` * Aggregates, consisting of zero or more comma-separated "fields" inside `{}`. A field can either be `name: <expr>` or just `<expr>` * Objects, which can be written as either `new SomeType{ <fields> }` or `new{ <fields> }` in the case where the type is know-able from context With this approach is should be possible to support almost arbitrary-type inputs on a single line. For now, I have used this support to re-enable an existing test that had been disabled due to lack of support for setting up arrays of objects. Major things left to do: * The new syntax doesn't support the existing cases we had for `Texture2D`, etc. Those should probably be supported but I'd like to find a way to do it without duplicating the parsing logic (ideally the value cases from the existing code should Just Work in the new model) * There is no support right now for non-32-bit scalar types * It would be good if this support (and the shader cursor system) supported treating vectors like aggregates * The actual value-setting logic doesn't currently handle aggregates without field names, so `{ a:0, b:1 }` will work but `{ 0, 1 }` will parse but fail when it comes time to set values * While this approach lets complicated values be set with a single line, that isn't always what a user will want to do: in the future we should provide a way to break up an aggregate value over multiple lines that is consistent with this approach * Once we port all of the relvant tests over, it would be great to drop the `set` prefix and have these lines look as simple and conventional as possible
Diffstat (limited to 'source')
-rw-r--r--source/core/slang-token-reader.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/source/core/slang-token-reader.h b/source/core/slang-token-reader.h
index f08c1674c..18b56f31f 100644
--- a/source/core/slang-token-reader.h
+++ b/source/core/slang-token-reader.h
@@ -175,6 +175,15 @@ namespace Slang
}
throw TextFormatException("Text parsing error: \'" + expectedStr + "\' expected.");
}
+ bool Read(TokenType tokenType)
+ {
+ if( NextToken().Type == tokenType )
+ {
+ ReadToken();
+ return true;
+ }
+ throw TextFormatException("Text parsing error: unexpected '" + NextToken().Content + "'.");
+ }
String ReadStringLiteral()
{
@@ -231,6 +240,18 @@ namespace Slang
return false;
}
}
+ bool LookAhead(TokenType tokenType)
+ {
+ if (tokenPtr < (int)tokens.getCount())
+ {
+ auto next = NextToken();
+ return next.Type == tokenType;
+ }
+ else
+ {
+ return false;
+ }
+ }
bool AdvanceIf(String token)
{
if( LookAhead(token) )