void expr(out Model.Expression exp) { exp = new Model.Expression(); char?sep = null; Model.Term trm = null; term(out trm); exp.Terms.Add(trm); while (la.kind == 4) { Get(); } while (StartOf(11)) { if (la.kind == 25 || la.kind == 46) { if (la.kind == 46) { Get(); sep = '/'; } else { Get(); sep = ','; } while (la.kind == 4) { Get(); } } term(out trm); if (sep.HasValue) { trm.Seperator = sep.Value; } exp.Terms.Add(trm); sep = null; while (la.kind == 4) { Get(); } } }
void declaration(out Model.Declaration dec) { dec = new Model.Declaration(); Model.Expression exp = null; string ident = ""; if (la.kind == 24) { Get(); dec.Name += "-"; } identity(out ident); dec.Name += ident; while (la.kind == 4) { Get(); } Expect(43); while (la.kind == 4) { Get(); } expr(out exp); dec.Expression = exp; while (la.kind == 4) { Get(); } if (la.kind == 44) { Get(); while (la.kind == 4) { Get(); } Expect(45); dec.Important = true; while (la.kind == 4) { Get(); } } }
static string Render(Model.Expression exp) { StringBuilder txt = new StringBuilder(); bool first = true; foreach (Model.Term t in exp.Terms) { if (first) { first = false; } else { txt.AppendFormat("{0} ", t.Seperator.HasValue ? t.Seperator.Value.ToString() : ""); } txt.AppendFormat("<span class=\"term\">{0}</span>", Render(t)); } return(txt.ToString()); }
void pseudo(out string pseudo) { pseudo = ""; Model.Expression exp = null; string ident = null; Expect(43); if (la.kind == 43) { Get(); } while (la.kind == 4) { Get(); } if (la.kind == 24) { Get(); pseudo += "-"; } identity(out ident); pseudo += ident; if (la.kind == 10) { Get(); pseudo += t.val; while (la.kind == 4) { Get(); } expr(out exp); pseudo += exp.ToString(); while (la.kind == 4) { Get(); } Expect(11); pseudo += t.val; } }
void expr(out Model.Expression exp) { exp = new Model.Expression(); char? sep = null; Model.Term trm = null; term(out trm); exp.Terms.Add(trm); while (la.kind == 4) { Get(); } while (StartOf(11)) { if (la.kind == 25 || la.kind == 46) { if (la.kind == 46) { Get(); sep = '/'; } else { Get(); sep = ','; } while (la.kind == 4) { Get(); } } term(out trm); if (sep.HasValue) { trm.Seperator = sep.Value; } exp.Terms.Add(trm); sep = null; while (la.kind == 4) { Get(); } } }
void directive(out Model.Directive dir) { dir = new Model.Directive(); Model.Declaration dec = null; Model.RuleSet rset = null; Model.Expression exp = null; Model.Directive dr = null; string ident = null; Model.Medium m; Expect(23); dir.Name = "@"; if (la.kind == 24) { Get(); dir.Name += "-"; } identity(out ident); dir.Name += ident; switch (dir.Name.ToLower()) { case "@media": dir.Type = Model.DirectiveType.Media; break; case "@import": dir.Type = Model.DirectiveType.Import; break; case "@charset": dir.Type = Model.DirectiveType.Charset; break; case "@page": dir.Type = Model.DirectiveType.Page; break; case "@font-face": dir.Type = Model.DirectiveType.FontFace; break; case "@namespace": dir.Type = Model.DirectiveType.Namespace; break; default: dir.Type = Model.DirectiveType.Other; break; } while (la.kind == 4) { Get(); } if (StartOf(4)) { if (StartOf(5)) { medium(out m); dir.Mediums.Add(m); while (la.kind == 4) { Get(); } while (la.kind == 25) { Get(); while (la.kind == 4) { Get(); } medium(out m); dir.Mediums.Add(m); while (la.kind == 4) { Get(); } } } else { expr(out exp); dir.Expression = exp; while (la.kind == 4) { Get(); } } } if (la.kind == 26) { Get(); while (la.kind == 4) { Get(); } if (StartOf(6)) { while (StartOf(1)) { if (dir.Type == Model.DirectiveType.Page || dir.Type == Model.DirectiveType.FontFace) { declaration(out dec); dir.Declarations.Add(dec); while (la.kind == 4) { Get(); } while (la.kind == 27) { Get(); while (la.kind == 4) { Get(); } if (la.val.Equals("}")) { Get(); return; } declaration(out dec); dir.Declarations.Add(dec); while (la.kind == 4) { Get(); } } if (la.kind == 27) { Get(); while (la.kind == 4) { Get(); } } } else if (StartOf(2)) { ruleset(out rset); dir.RuleSets.Add(rset); while (la.kind == 4) { Get(); } } else { directive(out dr); dir.Directives.Add(dr); while (la.kind == 4) { Get(); } } } } Expect(28); while (la.kind == 4) { Get(); } } else if (la.kind == 27) { Get(); while (la.kind == 4) { Get(); } } else { SynErr(50); } }
void term(out Model.Term trm) { trm = new Model.Term(); string val = ""; Model.Expression exp = null; string ident = null; if (la.kind == 7 || la.kind == 8) { QuotedString(out val); trm.Value = val; trm.Type = Model.TermType.String; } else if (la.kind == 9) { URI(out val); trm.Value = val; trm.Type = Model.TermType.Url; } else if (la.kind == 47) { Get(); identity(out ident); trm.Value = "U\\" + ident; trm.Type = Model.TermType.Unicode; } else if (la.kind == 33) { HexValue(out val); trm.Value = val; trm.Type = Model.TermType.Hex; } else if (StartOf(15)) { bool minus = false; if (la.kind == 24) { Get(); minus = true; } if (StartOf(16)) { identity(out ident); trm.Value = ident; trm.Type = Model.TermType.String; if (minus) { trm.Value = "-" + trm.Value; } while (la.kind == 4) { Get(); } if (StartOf(17)) { while (la.kind == 34 || la.kind == 36 || la.kind == 43) { if (la.kind == 43) { Get(); trm.Value += t.val; if (StartOf(18)) { if (la.kind == 43) { Get(); trm.Value += t.val; } if (la.kind == 24) { Get(); trm.Value += t.val; } identity(out ident); trm.Value += ident; } else if (la.kind == 33) { HexValue(out val); trm.Value += val; } else if (StartOf(19)) { while (la.kind == 3) { Get(); trm.Value += t.val; } if (la.kind == 34) { Get(); trm.Value += "."; while (la.kind == 3) { Get(); trm.Value += t.val; } } } else { SynErr(57); } } else if (la.kind == 34) { Get(); trm.Value += t.val; if (la.kind == 24) { Get(); trm.Value += t.val; } identity(out ident); trm.Value += ident; } else { Get(); trm.Value += t.val; while (la.kind == 4) { Get(); } if (la.kind == 24) { Get(); trm.Value += t.val; } if (StartOf(16)) { identity(out ident); trm.Value += ident; } else if (StartOf(19)) { while (la.kind == 3) { Get(); trm.Value += t.val; } } else { SynErr(58); } } } } if (la.kind == 10) { Get(); while (la.kind == 4) { Get(); } expr(out exp); Model.Function func = new Model.Function(); func.Name = trm.Value; func.Expression = exp; trm.Value = null; trm.Function = func; trm.Type = Model.TermType.Function; while (la.kind == 4) { Get(); } Expect(11); } } else if (StartOf(15)) { if (la.kind == 29) { Get(); trm.Sign = '+'; } if (minus) { trm.Sign = '-'; } while (la.kind == 3) { Get(); val += t.val; } if (la.kind == 34) { Get(); val += t.val; while (la.kind == 3) { Get(); val += t.val; } } if (StartOf(20)) { if (la.val.ToLower().Equals("n")) { Expect(22); val += t.val; if (la.kind == 24 || la.kind == 29) { if (la.kind == 29) { Get(); val += t.val; } else { Get(); val += t.val; } Expect(3); val += t.val; while (la.kind == 3) { Get(); val += t.val; } } } else if (la.kind == 48) { Get(); trm.Unit = Model.Unit.Percent; } else { if (IsUnit()) { identity(out ident); try { trm.Unit = (Model.Unit)Enum.Parse(typeof(Model.Unit), ident, true); } catch { errors.SemErr(t.line, t.col, string.Format("Unrecognized unit '{0}'", ident)); } } } } trm.Value = val; trm.Type = Model.TermType.Number; } else { SynErr(59); } } else { SynErr(60); } }