diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-06-26 14:09:53 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-06-26 14:14:06 -0700 |
| commit | 7d97d424c0a754ec49cccfc8af6c8983e0d06d80 (patch) | |
| tree | 3669bf42ed6e971cde176cb422beab6c53158e8c /source/slang/parser.cpp | |
| parent | 0259ddb0a72d3b12278404847f6e30b63e97cfc3 (diff) | |
Fix parsing of string literals.
String literals can be used as part of attributes, but we lacked an actual AST representation for them.
This change adds basic parsing for string literals, as well as emit logic for them.
I also included a fix for parsing of chained right-associative operators.
To test these fixes, I've re-enabled one of the HLSL tests I disabled a while back. It would be good to go through and see how many of those we can re-enable now.
Diffstat (limited to 'source/slang/parser.cpp')
| -rw-r--r-- | source/slang/parser.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index 61d7b225d..8edc3a122 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -3014,9 +3014,7 @@ namespace Slang { auto nextOpPrec = GetOpLevel(parser, parser->tokenReader.PeekTokenType()); - if((GetAssociativityFromLevel(nextOpPrec) == Associativity::Right) && (nextOpPrec != opPrec)) - break; - else if( nextOpPrec <= opPrec) + if((GetAssociativityFromLevel(nextOpPrec) == Associativity::Right) ? (nextOpPrec < opPrec) : (nextOpPrec <= opPrec)) break; right = parseInfixExprWithPrecedence(parser, right, nextOpPrec); @@ -3206,6 +3204,33 @@ namespace Slang return constExpr; } + case TokenType::StringLiterial: + { + RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); + auto token = parser->tokenReader.AdvanceToken(); + parser->FillPosition(constExpr.Ptr()); + constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::String; + + if (!parser->LookAheadToken(TokenType::StringLiterial)) + { + // Easy/common case: a single string + constExpr->stringValue = getStringLiteralTokenValue(token); + } + else + { + StringBuilder sb; + sb << getStringLiteralTokenValue(token); + while (parser->LookAheadToken(TokenType::StringLiterial)) + { + token = parser->tokenReader.AdvanceToken(); + sb << getStringLiteralTokenValue(token); + } + constExpr->stringValue = sb.ProduceString(); + } + + return constExpr; + } + case TokenType::Identifier: { // TODO(tfoley): Need a name-lookup step here to resolve |
