Token NextToken() { while (ch == ' ' || ch == 10 || ch == 13 ) NextCh(); if (ch == '/' && Comment0()) return NextToken(); int recKind = noSym; int recEnd = pos; t = new Token(); t.pos = pos; t.col = col; t.line = line; t.charPos = charPos; int state; if (start.ContainsKey(ch)) { state = (int) start[ch]; } else { state = 0; } tlen = 0; AddCh(); switch (state) { case -1: { t.kind = eofSym; break; } // NextCh already done case 0: { if (recKind != noSym) { tlen = recEnd - t.pos; SetScannerBehindT(); } t.kind = recKind; break; } // NextCh already done case 1: recEnd = pos; recKind = 1; if (ch == '-' || ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;} else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 2: {t.kind = 2; break;} case 3: {t.kind = 3; break;} case 4: {t.kind = 4; break;} case 5: if (ch == '!') {AddCh(); goto case 6;} else {goto case 0;} case 6: if (ch == '-') {AddCh(); goto case 7;} else {goto case 0;} case 7: if (ch == '-') {AddCh(); goto case 8;} else {goto case 0;} case 8: {t.kind = 5; break;} case 9: if (ch == '>') {AddCh(); goto case 10;} else {goto case 0;} case 10: {t.kind = 6; break;} case 11: {t.kind = 7; break;} case 12: {t.kind = 8; break;} case 13: {t.kind = 10; break;} case 14: {t.kind = 11; break;} case 15: {t.kind = 23; break;} case 16: {t.kind = 25; break;} case 17: {t.kind = 26; break;} case 18: {t.kind = 27; break;} case 19: {t.kind = 28; break;} case 20: {t.kind = 29; break;} case 21: {t.kind = 30; break;} case 22: {t.kind = 34; break;} case 23: {t.kind = 35; break;} case 24: {t.kind = 36; break;} case 25: {t.kind = 37; break;} case 26: {t.kind = 38; break;} case 27: {t.kind = 39; break;} case 28: if (ch == '=') {AddCh(); goto case 29;} else {goto case 0;} case 29: {t.kind = 40; break;} case 30: if (ch == '=') {AddCh(); goto case 31;} else {goto case 0;} case 31: {t.kind = 41; break;} case 32: {t.kind = 42; break;} case 33: {t.kind = 43; break;} case 34: {t.kind = 44; break;} case 35: {t.kind = 45; break;} case 36: {t.kind = 47; break;} case 37: {t.kind = 48; break;} case 38: {t.kind = 49; break;} case 39: recEnd = pos; recKind = 24; if (ch == '-') {AddCh(); goto case 9;} else {t.kind = 24; break;} case 40: recEnd = pos; recKind = 31; if (ch == '=') {AddCh(); goto case 26;} else {t.kind = 31; break;} case 41: recEnd = pos; recKind = 32; if (ch == '=') {AddCh(); goto case 32;} else {t.kind = 32; break;} case 42: recEnd = pos; recKind = 33; if (ch == '=') {AddCh(); goto case 27;} else {t.kind = 33; break;} case 43: recEnd = pos; recKind = 1; if (ch == '-' || ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;} else if (ch == 92) {AddCh(); goto case 37;} else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} } t.val = new String(tval, 0, tlen); return t; }
// get the next token (possibly a token already seen during peeking) internal Token Scan() { if (tokens.next == null) { return NextToken(); } else { pt = tokens = tokens.next; return tokens; } }
void Init() { pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2)); } buffer = new UTF8Buffer(buffer); col = 0; charPos = -1; NextCh(); } pt = tokens = new Token(); // first token is a dummy }
// peek for the next token, ignore pragmas internal Token Peek() { do { if (pt.next == null) { pt.next = NextToken(); } pt = pt.next; } while (pt.kind > maxT); // skip pragmas return pt; }
// make sure that peeking starts at the current scan position internal void ResetPeek() { pt = tokens; }
private Rule SkipDeclarations(Token token) { RaiseErrorOccurred(ParseError.InvalidToken, token.Position); MoveToRuleEnd(ref token); return default(Rule); }
private List<IConditionFunction> MultipleConditions(IConditionFunction condition, string connector,ref Token token) { var list = new List<IConditionFunction>(); ParseComments(ref token); list.Add(condition); while (token.Type != TokenType.EndOfFile) { condition = ExtractCondition(ref token); if (condition == null) { break; } list.Add(condition); if (!token.Data.Isi(connector)) { break; } token = NextToken(); ParseComments(ref token); } return list; }
public Property CreateDeclaration(ref Token token) { ParseComments(ref token); return CreateDeclarationWith(PropertyFactory.Instance.Create, ref token); }
public Medium CreateMedium(ref Token token) { var medium = new Medium(); ParseComments(ref token); if (token.Type == TokenType.Ident) { var identifier = token.Data; if (identifier.Isi(Keywords.Not)) { medium.IsInverse = true; token = NextToken(); ParseComments(ref token); } else if (identifier.Isi(Keywords.Only)) { medium.IsExclusive = true; token = NextToken(); ParseComments(ref token); } } if (token.Type == TokenType.Ident) { medium.Type = token.Data; token = NextToken(); ParseComments(ref token); if ((token.Type != TokenType.Ident) || !token.Data.Isi(Keywords.And)) { return medium; } token = NextToken(); ParseComments(ref token); } do { if (token.Type != TokenType.RoundBracketOpen) { return null; } token = NextToken(); ParseComments(ref token); var feature = CreateFeature(ref token); if (feature != null) { medium.AppendChild(feature); } if (token.Type != TokenType.RoundBracketClose) { return null; } token = NextToken(); ParseComments(ref token); if (feature == null) { return null; } if ((token.Type != TokenType.Ident) || !token.Data.Isi(Keywords.And)) { break; } token = NextToken(); ParseComments(ref token); } while (token.Type != TokenType.EndOfFile); return medium; }
public Property CreateDeclarationWith(Func<string, Property> createProperty, ref Token token) { var property = default(Property); var sb = Pool.NewStringBuilder(); var start = token.Position; while (token.IsDeclarationName()) { sb.Append(token.ToValue()); token = NextToken(); } var propertyName = sb.ToPool(); if (propertyName.Length > 0) { property = _parser.Options.IncludeUnknownDeclarations || _parser.Options.AllowInvalidValues ? new UnknownProperty(propertyName) : createProperty(propertyName); if (property == null) { RaiseErrorOccurred(ParseError.UnknownDeclarationName, start); } else { _nodes.Push(property); } ParseComments(ref token); if (token.Type == TokenType.Colon) { bool important; var value = CreateValue(TokenType.CurlyBracketClose, ref token, out important); if (value == null) { RaiseErrorOccurred(ParseError.ValueMissing, token.Position); } else if ((property != null) && property.TrySetValue(value)) { property.IsImportant = important; } ParseComments(ref token); } else { RaiseErrorOccurred(ParseError.ColonMissing, token.Position); } JumpToDeclEnd(ref token); if (property != null) { _nodes.Pop(); } } else if (token.Type != TokenType.EndOfFile) { RaiseErrorOccurred(ParseError.IdentExpected, start); JumpToDeclEnd(ref token); } if (token.Type == TokenType.Semicolon) { token = NextToken(); } return property; }
public IConditionFunction CreateCondition(ref Token token) { ParseComments(ref token); return AggregateCondition(ref token); }
public TokenValue CreateValue(ref Token token) { bool important; return CreateValue(TokenType.CurlyBracketClose, ref token, out important); }
void Get() { for (;;) { t = la; la = scanner.Scan(); if (la.kind <= maxT) { ++errDist; break; } la = t; } }
internal void Parse() { la = new Token(); la.val = ""; Get(); Css3(); Expect(0); }