public FunctionArgumentSyntax(SyntaxBase expression) { this.Expression = expression; }
public OutputDeclarationSyntax(Token outputKeyword, IdentifierSyntax name, TypeSyntax type, Token assignment, SyntaxBase value, Token?newLine) { AssertKeyword(outputKeyword, nameof(outputKeyword), LanguageConstants.OutputKeyword); AssertTokenType(assignment, nameof(assignment), TokenType.Assignment); AssertTokenType(newLine, nameof(newLine), TokenType.NewLine); this.OutputKeyword = outputKeyword; this.Name = name; this.Type = type; this.Assignment = assignment; this.Value = value; this.NewLine = newLine; }
public ResourceDeclarationSyntax(Token keyword, IdentifierSyntax name, SyntaxBase type, SyntaxBase assignment, SyntaxBase?ifCondition, SyntaxBase body) { AssertKeyword(keyword, nameof(keyword), LanguageConstants.ResourceKeyword); AssertSyntaxType(name, nameof(name), typeof(IdentifierSyntax)); AssertSyntaxType(type, nameof(type), typeof(StringSyntax), typeof(SkippedTriviaSyntax)); AssertTokenType(keyword, nameof(keyword), TokenType.Identifier); AssertSyntaxType(assignment, nameof(assignment), typeof(Token), typeof(SkippedTriviaSyntax)); AssertTokenType(assignment as Token, nameof(assignment), TokenType.Assignment); AssertSyntaxType(ifCondition, nameof(ifCondition), typeof(SkippedTriviaSyntax), typeof(IfConditionSyntax)); AssertSyntaxType(body, nameof(body), typeof(SkippedTriviaSyntax), typeof(ObjectSyntax)); this.Keyword = keyword; this.Name = name; this.Type = type; this.Assignment = assignment; this.IfCondition = ifCondition; this.Body = body; }
public ParameterDeclarationSyntax(IEnumerable <SyntaxBase> leadingNodes, Token keyword, IdentifierSyntax name, SyntaxBase type, SyntaxBase?modifier) : base(leadingNodes) { AssertKeyword(keyword, nameof(keyword), LanguageConstants.ParameterKeyword); AssertSyntaxType(name, nameof(name), typeof(IdentifierSyntax)); AssertSyntaxType(type, nameof(type), typeof(TypeSyntax), typeof(SkippedTriviaSyntax)); AssertSyntaxType(modifier, nameof(modifier), typeof(ParameterDefaultValueSyntax), typeof(SkippedTriviaSyntax)); this.Keyword = keyword; this.Name = name; this.Type = type; this.Modifier = modifier; }
public ImportDeclarationSyntax(IEnumerable <SyntaxBase> leadingNodes, Token keyword, IdentifierSyntax providerName, SyntaxBase asKeyword, IdentifierSyntax aliasName, SyntaxBase?config) : base(leadingNodes) { AssertKeyword(keyword, nameof(keyword), LanguageConstants.ImportKeyword); AssertSyntaxType(providerName, nameof(providerName), typeof(IdentifierSyntax)); AssertSyntaxType(asKeyword, nameof(asKeyword), typeof(Token), typeof(SkippedTriviaSyntax)); AssertSyntaxType(aliasName, nameof(aliasName), typeof(IdentifierSyntax)); AssertSyntaxType(config, nameof(config), typeof(ObjectSyntax), typeof(SkippedTriviaSyntax)); this.Keyword = keyword; this.ProviderName = providerName; this.AsKeyword = asKeyword; this.AliasName = aliasName; this.Config = config; }
public static ForSyntax CreateForSyntax(string indexIdentifier, SyntaxBase inSyntax, SyntaxBase body) { // generates "[for <identifier> in <inSyntax>: <body>]" return(new( LeftSquareToken, CreateToken(TokenType.Identifier, "for"), new LocalVariableSyntax(new IdentifierSyntax(CreateToken(TokenType.Identifier, indexIdentifier))), CreateToken(TokenType.Identifier, "in"), inSyntax, ColonToken, body, RightSquareToken)); }
public static ArrayItemSyntax CreateArrayItem(SyntaxBase value) => new ArrayItemSyntax(value);
public ModuleDeclarationSyntax(Token keyword, IdentifierSyntax name, SyntaxBase path, SyntaxBase assignment, SyntaxBase body) { AssertKeyword(keyword, nameof(keyword), LanguageConstants.ModuleKeyword); AssertSyntaxType(name, nameof(name), typeof(IdentifierSyntax)); AssertSyntaxType(path, nameof(path), typeof(StringSyntax), typeof(SkippedTriviaSyntax)); AssertTokenType(keyword, nameof(keyword), TokenType.Identifier); AssertSyntaxType(assignment, nameof(assignment), typeof(Token), typeof(SkippedTriviaSyntax)); AssertTokenType(assignment as Token, nameof(assignment), TokenType.Assignment); AssertSyntaxType(body, nameof(body), typeof(SkippedTriviaSyntax), typeof(ObjectSyntax)); this.Keyword = keyword; this.Name = name; this.Path = path; this.Assignment = assignment; this.Body = body; }
public static ObjectSyntax MergeProperty(this ObjectSyntax?syntax, string propertyName, SyntaxBase propertyValue) { if (syntax == null) { return(SyntaxFactory.CreateObject(SyntaxFactory.CreateObjectProperty(propertyName, propertyValue).AsEnumerable())); } var properties = syntax.Properties.ToList(); int matchingIndex = 0; while (matchingIndex < properties.Count) { if (string.Equals(properties[matchingIndex].TryGetKeyText(), propertyName, LanguageConstants.IdentifierComparison)) { break; } matchingIndex++; } if (matchingIndex < properties.Count) { // If both property values are objects, merge them. Otherwise, replace the matching property value. SyntaxBase mergedValue = properties[matchingIndex].Value is ObjectSyntax sourceObject && propertyValue is ObjectSyntax targetObject ? sourceObject.DeepMerge(targetObject) : propertyValue; properties[matchingIndex] = SyntaxFactory.CreateObjectProperty(propertyName, mergedValue); } else { properties.Add(SyntaxFactory.CreateObjectProperty(propertyName, propertyValue)); } return(SyntaxFactory.CreateObject(properties)); }
protected virtual void VisitInternal(SyntaxBase node) { node.Accept(this); }
public VariableDeclarationSyntax(Token variableKeyword, IdentifierSyntax name, Token assignment, SyntaxBase value) { AssertKeyword(variableKeyword, nameof(variableKeyword), LanguageConstants.VariableKeyword); AssertTokenType(assignment, nameof(assignment), TokenType.Assignment); this.VariableKeyword = variableKeyword; this.Name = name; this.Assignment = assignment; this.Value = value; }
/// <summary> /// Gets the nearest ancestor assignable to <typeparamref name="TSyntax" /> above <paramref name="syntax" /> /// in an ascending walk towards the root of the syntax tree. /// </summary> /// <param name="syntax">The syntax node.</param> /// <typeparam name="TSyntax">The type of node to query.</typeparam> /// <returns>The nearest ancestor or <c>null</c>.</returns> public TSyntax?GetNearestAncestor <TSyntax>(SyntaxBase syntax) where TSyntax : SyntaxBase => // Use default implementation ((ISyntaxHierarchy)this).GetNearestAncestor <TSyntax>(syntax);
/// <summary> /// Gets all ancestor nodes assignable to <typeparamref name="TSyntax" /> in descending order /// from the top of the tree. /// </summary> /// <param name="syntax">The syntax node.</param> /// <typeparam name="TSyntax">The type of node to query.</typeparam> /// <returns>The list of ancestors.</returns> public ImmutableArray <TSyntax> GetAllAncestors <TSyntax>(SyntaxBase syntax) where TSyntax : SyntaxBase => // Use default implementation ((ISyntaxHierarchy)this).GetAllAncestors <TSyntax>(syntax);
public TernaryOperationSyntax(SyntaxBase conditionExpression, Token question, SyntaxBase trueExpression, Token colon, SyntaxBase falseExpression) { AssertTokenType(question, nameof(question), TokenType.Question); AssertTokenType(colon, nameof(colon), TokenType.Colon); this.ConditionExpression = conditionExpression; this.Question = question; this.TrueExpression = trueExpression; this.Colon = colon; this.FalseExpression = falseExpression; }
public ModuleDeclarationSyntax(IEnumerable <SyntaxBase> leadingNodes, Token keyword, IdentifierSyntax name, SyntaxBase path, SyntaxBase assignment, SyntaxBase value) : base(leadingNodes) { AssertKeyword(keyword, nameof(keyword), LanguageConstants.ModuleKeyword); AssertSyntaxType(name, nameof(name), typeof(IdentifierSyntax)); AssertSyntaxType(path, nameof(path), typeof(StringSyntax), typeof(SkippedTriviaSyntax)); AssertTokenType(keyword, nameof(keyword), TokenType.Identifier); AssertSyntaxType(assignment, nameof(assignment), typeof(Token), typeof(SkippedTriviaSyntax)); AssertTokenType(assignment as Token, nameof(assignment), TokenType.Assignment); AssertSyntaxType(value, nameof(value), typeof(SkippedTriviaSyntax), typeof(ObjectSyntax), typeof(IfConditionSyntax), typeof(ForSyntax)); this.Keyword = keyword; this.Name = name; this.Path = path; this.Assignment = assignment; this.Value = value; }
/// <summary> /// Adds a root node and indexes the parents for all child nodes recursively. /// </summary> /// <param name="root">The root node.</param> public void AddRoot(SyntaxBase root) { var visitor = new ParentTrackingVisitor(this.parentMap); visitor.Visit(root); }
public OutputDeclarationSyntax(Token keyword, IdentifierSyntax name, SyntaxBase type, SyntaxBase assignment, SyntaxBase value) { AssertKeyword(keyword, nameof(keyword), LanguageConstants.OutputKeyword); AssertSyntaxType(name, nameof(name), typeof(IdentifierSyntax), typeof(IdentifierSyntax)); AssertSyntaxType(type, nameof(type), typeof(TypeSyntax), typeof(SkippedTriviaSyntax)); AssertSyntaxType(assignment, nameof(assignment), typeof(Token), typeof(SkippedTriviaSyntax)); AssertTokenType(assignment as Token, nameof(assignment), TokenType.Assignment); this.Keyword = keyword; this.Name = name; this.Type = type; this.Assignment = assignment; this.Value = value; }
public TokenOrSyntax(SyntaxBase syntax) { Syntax = syntax; Span = syntax.Span; }
public static ObjectPropertySyntax CreateObjectProperty(string key, SyntaxBase value) => new ObjectPropertySyntax(CreateObjectPropertyKey(key), CreateToken(TokenType.Colon, ":"), value);
public static bool HasParseErrors(this SyntaxBase syntax) => syntax.GetParseDiagnostics().Any(d => d.Level == DiagnosticLevel.Error);
public static ForSyntax CreateRangedForSyntax(string indexIdentifier, SyntaxBase count, SyntaxBase body) { // generates "range(0, <count>)" var rangeSyntax = new FunctionCallSyntax( CreateIdentifier("range"), LeftParenToken, new FunctionArgumentSyntax[] { new FunctionArgumentSyntax( new IntegerLiteralSyntax(CreateToken(TokenType.Integer, "0"), 0), CommaToken), new FunctionArgumentSyntax(count, null), }, RightParenToken); return(CreateForSyntax(indexIdentifier, rangeSyntax, body)); }
public ResourceDeclarationSyntax(IEnumerable <SyntaxBase> leadingNodes, Token keyword, IdentifierSyntax name, SyntaxBase type, Token?existingKeyword, SyntaxBase assignment, SyntaxBase value) : base(leadingNodes) { AssertKeyword(keyword, nameof(keyword), LanguageConstants.ResourceKeyword); AssertSyntaxType(name, nameof(name), typeof(IdentifierSyntax)); AssertSyntaxType(type, nameof(type), typeof(StringSyntax), typeof(SkippedTriviaSyntax)); AssertKeyword(existingKeyword, nameof(existingKeyword), LanguageConstants.ExistingKeyword); AssertTokenType(keyword, nameof(keyword), TokenType.Identifier); AssertSyntaxType(assignment, nameof(assignment), typeof(Token), typeof(SkippedTriviaSyntax)); AssertTokenType(assignment as Token, nameof(assignment), TokenType.Assignment); AssertSyntaxType(value, nameof(value), typeof(SkippedTriviaSyntax), typeof(ObjectSyntax), typeof(IfConditionSyntax), typeof(ForSyntax)); this.Keyword = keyword; this.Name = name; this.Type = type; this.ExistingKeyword = existingKeyword; this.Assignment = assignment; this.Value = value; }
public ArrayItemSyntax(SyntaxBase value) { this.Value = value; }
public ResourceDeclarationSyntax(Token resourceKeyword, IdentifierSyntax name, SyntaxBase type, Token assignment, SyntaxBase body) { AssertKeyword(resourceKeyword, nameof(resourceKeyword), LanguageConstants.ResourceKeyword); AssertTokenType(resourceKeyword, nameof(resourceKeyword), TokenType.Identifier); AssertTokenType(assignment, nameof(assignment), TokenType.Assignment); this.ResourceKeyword = resourceKeyword; this.Name = name; this.Type = type; this.Assignment = assignment; this.Body = body; }