public override Token Eval(TokenExtractor extractor) { EnsureExtractor(extractor, nameof(extractor)); // TODO: Remover tratamento de cursor do extrator // Isso será garantido pelo anterior? var cursor = extractor.SaveCursor(); try { var c = extractor.NextChar(); if (c == _char) { return(new Token(c) { ContentPosBegin = cursor.Position, ContentLength = extractor.SaveCursor().Position - cursor.Position }); } } catch (Exception) { extractor.RollbackCursor(cursor); throw; } extractor.RollbackCursor(cursor); return(null); }
public override Token Eval(TokenExtractor extractor) { EnsureExtractor(extractor, nameof(extractor)); var cursor = extractor.SaveCursor(); var content = new List <Token>(); try { foreach (var grammarElement in _list) { var token = grammarElement.Eval(extractor); if (token == null) { extractor.RollbackCursor(cursor); return(null); } content.Add(token); } } catch (Exception) { extractor.RollbackCursor(cursor); throw; } return(new Token(content.ToArray()) { ContentPosBegin = cursor.Position, ContentLength = extractor.SaveCursor().Position - cursor.Position }); }
public override Token Eval(TokenExtractor extractor) { EnsureExtractor(extractor, nameof(extractor)); var cursor = extractor.SaveCursor(); var content = new StringBuilder(); try { var token = base.Eval(extractor); if (token == null) { extractor.RollbackCursor(cursor); return(null); } foreach (var childToken in (token.Content as Token[])) { content.Append((char)childToken.Content); } } catch (Exception) { extractor.RollbackCursor(cursor); throw; } return(new Token(content.ToString()) { ContentPosBegin = cursor.Position, ContentLength = extractor.SaveCursor().Position - cursor.Position }); }
public override Token Eval(TokenExtractor extractor) { EnsureExtractor(extractor, nameof(extractor)); var cursor = extractor.SaveCursor(); try { Token token = null; foreach (var grammarElement in _list) { token = grammarElement.Eval(extractor); if (token != null) { break; } } if (token == null) { extractor.RollbackCursor(cursor); return(null); } return(token); } catch (Exception) { extractor.RollbackCursor(cursor); throw; } }
public override Token Eval(TokenExtractor extractor) { EnsureExtractor(extractor, nameof(extractor)); var cursor = extractor.SaveCursor(); var content = new List <Token>(); try { while (true) { var token = _element.Eval(extractor); if (token == null) { break; } content.Add(token); } } catch (Exception) { extractor.RollbackCursor(cursor); throw; } // Se não achou nenhum token to elemento informado é inválido if (content.Count < 1) { return(null); } return(new Token(content.ToArray()) { ContentPosBegin = cursor.Position, ContentLength = extractor.SaveCursor().Position - cursor.Position }); }