public void SetGetMulti() { GrammarObjectSet<Symbol> set = new GrammarObjectSet<Symbol>(); Symbol symbolX = grammar.GetSymbol(0); Symbol symbolY = grammar.GetSymbol(1); set[symbolX] = true; set[symbolY] = true; Assert.Equal(true, set[symbolX]); Assert.Equal(true, set[symbolY]); set[symbolX] = false; Assert.Equal(false, set[symbolX]); Assert.Equal(true, set[symbolY]); }
public void MultiSetGet() { GrammarObjectSet<Symbol> set = new GrammarObjectSet<Symbol>(); Symbol symbol = grammar.GetSymbol(0); set[symbol] = false; Assert.Equal(false, set[symbol]); set[symbol] = true; Assert.Equal(true, set[symbol]); set[symbol] = true; Assert.Equal(true, set[symbol]); set[symbol] = false; Assert.Equal(false, set[symbol]); }
public override Type GetSymbolOutputType(Symbol symbol) { if (symbol == null) { throw new ArgumentNullException("symbol"); } if (symbol.Owner != Grammar) { throw new ArgumentException("The given symbol belongs to another grammar", "symbol"); } Queue <Symbol> pending = new Queue <Symbol>(); pending.Enqueue(symbol); GrammarObjectSet <Symbol> visited = new GrammarObjectSet <Symbol>(); Type bestMatch = null; while (pending.Count > 0) { symbol = pending.Dequeue(); if (visited.Set(symbol)) { foreach (SemanticTokenFactory <T> factory in GetTokenFactoriesForSymbol(symbol)) { Symbol redirectForOutputType = factory.RedirectForOutputType; if (redirectForOutputType == null) { symbolTypeMap.ApplyCommonBaseType(ref bestMatch, factory.OutputType); } else { pending.Enqueue(redirectForOutputType); } } } } return(bestMatch ?? typeof(T)); }
/// <summary> /// Gets the DFA states which may lead to one of the given (terminal) symbols. /// </summary> /// <param name="filter">The filter predicate, specifying all symbols that shall be requested.</param> public ICollection<DfaState> GetDfaStatesOfSymbols(Predicate<Symbol> filter) { if (filter == null) { throw new ArgumentNullException("filter"); } int symbolsFound = 0; GrammarObjectSet<Symbol> acceptSymbols = new GrammarObjectSet<Symbol>(); for (int i = 0; i < SymbolCount; i++) { Symbol symbol = GetSymbol(i); if (filter(symbol)) { acceptSymbols[symbol] = true; symbolsFound++; } } if (symbolsFound != 0) { Queue<DfaState> stateQueue = new Queue<DfaState>(); for (int i = 0; i < DfaStateCount; i++) { DfaState state = GetDfaState(i); if (acceptSymbols[state.AcceptSymbol]) { stateQueue.Enqueue(state); } } Debug.Assert(stateQueue.Count >= symbolsFound); Dictionary<DfaState, int> allowedStates = new Dictionary<DfaState, int>(); do { DfaState state = stateQueue.Dequeue(); int count; if (!allowedStates.TryGetValue(state, out count)) { foreach (DfaState originState in state.GetOriginStates()) { stateQueue.Enqueue(originState); } } allowedStates[state] = count+1; } while (stateQueue.Count > 0); return allowedStates.Keys; } return new DfaState[0]; }
public void SetNull() { GrammarObjectSet<Symbol> set = new GrammarObjectSet<Symbol>(); Assert.Throws<ArgumentNullException>(() => { set[null] = true; }); }
public void SetGetTrue() { GrammarObjectSet<Symbol> set = new GrammarObjectSet<Symbol>(); Symbol symbol = grammar.GetSymbol(0); set[symbol] = true; Assert.Equal(true, set[symbol]); }
public void GetFalse() { GrammarObjectSet<Symbol> set = new GrammarObjectSet<Symbol>(); Assert.Equal(false, set[grammar.GetSymbol(0)]); }