public ParseError(ISourceCellRef cellRef, string formula, int charPosition, string condition) { CellRef = cellRef; Formula = formula; Condition = condition; CharPosition = charPosition; }
public LinksLexer(ISourceCellRef cellRef, string formula) { CellRef = cellRef; Formula = formula + " "; ParenDepth = 0; BraceDepth = 0; CharPosition = 0; Tokens = new List <IToken>(); }
private bool ParseOpenExternRef(string path, string cell, string formula, ISourceCellRef source) { var indexKet = path.IndexOf(']', 0); if (indexKet < 0) { return(IsValidSheetName(path)); } return(Add(new ExternalRef(formula, source, new SourceCellRef( "open workbook w/o a path", path.Substring(1, indexKet - 1), // omit "'[' path.Substring(indexKet + 1, path.Length - indexKet - 1), // omit ']' trailing cell )))); }
private bool ParseExternRef(string path, string cell, string formula, ISourceCellRef source) { var indexBra = path.IndexOf('[', 0); if (indexBra < 0) { return(IsValidSheetName(path)); } var indexKet = path.IndexOf(']', indexBra); if (indexKet < 0) { return(false); } return(Add(new ExternalRef(formula, source, new SourceCellRef( path.Substring(1, indexBra - 1), // omit "'" leading path.Substring(indexBra + 1, indexKet - indexBra - 1), // omit "'[' path.Substring(indexKet + 1, path.Length - indexKet - 2), // omit ']' trailing cell )))); }
internal ExternalRef(string formula, ISourceCellRef source, ISourceCellRef target) { Formula = formula; Source = source; Target = target; }
/// <inheritdoc/> public ILinksAnalysis Parse(ISourceCellRef cellRef, string formula) => new FormulaParser(cellRef, formula).Parse();
/// <inheritdoc/> public ILinksLexer NewLinksLexer(ISourceCellRef cellRef, string formula) => new LinksLexer(cellRef, formula);
public ILinksAnalysis ParseFormula(ISourceCellRef sourceCell, string formula) { var lexer = new LinksLexer(sourceCell, formula); for (var token = lexer.Scan(); token.Value != EToken.EOT; token = lexer.Scan()) { switch (token.Value) { case EToken.ScanError: AddParseError(sourceCell, lexer.Formula, lexer.CharPosition, $"Scan error at position {lexer.CharPosition}; found: '{token.Text}'"); break; case EToken.ExternRef: var path = token.Text; if ((token = lexer.Scan()).Value != EToken.Bang) { AddParseError(sourceCell, lexer.Formula, lexer.CharPosition, $"Expected '!' found '{token.Name()}' at position {lexer.CharPosition}"); } else if ((token = lexer.Scan()).Value != EToken.Identifier) { AddParseError(sourceCell, lexer.Formula, lexer.CharPosition, $"Expected Identifier, found '{token.Name()}' at position {lexer.CharPosition}"); } else if (!ParseExternRef(path, token.Text, formula, sourceCell)) { AddParseError(sourceCell, lexer.Formula, lexer.CharPosition, $"Expected a cell reference at position {lexer.CharPosition}; found '{token.Text}'"); } else { break; } break; case EToken.OpenExternRef: path = token.Text; if ((token = lexer.Scan()).Value != EToken.Bang) { AddParseError(sourceCell, lexer.Formula, lexer.CharPosition, $"Expected '!' found '{token.Name()}' at position {lexer.CharPosition}"); } else if ((token = lexer.Scan()).Value != EToken.Identifier) { AddParseError(sourceCell, lexer.Formula, lexer.CharPosition, $"Expected Identifier, found '{token.Name()}' at position {lexer.CharPosition}"); } else if (!ParseOpenExternRef(path, token.Text, formula, sourceCell)) { AddParseError(sourceCell, lexer.Formula, lexer.CharPosition, $"Expected a cell reference at position {lexer.CharPosition}; found '{token.Text}'"); } else { break; } break; default: break; } } return(this); }
private void AddParseError(ISourceCellRef cellRef, string formula, int charPosition, string condition) => _errors.Add(new ParseError(cellRef, formula, charPosition, condition));
/// <summary>Creates a new <see cref="IParser"/> for a single string formula.</summary> public FormulaParser(ISourceCellRef cellRef, string formula) => FuncParse = () => ParseFormula(cellRef, formula);