internal static IEnumerable <SemanticToken> ConvertToSemanticTokens(Token token) { if (token is StringExpandableToken stringExpandableToken) { // Try parsing tokens within the string if (stringExpandableToken.NestedTokens != null) { foreach (Token t in stringExpandableToken.NestedTokens) { foreach (SemanticToken subToken in ConvertToSemanticTokens(t)) { yield return(subToken); } } yield break; } } SemanticTokenType mappedType = MapSemanticTokenType(token); if (mappedType == null) { yield break; } //Note that both column and line numbers are 0-based yield return(new SemanticToken( token.Text, mappedType, line: token.Extent.StartLineNumber - 1, column: token.Extent.StartColumnNumber - 1, tokenModifiers: Array.Empty <string>())); }
public InputToken(Regex match, SemanticTokenType tokenType, OperationType operationType = OperationType.Operator, TokenDiscardPolicy discardPolicy = TokenDiscardPolicy.Keep) { m_TokenType = tokenType; m_DiscardPolicy = discardPolicy; m_OperationType = operationType; m_Regex = match; }
public Var(VarInfo varInfo) { Name = varInfo.Name; DefinedAt = varInfo.DefinedAt; _parseInfo = varInfo.ParseInfo; AccessLevel = varInfo.AccessLevel; WholeContext = varInfo.WholeContext; CodeType = varInfo.Type; InExtendedCollection = varInfo.InExtendedCollection; Ref = varInfo.Ref; ID = varInfo.ID; Static = varInfo.Static; Recursive = varInfo.Recursive; BridgeInvocable = varInfo.BridgeInvocable; RequiresCapture = varInfo.RequiresCapture; IsMacro = varInfo.IsMacro; Virtual = varInfo.Virtual; Override = varInfo.Override; _tokenType = varInfo.TokenType; _tokenModifiers = varInfo.TokenModifiers.ToArray(); _handleRestrictedCalls = varInfo.HandleRestrictedCalls; _inferType = varInfo.InferType; _initialValueContext = varInfo.InitialValueContext; _initialValueResolve = varInfo.InitialValueResolve; _operationalScope = varInfo.Scope; _variableTypeHandler = varInfo.VariableTypeHandler; if (!_inferType) { AddScriptData(); } if (ID != -1) { if (VariableType == VariableType.Global) { _parseInfo.TranslateInfo.VarCollection.Reserve(ID, true, _parseInfo.Script.Diagnostics, DefinedAt.range); } else if (VariableType == VariableType.Player) { _parseInfo.TranslateInfo.VarCollection.Reserve(ID, false, _parseInfo.Script.Diagnostics, DefinedAt.range); } } // Get the initial value. if (_initialValueResolve == InitialValueResolve.Instant) { GetInitialValue(); } else { _parseInfo.TranslateInfo.StagedInitiation.On(InitiationStage.Content, GetInitialValue); } if (DefinedAt != null) { _parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, _parseInfo, varInfo.CodeLensType, DefinedAt.range)); _parseInfo.Script.Elements.AddDeclarationCall(this, new DeclarationCall(DefinedAt.range, true)); } }
public SemanticToken(int line, int character, int length, SemanticTokenType tokenType) { Line = line; Character = character; Length = length; TokenType = tokenType; }
public SemanticToken(string text, SemanticTokenType type, int line, int column, IEnumerable <string> tokenModifiers) { Line = line; Text = text; Column = column; Type = type; TokenModifiers = tokenModifiers; }
private static string GetTokenName(SemanticTokenType tokenType) { switch (tokenType) { case Deltin.Deltinteger.Parse.SemanticTokenType.TypeParameter: return("typeParameter"); default: return(tokenType.ToString().ToLower()); } }
public NormalizedToken(string text, SemanticTokenType type, params SemanticTokenModifier[] modifiers) { Text = text; Type = type; Modifiers = modifiers; }
public void AddToken(string stringToMatch, SemanticTokenType tokenType, OperationType operationType = OperationType.Operator, TokenDiscardPolicy discardPolicy = TokenDiscardPolicy.Keep) { m_Tokens.Add(new InputToken(new Regex(stringToMatch, RegexOptions.IgnoreCase), tokenType, operationType, discardPolicy)); // Add tokens in order of precedence }
public void AddToken(Regex match, SemanticTokenType tokenType, OperationType operationType = OperationType.Operator, TokenDiscardPolicy discardPolicy = TokenDiscardPolicy.Keep) { m_Tokens.Add(new InputToken(match, tokenType, operationType, discardPolicy)); // Add tokens in order of precedence }
public SemanticToken(DocRange range, SemanticTokenType tokenType, params TokenModifier[] modifiers) { Range = range; TokenType = GetTokenName(tokenType); Modifiers = modifiers == null ? new string[0] : Array.ConvertAll(modifiers, modifier => GetModifierName(modifier)); }