From 488e7cd8d02bf9e1d37b3e76fad6cb5ced6d8878 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Tue, 30 Mar 2021 08:38:33 -0700 Subject: 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: ` or just `` * Objects, which can be written as either `new SomeType{ }` or `new{ }` 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 --- source/core/slang-token-reader.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source') 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) ) -- cgit v1.2.3