public Token Parse(Token openingToken) { if (!openingToken.IsNumericToken()) { throw new RangeMemberMustBeNumericException(openingToken, _tokenizer.Path); } int dotCount = 1; bool inclusive = true; int from = int.Parse(openingToken.Text); int to = int.MinValue; bool done = false; foreach(Token token in _tokenizer) { switch (token.Type) { case TokenType.DotSeparator: if(dotCount == 3) { throw new UnexpectedTokenException(token, _tokenizer.Path); } dotCount++; if(dotCount == 3) { inclusive = false; } break; case TokenType.Token: if (!token.IsNumericToken()) { throw new RangeMemberMustBeNumericException(token, _tokenizer.Path); } to = int.Parse(token.Text); done = true; break; default: throw new UnexpectedTokenException(token, _tokenizer.Path); } if(done) { break; } } return new RangeToken(openingToken.StartIndex, from, inclusive ? to : to - 1); }
internal RangeMemberMustBeNumericException(Token token, string path) : base(token, path, ErrorTexts.RangeMemberMustBeNumericException) { }
internal IllegalEscapeException(Token token, string path) :base(token, path, ErrorTexts.IllegalEscapeException) { }
internal FalcorParseException(Token token, string path, string message) : this(string.Format(ErrorTexts.FalcorParseTokenException, message, path, token.StartIndex, token.Text)) { }
internal IndexerSeperationRequiresCommaException(Token token, string path) :base(token, path, ErrorTexts.IndexerSeperationRequiresCommaException) { }
internal EmptyQuoteException(Token token, string path) :base(token, path, ErrorTexts.EmptyQuoteException) { }
internal InvalidIdentifierException(Token token, string path) :base(token, path, ErrorTexts.InvalidIdentifierException) { }
internal UnexpectedTokenException(Token token, string path) :base(token, path, string.Format(ErrorTexts.UnexpectedTokenException, token.Type)) { }
public IEnumerable<Token> Parse(Token indexStartToken) { int allowedMaxIndexer = 1; List<Token> indexer = new List<Token>(); bool routedIndexer = false; bool done = false; foreach(Token token in _tokenizer) { if((token.Type == TokenType.Quote || token.Type == TokenType.Token) && indexer.Count == allowedMaxIndexer) { throw new IndexerSeperationRequiresCommaException(token, _tokenizer.Path); } switch(token.Type) { case TokenType.OpeningBrace: throw new NotSupportedException("Routed paths are currently not supported"); //routedIndexer = true; //indexer.Add(RoutedParser.Parse()); //break; case TokenType.Token: if(!token.IsNumericToken()) { throw new NonNumericIndexerNeedsQuotesException(token, _tokenizer.Path); } indexer.Add(token); break; case TokenType.DotSeparator: if (!indexer.Any()) { throw new UnexpectedTokenException(token, _tokenizer.Path); } Token rangeStart = indexer.Last(); indexer.Remove(rangeStart); indexer.Add(RangeParser.Parse(rangeStart)); break; case TokenType.Space: break; case TokenType.ClosingBracket: done = true; break; case TokenType.Quote: indexer.Add(QuoteParser.Parse(token)); break; case TokenType.CommaSeparator: allowedMaxIndexer++; break; default: throw new UnexpectedTokenException(token, _tokenizer.Path); } if(done) { break; } } if(!indexer.Any()) { throw new EmptyIndexerExeption(indexStartToken, _tokenizer.Path); } if(indexer.Count > 1 && routedIndexer) { throw new MultipleRoutedIndexTokensException(indexer[1], _tokenizer.Path); } return indexer; }
public Token Parse(Token openingToken) { bool escaping = false; bool done = false; StringBuilder innerToken = new StringBuilder(); foreach(Token token in _tokenizer) { switch(token.Type) { case TokenType.Token: case TokenType.Space: case TokenType.DotSeparator: case TokenType.CommaSeparator: case TokenType.OpeningBracket: case TokenType.ClosingBracket: case TokenType.OpeningBrace: case TokenType.ClosingBrace: if (escaping) { throw new IllegalEscapeException(token, _tokenizer.Path); } innerToken.Append(token.Text); break; case TokenType.Quote: if(escaping) { innerToken.Append(token.Text); escaping = false; } else if(token.Text != openingToken.Text) { innerToken.Append(token.Text); } else { done = true; } break; case TokenType.Escape: escaping = true; break; default: throw new UnexpectedTokenException(token, _tokenizer.Path); } if (done) { break; } } if(innerToken.Length == 0) { throw new EmptyQuoteException(openingToken, _tokenizer.Path); } return new Token(innerToken.ToString(), TokenType.Token, openingToken.StartIndex); }
internal MultipleRoutedIndexTokensException(Token token, string path) :base(token, path, ErrorTexts.MultipleRoutedIndexTokensException) { }
internal EmptyIndexerExeption(Token indexToken, string path) : base(indexToken, path, ErrorTexts.EmptyIndexerExeption) { }