Return break, continue и exit in completion list (#3298)
This commit is contained in:
parent
5abe6333ba
commit
0972d09837
|
|
@ -389,7 +389,7 @@ namespace CodeCompletion
|
|||
public List<string> GetKeywords()
|
||||
{
|
||||
if (CodeCompletionController.CurrentParser != null)
|
||||
return CodeCompletionController.CurrentParser.LanguageInformation.KeywordsStorage.Keywords;
|
||||
return CodeCompletionController.CurrentParser.LanguageInformation.KeywordsStorage.KeywordsForIntellisenseList;
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -754,9 +754,9 @@ namespace PascalABCCompiler.Parsers
|
|||
|
||||
public abstract bool IsDefinitionIdentifierAfterKeyword(KeywordKind keyw);
|
||||
|
||||
public virtual bool IsKeyword(string value)
|
||||
public bool IsKeyword(string value)
|
||||
{
|
||||
return KeywordsStorage.KeywordsToTokens.ContainsKey(value);
|
||||
return KeywordsStorage.KeywordsForIntellisenseSet.Contains(value);
|
||||
}
|
||||
|
||||
public abstract bool IsMethodCallParameterSeparator(char key);
|
||||
|
|
|
|||
|
|
@ -10,14 +10,28 @@ namespace PascalABCCompiler.Parsers
|
|||
public abstract class BaseKeywords
|
||||
{
|
||||
/// <summary>
|
||||
/// Соотвествие ключевых слов токенам
|
||||
/// Соотвествие ключевых слов токенам (ключевые слова для парсера)
|
||||
/// </summary>
|
||||
public Dictionary<string, int> KeywordsToTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Типы ключевых слов
|
||||
/// </summary>
|
||||
public Dictionary<string, KeywordKind> KeywordKinds { get; set; }
|
||||
|
||||
public List<string> Keywords { get; set; } = new List<string>();
|
||||
/// <summary>
|
||||
/// Ключевые слова в контексте Intellisense (множество)
|
||||
/// </summary>
|
||||
public HashSet<string> KeywordsForIntellisenseSet { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Ключевые слова в контексте Intellisense (список)
|
||||
/// </summary>
|
||||
public List<string> KeywordsForIntellisenseList { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Ключевые слова, соответствующие типам (array, set), либо классу, функции
|
||||
/// </summary>
|
||||
public List<string> TypeKeywords { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -42,7 +56,7 @@ namespace PascalABCCompiler.Parsers
|
|||
if (System.IO.File.Exists(pathToKeymapFile))
|
||||
keymap = System.IO.File.ReadLines(pathToKeymapFile, Encoding.Unicode).Select(s => s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)).ToDictionary(w => w[0], w => w[1]);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception)
|
||||
{
|
||||
//var w = e.Message;
|
||||
}
|
||||
|
|
@ -63,9 +77,13 @@ namespace PascalABCCompiler.Parsers
|
|||
{
|
||||
ReloadKeyMap();
|
||||
|
||||
KeywordsToTokens = new Dictionary<string, int>(caseSensitive ? StringComparer.CurrentCulture : StringComparer.CurrentCultureIgnoreCase);
|
||||
StringComparer stringComparer = caseSensitive ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase;
|
||||
|
||||
KeywordKinds = new Dictionary<string, KeywordKind>(caseSensitive ? StringComparer.CurrentCulture : StringComparer.CurrentCultureIgnoreCase);
|
||||
KeywordsToTokens = new Dictionary<string, int>(stringComparer);
|
||||
|
||||
KeywordsForIntellisenseSet = new HashSet<string>(stringComparer);
|
||||
|
||||
KeywordKinds = new Dictionary<string, KeywordKind>(stringComparer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -84,20 +102,22 @@ namespace PascalABCCompiler.Parsers
|
|||
return GetIdToken();
|
||||
}
|
||||
|
||||
public void CreateNewKeyword(string name, Enum token, KeywordKind kind = KeywordKind.None, bool isTypeKeyword = false)
|
||||
public void CreateNewKeyword(string name, Enum token = null, KeywordKind kind = KeywordKind.None, bool isTypeKeyword = false)
|
||||
{
|
||||
name = ConvertKeyword(name);
|
||||
|
||||
if (kind != KeywordKind.None)
|
||||
KeywordKinds[name] = kind;
|
||||
|
||||
Keywords.Add(name);
|
||||
KeywordsToTokens[name] = (int)(object)token;
|
||||
KeywordsForIntellisenseList.Add(name);
|
||||
KeywordsForIntellisenseSet.Add(name);
|
||||
|
||||
// token null может передаваться, если это ключевое слово исключительно для Intellisense (например, break)
|
||||
if (token != null)
|
||||
KeywordsToTokens[name] = (int)(object)token;
|
||||
|
||||
if (isTypeKeyword)
|
||||
TypeKeywords.Add(name);
|
||||
|
||||
// return new Keyword(name, token, kind, isTypeKeyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,11 @@ namespace Languages.Pascal.Frontend.Core
|
|||
CreateNewKeyword("index", Tokens.tkIndex);
|
||||
CreateNewKeyword("async", Tokens.tkAsync);
|
||||
CreateNewKeyword("await", Tokens.tkAwait);
|
||||
|
||||
// В парсере это не ключевые слова
|
||||
CreateNewKeyword("break");
|
||||
CreateNewKeyword("exit");
|
||||
CreateNewKeyword("continue");
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,13 +82,6 @@ namespace Languages.Pascal.Frontend.Data
|
|||
#endregion
|
||||
}
|
||||
|
||||
public override bool IsKeyword(string value)
|
||||
{
|
||||
// typeof и sizeof воспринимаются Intellisense по другому EVA
|
||||
return !value.Equals("typeof", StringComparison.CurrentCultureIgnoreCase) && !value.Equals("sizeof", StringComparison.CurrentCultureIgnoreCase)
|
||||
&& KeywordsStorage.KeywordsToTokens.ContainsKey(value);
|
||||
}
|
||||
|
||||
public override string BodyStartBracket
|
||||
{
|
||||
get
|
||||
|
|
@ -109,7 +102,7 @@ namespace Languages.Pascal.Frontend.Data
|
|||
{
|
||||
get
|
||||
{
|
||||
return KeywordsStorage.Keywords;
|
||||
return KeywordsStorage.KeywordsForIntellisenseList;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue