public FieldParameterSyntax(TextSpan span, Name name, IExpressionSyntax?defaultValue) : base(span, name) { Name = name; DefaultValue = defaultValue; DataType = ReferencedSymbol.Select(s => s?.DataType ?? Types.DataType.Unknown); }
// Requires the binding has already been consumed private IStatementSyntax ParseRestOfVariableDeclaration( TextSpan binding, bool mutableBinding) { var identifier = Tokens.RequiredToken <IIdentifierToken>(); var name = identifier.Value; ITypeSyntax?type = null; bool inferMutableType = false; if (Tokens.Accept <IColonToken>()) { (type, inferMutableType) = ParseVariableDeclarationType(); } IExpressionSyntax?initializer = null; if (Tokens.Accept <IEqualsToken>()) { initializer = ParseExpression(); } var semicolon = Tokens.Expect <ISemicolonToken>(); var span = TextSpan.Covering(binding, semicolon); return(new VariableDeclarationStatementSyntax(span, mutableBinding, name, identifier.Span, type, inferMutableType, initializer)); }
internal FieldDeclarationSyntax ParseField( IClassDeclarationSyntax declaringType, bool mutableBinding, ModifierParser modifiers) { var accessModifer = modifiers.ParseAccessModifier(); modifiers.ParseEndOfModifiers(); // We should only be called when there is a binding keyword var binding = Tokens.Required <IBindingToken>(); var identifier = Tokens.RequiredToken <IIdentifierToken>(); Name name = identifier.Value; Tokens.Expect <IColonToken>(); var type = ParseType(); IExpressionSyntax?initializer = null; if (Tokens.Accept <IEqualsToken>()) { initializer = ParseExpression(); } var semicolon = Tokens.Expect <ISemicolonToken>(); var span = TextSpan.Covering(binding, semicolon); return(new FieldDeclarationSyntax(declaringType, span, File, accessModifer, mutableBinding, identifier.Span, name, type, initializer)); }
public BreakExpressionSyntax( TextSpan span, IExpressionSyntax?value) : base(span, ExpressionSemantics.Void) { this.value = value; }
public ReturnStatementSyntax(ISyntaxNode parent, JurParser.ReturnStatementContext context) : base(parent, context) { if (context.expression() != null) { ReturnValue = ToExpression(context.expression()); } ImmediateChildren = ImmutableArray.Create <ITreeNode>().AddIfNotNull(ReturnValue); }
private static string GetExpressionDisplayString(IExpressionSyntax?expression) { if (expression is null) { return("<null>"); } return($"'{expression}'<{expression.GetType().Name}>"); }
public void TestExpressionParser(string expression, IExpressionSyntax?expected = null) { if (expected is null) { SyntaxAssert.ExpressionThrowsException(expression); } else { var actual = JassPidginParser.ParseExpression(expression); SyntaxAssert.AreEqual(expected, actual); } }
private bool TryAdaptExpression(JassMapScriptAdapterContext context, IExpressionSyntax?expression, [NotNullWhen(true)] out IExpressionSyntax?adaptedExpression) { return(expression switch { JassFunctionReferenceExpressionSyntax functionReferenceExpression => TryAdaptFunctionReferenceExpression(context, functionReferenceExpression, out adaptedExpression), JassInvocationExpressionSyntax invocationExpression => TryAdaptInvocationExpression(context, invocationExpression, out adaptedExpression), JassArrayReferenceExpressionSyntax arrayReferenceExpression => TryAdaptArrayReferenceExpression(context, arrayReferenceExpression, out adaptedExpression), JassVariableReferenceExpressionSyntax variableReferenceExpression => TryAdaptVariableReferenceExpression(context, variableReferenceExpression, out adaptedExpression), JassParenthesizedExpressionSyntax parenthesizedExpression => TryAdaptParenthesizedExpression(context, parenthesizedExpression, out adaptedExpression), JassUnaryExpressionSyntax unaryExpression => TryAdaptUnaryExpression(context, unaryExpression, out adaptedExpression), JassBinaryExpressionSyntax binaryExpression => TryAdaptBinaryExpression(context, binaryExpression, out adaptedExpression), _ => TryAdaptDummy(context, expression, out adaptedExpression), });
public NamedParameterSyntax( TextSpan span, bool isMutableBinding, Name name, ITypeSyntax typeSyntax, IExpressionSyntax?defaultValue) : base(span, name) { IsMutableBinding = isMutableBinding; Name = name; Type = typeSyntax; DefaultValue = defaultValue; DataType = Symbol.Select(s => s.DataType); }
public FieldDeclarationSyntax( IClassDeclarationSyntax declaringClass, TextSpan span, CodeFile file, IAccessModifierToken?accessModifier, bool mutableBinding, TextSpan nameSpan, Name name, ITypeSyntax type, IExpressionSyntax?initializer) : base(declaringClass, span, file, accessModifier, nameSpan, name, new AcyclicPromise <FieldSymbol>()) { IsMutableBinding = mutableBinding; Name = name; Type = type; this.initializer = initializer; Symbol = (AcyclicPromise <FieldSymbol>)base.Symbol; }
public INamedParameterSyntax ParseFunctionParameter() { var span = Tokens.Current.Span; var mutableBinding = Tokens.Accept <IVarKeywordToken>(); var identifier = Tokens.RequiredToken <IIdentifierOrUnderscoreToken>(); var name = identifier.Value; Tokens.Expect <IColonToken>(); var type = ParseType(); IExpressionSyntax?defaultValue = null; if (Tokens.Accept <IEqualsToken>()) { defaultValue = ParseExpression(); } span = TextSpan.Covering(span, type.Span, defaultValue?.Span); return(new NamedParameterSyntax(span, mutableBinding, name, type, defaultValue)); }
public IConstructorParameterSyntax ParseConstructorParameter() { switch (Tokens.Current) { case IDotToken _: { var dot = Tokens.Expect <IDotToken>(); var identifier = Tokens.RequiredToken <IIdentifierToken>(); var equals = Tokens.AcceptToken <IEqualsToken>(); IExpressionSyntax?defaultValue = null; if (equals != null) { defaultValue = ParseExpression(); } var span = TextSpan.Covering(dot, identifier.Span, defaultValue?.Span); Name name = identifier.Value; return(new FieldParameterSyntax(span, name, defaultValue)); } default: return(ParseFunctionParameter()); } }
public bool Equals(IExpressionSyntax?other) => other is JassNullLiteralExpressionSyntax;
public JassReturnStatementSyntax(IExpressionSyntax?value = null) { Value = value; }
private bool TryAdaptArrayReferenceExpression(JassMapScriptAdapterContext context, JassArrayReferenceExpressionSyntax arrayReferenceExpression, [NotNullWhen(true)] out IExpressionSyntax?adaptedArrayReferenceExpression) { if (!context.KnownLocalVariables.ContainsKey(arrayReferenceExpression.IdentifierName.Name) && !context.KnownGlobalVariables.ContainsKey(arrayReferenceExpression.IdentifierName.Name)) { context.Diagnostics.Add($"Unknown array '{arrayReferenceExpression.IdentifierName}'."); } if (TryAdaptExpression(context, arrayReferenceExpression.Indexer, out var adaptedIndexer)) { adaptedArrayReferenceExpression = new JassArrayReferenceExpressionSyntax( arrayReferenceExpression.IdentifierName, adaptedIndexer); return(true); } adaptedArrayReferenceExpression = null; return(false); }
private bool TryAdaptUnaryExpression(JassMapScriptAdapterContext context, JassUnaryExpressionSyntax unaryExpression, [NotNullWhen(true)] out IExpressionSyntax? adaptedUnaryExpression) { if (TryAdaptExpression(context, unaryExpression.Expression, out var adaptedExpression)) { adaptedUnaryExpression = new JassUnaryExpressionSyntax( unaryExpression.Operator, adaptedExpression); return true; } adaptedUnaryExpression = null; return false; }
private bool TryAdaptParenthesizedExpression(JassMapScriptAdapterContext context, JassParenthesizedExpressionSyntax parenthesizedExpression, [NotNullWhen(true)] out IExpressionSyntax?adaptedParenthesizedExpression) { if (TryAdaptExpression(context, parenthesizedExpression.Expression, out var adaptedExpression)) { adaptedParenthesizedExpression = new JassParenthesizedExpressionSyntax(adaptedExpression); return(true); } adaptedParenthesizedExpression = null; return(false); }
private bool TryAdaptBinaryExpression(JassMapScriptAdapterContext context, JassBinaryExpressionSyntax binaryExpression, [NotNullWhen(true)] out IExpressionSyntax?adaptedBinaryExpression) { if (TryAdaptExpression(context, binaryExpression.Left, out var adaptedLeftExpression) | TryAdaptExpression(context, binaryExpression.Right, out var adaptedRightExpression)) { adaptedBinaryExpression = new JassBinaryExpressionSyntax( binaryExpression.Operator, adaptedLeftExpression ?? binaryExpression.Left, adaptedRightExpression ?? binaryExpression.Right); return(true); } adaptedBinaryExpression = null; return(false); }
private bool TryAdaptFunctionReferenceExpression(JassMapScriptAdapterContext context, JassFunctionReferenceExpressionSyntax functionReferenceExpression, [NotNullWhen(true)] out IExpressionSyntax?adaptedFunctionReferenceExpression) { if (context.KnownFunctions.TryGetValue(functionReferenceExpression.IdentifierName.Name, out var knownFunctionParameters)) { if (knownFunctionParameters.Length != 0) { context.Diagnostics.Add($"Invalid function reference: '{functionReferenceExpression.IdentifierName}' should not have any parameters."); } } else { context.Diagnostics.Add($"Unknown function '{functionReferenceExpression.IdentifierName}'."); } adaptedFunctionReferenceExpression = null; return(false); }
public AbstractVariableDeclarationSyntax(string variableName, IExpressionSyntax?initializer) { VariableName = variableName; Initializer = initializer; }
private bool TryAdaptInvocationExpression(JassMapScriptAdapterContext context, JassInvocationExpressionSyntax invocationExpression, [NotNullWhen(true)] out IExpressionSyntax?adaptedInvocationExpression) { if (TryAdaptInvocation(context, invocationExpression, out var adaptedInvocationName, out var adaptedInvocationArguments)) { if (string.IsNullOrEmpty(adaptedInvocationName)) { context.Diagnostics.Add($"Invocation expression of function '{invocationExpression.IdentifierName}' should be removed."); adaptedInvocationExpression = invocationExpression; } else if (TryAdaptArgumentList(context, adaptedInvocationArguments, out var adaptedArguments)) { adaptedInvocationExpression = JassSyntaxFactory.InvocationExpression( adaptedInvocationName, adaptedArguments); } else { adaptedInvocationExpression = JassSyntaxFactory.InvocationExpression( adaptedInvocationName, adaptedInvocationArguments); } return(true); }
private bool TryAdaptVariableReferenceExpression(JassMapScriptAdapterContext context, JassVariableReferenceExpressionSyntax variableReferenceExpression, [NotNullWhen(true)] out IExpressionSyntax?adaptedVariableReferenceExpression) { if (!context.KnownLocalVariables.ContainsKey(variableReferenceExpression.IdentifierName.Name) && !context.KnownGlobalVariables.ContainsKey(variableReferenceExpression.IdentifierName.Name)) { context.Diagnostics.Add($"Unknown variable '{variableReferenceExpression.IdentifierName}'."); } adaptedVariableReferenceExpression = null; return(false); }
public JassSetStatementSyntax(JassIdentifierNameSyntax identifierName, IExpressionSyntax?indexer, JassEqualsValueClauseSyntax value) { IdentifierName = identifierName; Indexer = indexer; Value = value; }
public static void AreEqual(IExpressionSyntax?expected, IExpressionSyntax?actual) { Assert.IsTrue(ReferenceEquals(expected, actual) || expected?.Equals(actual) == true, GetAssertFailedMessage(expected, actual)); }