private void acceptTerminal (CssToken t) { tokens.Push (t); Console.WriteLine("State: {0} with Token: {1} ({2})", state.Peek ().ToString (), t.GetValue (), t.GetTokenType ().ToString ()); }
public void NewCssToken (CssToken t) { switch((CssParserStates)state.Peek ()) { case CssParserStates.STYLESHEET: switch(t.GetTokenType ()) { case CssTokenType.CDO: //state.push (CssParserStates.CDO); break; case CssTokenType.CDC: //state.push (CssParserStates.CDC); break; case CssTokenType.ATKEYWORD: addParentNode (CssParserStates.ATRULE); state.Push (CssParserStates.ATRULE); state.Push (CssParserStates.ATKEYWORD); acceptTerminal(t); break; default: state.Push (CssParserStates.RULESET); break; } break; case CssParserStates.BLOCK: // In blocks we have ruleset CssTokenType tp = t.GetTokenType (); if (tp == CssTokenType.IDENT || tp == CssTokenType.HASH) { addParentNode (CssParserStates.RULESET); state.Push (CssParserStates.RULESET); state.Push (CssParserStates.SELECTOR); acceptTerminal (t); } break; case CssParserStates.SELECTOR: // We can have multiple selectors CssTokenType tp = t.GetTokenType (); if (tp == CssTokenType.IDENT || tp == CssTokenType.HASH) { addParentNode (CssParserStates.RULESET); state.Push (CssParserStates.RULESET); state.Push (CssParserStates.SELECTOR); acceptTerminal (t); } break; case CssParserStates.ATKEYWORD: switch(t.GetTokenType ()) { case CssTokenType.STRING: state.Push (CssParserStates.ATRULESTRING); acceptTerminal (t); break; case CssTokenType.LEFTCURLY: state.Push (CssParserStates.BLOCK); acceptTerminal (t); break; default: state.Push (CssParserStates.ERROR); break; } break; case CssParserStates.ATRULESTRING: switch(t.GetTokenType ()) { case CssTokenType.SEMICOLON: state.Push (CssParserStates.ATRULEEND); acceptTerminal (t); acceptState (CssParserStates.ATRULE); break; default: state.Push (CssParserStates.ERROR); break; } break; } if (t == null) Console.WriteLine("Something went wrong, got null"); else Console.WriteLine("Parser: Token: {0} Type: {1}", t.GetValue(), t.GetTokenType().ToString()); }