Skip to content

Commit

Permalink
Change logic to use callnode
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaselv committed Nov 14, 2024
1 parent 7a12483 commit 71d67e0
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 323 deletions.
9 changes: 0 additions & 9 deletions src/libraries/Microsoft.PowerFx.Core/Binding/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2579,15 +2579,6 @@ public override void Visit(TypeLiteralNode node)
_txb.SetType(node, DType.Error);
_txb.ErrorContainer.Error(node, TexlStrings.ErrTypeLiteral_InvalidTypeDefinition, node.ToString());
}
}

public override void Visit(RecordOfNode node)
{
AssertValid();
Contracts.AssertValue(node);

_txb.SetType(node, DType.Error);
_txb.ErrorContainer.Error(node, TexlStrings.ErrTypeLiteral_InvalidTypeDefinition, node.ToString());
}

public override void Visit(BoolLitNode node)
Expand Down
8 changes: 0 additions & 8 deletions src/libraries/Microsoft.PowerFx.Core/IR/IRTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ public override IntermediateNode Visit(TypeLiteralNode node, IRTranslatorContext
Contracts.AssertValue(context);

return new TextLiteralNode(IRContext.NotInSource(FormulaType.String), context.Binding.GetType(node).ToString());
}

public override IntermediateNode Visit(RecordOfNode node, IRTranslatorContext context)
{
Contracts.AssertValue(node);
Contracts.AssertValue(context);

return new ErrorNode(context.GetIRContext(node), node.ToString());
}

public override IntermediateNode Visit(NumLitNode node, IRTranslatorContext context)
Expand Down
16 changes: 0 additions & 16 deletions src/libraries/Microsoft.PowerFx.Core/Logging/StructuralPrint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,22 +352,6 @@ public override LazyList<string> Visit(TypeLiteralNode node, Precedence context)
.With(node.TypeRoot.Accept(this, Precedence.None))
.With(TexlLexer.PunctuatorParenClose);

return result;
}

public override LazyList<string> Visit(RecordOfNode node, Precedence context)
{
Contracts.AssertValue(node);

var result = LazyList<string>.Empty;

result = result
.With(
LanguageConstants.RecordOfInvariantName,
TexlLexer.PunctuatorParenOpen)
.With(node.TableName.Accept(this, Precedence.None))
.With(TexlLexer.PunctuatorParenClose);

return result;
}

Expand Down
45 changes: 1 addition & 44 deletions src/libraries/Microsoft.PowerFx.Core/Parser/TexlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public enum Flags
// When specified, allows reserved keywords to be used as identifiers.
DisableReservedKeywords = 1 << 3,

// Parse as RecordOf node
ParseAsRecordOf = 1 << 4,

// Text first. Implemented entirely in the Lexer.
TextFirst = 1 << 5,

Expand Down Expand Up @@ -213,10 +210,7 @@ private TypeLiteralNode ParseTypeLiteral(Identifier typeLiteralIdentifier)
leftTrivia
};

_flagsMode.Push(_flagsMode.Peek() | Flags.ParseAsRecordOf);
var expr = ParseExpr(Precedence.None);
_flagsMode.Pop();

sourceList.Add(new NodeSource(expr));
sourceList.Add(ParseTrivia());

Expand All @@ -230,35 +224,6 @@ private TypeLiteralNode ParseTypeLiteral(Identifier typeLiteralIdentifier)
return new TypeLiteralNode(ref _idNext, parenOpen, expr, new SourceList(sourceList));
}

private RecordOfNode ParseRecordOf(Identifier recordOfIdentifier)
{
var lefterTrivia = ParseTrivia();
var parenOpen = TokEat(TokKind.ParenOpen);
var leftTrivia = ParseTrivia();
var sourceList = new List<ITexlSource>
{
new IdentifierSource(recordOfIdentifier),
lefterTrivia,
new TokenSource(parenOpen),
leftTrivia
};

var identifier = ParseIdentifier();
var fsNode = new FirstNameNode(ref _idNext, identifier.Token, identifier);

sourceList.Add(new IdentifierSource(identifier));
sourceList.Add(ParseTrivia());

var parenClose = TokEat(TokKind.ParenClose);

if (parenClose != null)
{
sourceList.Add(new TokenSource(parenClose));
}

return new RecordOfNode(ref _idNext, parenOpen, fsNode, new SourceList(sourceList));
}

private PartialAttribute MaybeParseAttribute()
{
if (_curs.TidCur != TokKind.BracketOpen)
Expand Down Expand Up @@ -1318,8 +1283,7 @@ private TexlNode ParseOperand()

if (AfterSpaceTokenId() == TokKind.ParenOpen)
{
if (ident.Token.As<IdentToken>().Name.Value == LanguageConstants.TypeLiteralInvariantName
&& _features.IsUserDefinedTypesEnabled)
if (ident.Token.As<IdentToken>().Name.Value == LanguageConstants.TypeLiteralInvariantName && _features.IsUserDefinedTypesEnabled)
{
var typeLiteralNode = ParseTypeLiteral(ident);

Expand All @@ -1331,13 +1295,6 @@ private TexlNode ParseOperand()
return typeLiteralNode;
}

if (ident.Token.As<IdentToken>().Name.Value == LanguageConstants.RecordOfInvariantName
&& _flagsMode.Peek().HasFlag(Flags.ParseAsRecordOf)
&& _features.IsUserDefinedTypesEnabled)
{
return ParseRecordOf(ident);
}

trivia = ParseTrivia();

return ParseInvocation(ident, trivia, null);
Expand Down
3 changes: 1 addition & 2 deletions src/libraries/Microsoft.PowerFx.Core/Syntax/NodeKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public enum NodeKind

Error,
StrInterp,
TypeLiteral,
RecordOf
TypeLiteral
}
}
53 changes: 0 additions & 53 deletions src/libraries/Microsoft.PowerFx.Core/Syntax/Nodes/RecordOfNode.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal TypeLiteralNode(ref int idNext, Token firstToken, TexlNode type, Source
: base(ref idNext, firstToken, sources)
{
TypeRoot = type;
TypeRoot.Parent = this;
}

internal override TexlNode Clone(ref int idNext, Span ts)
Expand Down Expand Up @@ -89,10 +90,6 @@ public override void Visit(FirstNameNode node)
{
}

public override void Visit(RecordOfNode node)
{
}

public override bool PreVisit(RecordNode node)
{
return true;
Expand Down Expand Up @@ -195,12 +192,28 @@ public override bool PreVisit(VariadicOpNode node)

public override bool PreVisit(CallNode node)
{
if (node.Parent is TypeLiteralNode &&
node.Head.Token.Name == LanguageConstants.RecordOfInvariantName &&
node.Args.Count == 1 &&
node.Args.ChildNodes.Single().AsFirstName() != null)
{
return true;
}

_errors.Add(new TexlError(node, DocumentErrorSeverity.Severe, TexlStrings.ErrTypeLiteral_InvalidTypeDefinition, node.ToString()));
return false;
}

public override bool PreVisit(ListNode node)
{
if (node.Parent is CallNode cn &&
cn.Head.Token.Name == LanguageConstants.RecordOfInvariantName &&
node.ChildNodes.Count == 1 &&
node.ChildNodes.Single().AsFirstName() != null)
{
return true;
}

_errors.Add(new TexlError(node, DocumentErrorSeverity.Severe, TexlStrings.ErrTypeLiteral_InvalidTypeDefinition, node.ToString()));
return false;
}
Expand Down
24 changes: 0 additions & 24 deletions src/libraries/Microsoft.PowerFx.Core/Syntax/TexlPretty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,23 +417,6 @@ public override LazyList<string> Visit(TypeLiteralNode node, Precedence parentPr
.With(node.TypeRoot.Accept(this, Precedence.Atomic))
.With(TexlLexer.PunctuatorParenClose);

return result;
}

public override LazyList<string> Visit(RecordOfNode node, Precedence parentPrecedence)
{
Contracts.AssertValue(node);

var result = LazyList<string>.Empty;
var sb = new StringBuilder();

result = result
.With(
LanguageConstants.TypeLiteralInvariantName,
TexlLexer.PunctuatorParenOpen)
.With(node.TableName.Accept(this, Precedence.None))
.With(TexlLexer.PunctuatorParenClose);

return result;
}

Expand Down Expand Up @@ -1018,13 +1001,6 @@ public override LazyList<string> Visit(TypeLiteralNode node, Context context)
{
Contracts.AssertValue(node);

return Basic(node, context);
}

public override LazyList<string> Visit(RecordOfNode node, Context context)
{
Contracts.AssertValue(node);

return Basic(node, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,28 @@ public override DType Visit(TableNode node, INameResolver context)
return rowType.ToTable();
}

public override DType Visit(RecordOfNode node, INameResolver context)
public override DType Visit(CallNode node, INameResolver context)
{
Contracts.AssertValue(node);
Contracts.AssertValue(context);
Contracts.AssertValue(node.Args);
Contracts.AssertAllValues(node.Args.ChildNodes);

var inputType = node.TableName.Accept(this, context);
if (node.Head.Name != LanguageConstants.RecordOfInvariantName ||
node.Args.Count != 1 ||
node.Args.ChildNodes.Single().AsFirstName() == null)
{
return DType.Invalid;
}

var childType = node.Args.ChildNodes.Single().Accept(this, context);

if (!inputType.IsTable)
if (!childType.IsTable)
{
return DType.Invalid;
}

return inputType.ToRecord();
return childType.ToRecord();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ public override void Visit(FirstNameNode node)
/// <inheritdoc />
public override void Visit(ParentNode node)
{
}

/// <inheritdoc />
public override void Visit(RecordOfNode node)
{
}

/// <inheritdoc />
public override void Visit(SelfNode node)
{
}

/// <inheritdoc />
public override void Visit(TypeLiteralNode node)
{
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ public abstract class TexlFunctionalVisitor<TResult, TContext>
/// <param name="context">The context passed to the node.</param>
/// <returns>The node visit result.</returns>
public abstract TResult Visit(TypeLiteralNode node, TContext context);

/// <summary>
/// Visit <see cref="RecordOfNode"/> leaf node.
/// </summary>
/// <param name="node">The visited node.</param>
/// <param name="context">The context passed to the node.</param>
/// <returns>The node visit result.</returns>
public abstract TResult Visit(RecordOfNode node, TContext context);

/// <summary>
/// Visit <see cref="ErrorNode" /> leaf node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,7 @@ public abstract class TexlVisitor
/// Visit <see cref="TypeLiteralNode"/> leaf node.
/// </summary>
/// <param name="node">The visited node.</param>
public virtual void Visit(TypeLiteralNode node)
{
}

/// <summary>
/// Visit <see cref="RecordOfNode"/> leaf node.
/// </summary>
/// <param name="node">The visited node.</param>
public abstract void Visit(RecordOfNode node);
public abstract void Visit(TypeLiteralNode node);

/// <summary>
/// Visit <see cref="ErrorNode" /> leaf node.
Expand Down
Loading

0 comments on commit 71d67e0

Please sign in to comment.