protected static SymbolSet GetSetValues(string values) { SymbolSet set = new SymbolSet(); string[] valuess = values.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string s in valuess) { set.Add(new Symbol(GetSymbolValue(s.Trim()))); } return(set); }
private static void AddRange(SymbolSet foundTypes, SymbolSet currentTypes, Func <INamedTypeSymbol, bool> shouldContinueSearching) { // Directly enumerate to avoid IEnumerator allocations. foreach (var type in foundTypes) { if (shouldContinueSearching(type)) { currentTypes.Add(type); } } }
public IEnumerable <Option> BuildOptions() { var optionSet = new SymbolSet(); foreach (var parameter in GetParameters().OmitInfrastructureTypes()) { optionSet.Add(parameter.BuildOption()); } return(optionSet.Cast <Option>()); }
public IEnumerable <Option> BuildOptions() { var optionSet = new SymbolSet(); foreach (var parameter in _constructorBinder.BuildOptions()) { optionSet.Add(parameter); } foreach (var property in GetSettableProperties() .OmitInfrastructureTypes()) { var option = property.BuildOption(); if (!optionSet.Contains(option.Name)) { optionSet.Add(option); } } return(optionSet.Cast <Option>()); }
public void CodeSymbolSet(ref SymbolSet set) { int count = CodeCount(ref set, n => new SymbolSet(n)); if (count < 1) { return; } while (count-- > 0) { set.Add(m_reader.ReadSymbol()); } }
private static async Task AddMatchingMetadataTypesInMetadataReferenceAsync( SymbolSet metadataTypes, Project project, Func <INamedTypeSymbol, SymbolSet, bool> typeMatches, Compilation compilation, PortableExecutableReference reference, SymbolSet result, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); // We store an index in SymbolTreeInfo of the *simple* metadata type name // to the names of the all the types that either immediately derive or // implement that type. Because the mapping is from the simple name // we might get false positives. But that's fine as we still use // 'tpeMatches' to make sure the match is correct. var symbolTreeInfo = await SymbolTreeInfo.GetInfoForMetadataReferenceAsync( project.Solution, reference, loadOnly : false, cancellationToken : cancellationToken).ConfigureAwait(false); // For each type we care about, see if we can find any derived types // in this index. foreach (var metadataType in metadataTypes) { cancellationToken.ThrowIfCancellationRequested(); var baseTypeName = metadataType.Name; // For each derived type we find, see if we can map that back // to an actual symbol. Then check if that symbol actually fits // our criteria. foreach (var derivedType in symbolTreeInfo.GetDerivedMetadataTypes(baseTypeName, compilation, cancellationToken)) { if (derivedType != null && derivedType.Locations.Any(s_isInMetadata) && typeMatches(derivedType, metadataTypes)) { result.Add(derivedType); } } } }
protected static void ParseMPGE(Grammar.Grammar grammar, string line) { string backup = line; LiteralGrammarElement SymbolKeyword = new LiteralGrammarElement("MultiGrammarElement "); if (SymbolKeyword.Validate(ref line, true).Result) { line = line.Trim(); string templine = line; SymbolSet AlphabetWithSpace = SymbolSet.FromType(SymbolSetPredefinedType.AlphaNumeric); AlphabetWithSpace.Add(new Symbol('_')); AlphabetWithSpace.Add(new Symbol('$')); AlphabetWithSpace.Add(new Symbol('/')); VariableLengthGrammarElement SymbolName = new VariableLengthGrammarElement(VariableLengthGrammarElementType.Plus, AlphabetWithSpace); if (SymbolName.Validate(ref line, true).Result) { string name = templine.Substring(0, templine.IndexOf(line)).Trim(); line = line.Trim(); LiteralGrammarElement EqualsSign = new LiteralGrammarElement("="); if (EqualsSign.Validate(ref line, true).Result) { line = line.Trim(); MultiParsePrecedenceType precedence = MultiParsePrecedenceType.Normal; if (line.LastIndexOf(',') >= 0) { string precedenceString = line.Substring(line.IndexOf(',') + 1).Trim(); line = line.Substring(0, line.IndexOf(',')).Trim(); LiteralGrammarElement precKey = new LiteralGrammarElement("precedence"); LiteralGrammarElement colon = new LiteralGrammarElement(":"); if (precKey.Validate(ref precedenceString, true).Result) { precedenceString = precedenceString.Trim(); if (colon.Validate(ref precedenceString, true).Result) { string[] precedenceList = Enum.GetNames(typeof(MultiParsePrecedenceType)); LiteralGrammarElement type = new LiteralGrammarElement(precedenceList); precedenceString = precedenceString.Trim(); if (type.Validate(ref precedenceString, false).Result) { precedence = (MultiParsePrecedenceType)Enum.Parse(typeof(MultiParsePrecedenceType), precedenceString); } else { throw new InfinityGrammarScriptParseError("Error", backup); } } else { throw new InfinityGrammarScriptParseError("Precedence is always followed by a Colon \":\"", backup); } } else { throw new InfinityGrammarScriptParseError("Invalid syntax. Only 'precedence' keyword allowed here", backup); } } string[] terminals = line.Split(new string[] { " or ", " | " }, StringSplitOptions.RemoveEmptyEntries); MultiParseGrammarElement mpge = new MultiParseGrammarElement(); mpge.Precedence = precedence; int count = 0; foreach (string ss in terminals) { try { GrammarElement cge = ParseCGE(grammar, ss); if (cge.Name == null || cge.Name == "") { cge.Name = name + ":" + count++; } mpge.AddTerminal(cge); } catch (KeyNotFoundException) { _temp.Add(backup); throw new InfinityGrammarScriptParseError("No such terminal to add to.", backup); } } grammar.AddTerminal(name, mpge); } else { throw new InfinityGrammarScriptParseError("MultiGrammarElement requires assignment after the name, missing '=' sign", backup); } } else { throw new InfinityGrammarScriptParseError("Check name", backup); } } else { throw new InfinityGrammarScriptParseError("Undetected error", backup); } }
protected static void ParseGrammarElement(ref Grammar.Grammar grammar, string line) { string backup = line; LiteralGrammarElement SymbolKeyword = new LiteralGrammarElement("GrammarElement "); if (SymbolKeyword.Validate(ref line, true).Result) { line = line.Trim(); string templine = line; SymbolSet AlphabetWithSpace = SymbolSet.FromType(SymbolSetPredefinedType.AlphaNumeric); AlphabetWithSpace.Add(new Symbol('_')); AlphabetWithSpace.Add(new Symbol('$')); AlphabetWithSpace.Add(new Symbol('/')); VariableLengthGrammarElement SymbolName = new VariableLengthGrammarElement(VariableLengthGrammarElementType.Plus, AlphabetWithSpace); if (SymbolName.Validate(ref line, true).Result) { string name = templine.Substring(0, templine.IndexOf(line)).Trim(); line = line.Trim(); LiteralGrammarElement EqualsSign = new LiteralGrammarElement("="); if (EqualsSign.Validate(ref line, true).Result) { line = line.Trim(); if (line.Contains(" or ") || line.Contains(" | ") || (line.Contains("precedence") && (line.Contains("Ascending") || line.Contains("Descending")))) { MultiParsePrecedenceType precedence = MultiParsePrecedenceType.Normal; if (line.IndexOf(',') >= 0) { string precedenceString = line.Substring(line.IndexOf(',') + 1).Trim(); line = line.Substring(0, line.IndexOf(',')).Trim(); LiteralGrammarElement precKey = new LiteralGrammarElement("precedence"); LiteralGrammarElement colon = new LiteralGrammarElement(":"); if (precKey.Validate(ref precedenceString, true).Result) { precedenceString = precedenceString.Trim(); if (colon.Validate(ref precedenceString, true).Result) { string[] precedenceList = Enum.GetNames(typeof(MultiParsePrecedenceType)); LiteralGrammarElement type = new LiteralGrammarElement(precedenceList); precedenceString = precedenceString.Trim(); if (type.Validate(ref precedenceString, false).Result) { precedence = (MultiParsePrecedenceType)Enum.Parse(typeof(MultiParsePrecedenceType), precedenceString); } } } } string[] terminals = line.Split(new string[] { " or ", " | " }, StringSplitOptions.RemoveEmptyEntries); MultiParseGrammarElement mpge = new MultiParseGrammarElement(); mpge.Precedence = precedence; int count = 0; foreach (string ss in terminals) { try { GrammarElement cge = ParseCGE(grammar, ss); if (cge.Name == null || cge.Name == "") { cge.Name = name + ":" + count++; } mpge.AddTerminal(cge); } catch (KeyNotFoundException k) { _temp.Add(backup); throw new InfinityGrammarScriptParseError("No such terminal to add to. " + k.Message, backup); } } grammar.AddTerminal(name, mpge); } else { string delimiters = " \n\r\t"; int idx = line.LastIndexOf(','); if (line.Substring(idx + 1).Trim().StartsWith("delimiters")) { delimiters = line.Substring(idx + 1).Trim(); line = line.Substring(0, idx); LiteralGrammarElement lge = new LiteralGrammarElement("delimiters"); if (lge.Validate(ref delimiters, true).Result) { delimiters = delimiters.Trim(); if (delimiters.StartsWith("[") && delimiters.EndsWith("]")) { delimiters = delimiters.Substring(1, delimiters.Length - 2); if (delimiters.Length == 0) { delimiters = "@None"; } } } else { throw new InfinityGrammarScriptParseError("Delimiters not declared properly - " + delimiters, backup); } } try { GrammarElement cge = ParseCGE(grammar, line, delimiters); grammar.AddTerminal(name, cge); } catch (KeyNotFoundException) { _temp.Add(backup); throw new InfinityGrammarScriptParseError("No such terminal to add to.", backup); } } } } } }
protected static void ParseSymbolSet(ref Grammar.Grammar grammar, string line) { string backup = line; LiteralGrammarElement SymbolKeyword = new LiteralGrammarElement("SymbolSet ") { Name = "SymbolSetKeyword" }; if (SymbolKeyword.Validate(ref line, true).Result) { line = line.Trim(); string exception = ""; if (line.Contains("except")) { int idxx = line.IndexOf("except"); exception = line.Substring(idxx + 7).Trim(); line = line.Substring(0, idxx); } string templine = line; SymbolSet Identifier = SymbolSet.FromType(SymbolSetPredefinedType.AlphaNumeric); Identifier.Add(new Symbol('_')); Identifier.Add(new Symbol('$')); VariableLengthGrammarElement SymbolName = new VariableLengthGrammarElement(VariableLengthGrammarElementType.Plus, Identifier) { Name = "Identifier" }; if (SymbolName.Validate(ref line, true).Result) { string name = templine.Substring(0, templine.IndexOf(line)).Trim(); line = line.Trim(); LiteralGrammarElement EqualsSign = new LiteralGrammarElement("=") { Name = "EqualsSign" }; if (EqualsSign.Validate(ref line, true).Result) { line = line.Trim(); #region Symbol Set %[...] if (line.StartsWith("%")) { line = line.Substring(1); line = line.Trim(); if (line.StartsWith("[") && line.EndsWith("]")) { line = line.Substring(1, line.Length - 2); SymbolSet set = new SymbolSet(); foreach (char c in line) { set.Add(new Symbol(c)); } foreach (char c in exception) { set.RemoveSymbol(new Symbol(c)); } grammar.AddSymbolSet(name, set); LiteralGrammarElement none = new LiteralGrammarElement(); none.AddElement(set); VariableLengthGrammarElement star = new VariableLengthGrammarElement(VariableLengthGrammarElementType.Star, set); VariableLengthGrammarElement plus = new VariableLengthGrammarElement(VariableLengthGrammarElementType.Plus, set); grammar.AddTerminal(name, none); grammar.AddTerminal(name + "*", star); grammar.AddTerminal(name + "+", plus); } } #endregion #region Symbol Set [...] else if (line.StartsWith("[") && line.EndsWith("]")) { line = line.Substring(1, line.Length - 2); SymbolSet set = GetSetValues(line); foreach (char c in exception) { set.RemoveSymbol(new Symbol(c)); } grammar.AddSymbolSet(name, set); LiteralGrammarElement none = new LiteralGrammarElement(); none.AddElement(set); VariableLengthGrammarElement star = new VariableLengthGrammarElement(VariableLengthGrammarElementType.Star, set); VariableLengthGrammarElement plus = new VariableLengthGrammarElement(VariableLengthGrammarElementType.Plus, set); grammar.AddTerminal(name, none); grammar.AddTerminal(name + "*", star); grammar.AddTerminal(name + "+", plus); } #endregion #region Symbol Set with Predefined/Predeclared Sets else { string[] types = Enum.GetNames(typeof(SymbolSetPredefinedType)); LiteralGrammarElement NewKeyword = new LiteralGrammarElement("new"); LiteralGrammarElement SetTypes = new LiteralGrammarElement(types); CompoundGrammarElement PreDefinedSet = new CompoundGrammarElement(NewKeyword, SetTypes) { Delimiters = " \n\r" }; string[] values = line.Split(','); SymbolSet set = new SymbolSet(); foreach (string valueq in values) { string value = valueq.Trim(); string iv = value; string iv2 = value; if (PreDefinedSet.Validate(ref iv2, true).Result) { NewKeyword.Validate(ref value, true); SymbolSetPredefinedType type = (SymbolSetPredefinedType)Enum.Parse(typeof(SymbolSetPredefinedType), value); SymbolSet temp = SymbolSet.FromType(type); foreach (Symbol s in temp) { set.Add(s); } } else if (SymbolName.Validate(ref iv, true).Result) { if (grammar.Symbols.Keys.Contains(value)) { set.Add(grammar.Symbols[value]); } else if (grammar.SymbolSets.Keys.Contains(value)) { foreach (Symbol sym in grammar.SymbolSets[value]) { set.Add(sym); } } else { throw new InfinityGrammarScriptParseError("Symbol not declared or found - " + value, backup); } } else { throw new InfinityGrammarScriptParseError("Invalid parameters passed - " + value, backup); } } foreach (char c in exception) { set.RemoveSymbol(new Symbol(c)); } grammar.SymbolSets.Add(name, set); LiteralGrammarElement none = new LiteralGrammarElement(); none.AddElement(set); VariableLengthGrammarElement star = new VariableLengthGrammarElement(VariableLengthGrammarElementType.Star, set); VariableLengthGrammarElement plus = new VariableLengthGrammarElement(VariableLengthGrammarElementType.Plus, set); grammar.AddTerminal(name, none); grammar.AddTerminal(name + "*", star); grammar.AddTerminal(name + "+", plus); } #endregion } else { throw new InfinityGrammarScriptParseError("Syntax requires a symbol value assignment, which is missing.", backup); } } else { throw new InfinityGrammarScriptParseError("The Symbol name specified was not valid. Names given can have Letters, Numbers and $ and _.", backup); } } else { throw new InfinityGrammarScriptParseError("Not a SymbolSet definition.", backup); } }
protected static void ParseSymbolRange(ref Grammar.Grammar grammar, string line) { string backup = line; LiteralGrammarElement SymbolRangeKeyword = new LiteralGrammarElement("SymbolRange "); if (SymbolRangeKeyword.Validate(ref line, true).Result) { line = line.Trim(); string templine = line; SymbolSet AlphabetWithSpace = SymbolSet.FromType(SymbolSetPredefinedType.AlphaNumeric); AlphabetWithSpace.Add(new Symbol('_')); AlphabetWithSpace.Add(new Symbol('$')); VariableLengthGrammarElement SymbolName = new VariableLengthGrammarElement(VariableLengthGrammarElementType.Plus, AlphabetWithSpace); if (SymbolName.Validate(ref line, true).Result) { string name = templine.Substring(0, templine.IndexOf(line)).Trim(); line = line.Trim(); LiteralGrammarElement EqualsSign = new LiteralGrammarElement("="); if (EqualsSign.Validate(ref line, true).Result) { line = line.Trim(); string templine2 = line; LiteralGrammarElement FromKeyword = new LiteralGrammarElement("From "); LiteralGrammarElement FromStrKeyword = new LiteralGrammarElement("FromStr "); if (FromKeyword.Validate(ref line, true).Result) { line = line.Trim(); string from = line.Substring(0, line.IndexOf("To") - 1).Trim(); string to = line.Substring(line.IndexOf("To") + 2, line.Length - line.IndexOf("To") - 2).Trim(); from = GetSymbolValue(from); to = GetSymbolValue(to); Console.WriteLine(from + " to " + to); SymbolRange sr = new SymbolRange(from, to); grammar.AddSymbol(name, sr); } else if (FromStrKeyword.Validate(ref line, true).Result) { line = line.Trim(); string from = line.Substring(0, line.IndexOf("To") - 1).Trim(); string to = line.Substring(line.IndexOf("To") + 2, line.Length - line.IndexOf("To") - 2).Trim(); from = GetSymbolValue(from); to = GetSymbolValue(to); Console.WriteLine(from + " to " + to); SymbolRange sr = new SymbolRange(from, to); grammar.AddSymbol(name, sr); } else { throw new InfinityGrammarScriptParseError("From ranges specified by wrong keyword or syntax error.", backup); } } else { throw new InfinityGrammarScriptParseError("Syntax requires a symbol value assignment, which is missing.", backup); } } else { throw new InfinityGrammarScriptParseError("The Symbol name specified was not valid. Names given can have Letters, Numbers and $ and _.", backup); } } else { throw new InfinityGrammarScriptParseError("Not a valid SymbolRange definition.", backup); } }