public Token Execute(Token rootToken, string code) { this.pos = 0; this.checkpoints = new Stack<ParserCheckpoint>(); this.code = code; FindLines(); if (rootToken.Match(this) && pos == code.Length) { if (rootToken is Node) { return ((Node)rootToken).Interpret(); } else { return rootToken; } } else { int p, line, col; GetLineCol(out p, out line, out col); var ex = new ParserException(String.Format(ExceptionMessages.NotUnderstandableToken, line + 1, col + 1)); ex.Pos = p; ex.Line = line; ex.Col = col; throw ex; } }
private void CopyMembers(Token old) { this.pos = old.pos; this.line = old.line; this.col = old.col; this.value = old.value; this.parent = old.parent; }
protected Exception CreateException(string message, Token token) { string msg; msg = String.Format(message, null, token.Line + 1, token.Pos + 1); ValidatorException ex = new ValidatorException(msg); ex.Token = token; return ex; }
protected internal virtual bool WriteNode(Token node) { var res = node.AcceptCodeGenerator(this); if (res && node is Node) { WriteChildren((Node)node); } return res; }
/// <summary> /// Writes a node by visiting its children. /// </summary> /// <param name="token"></param> /// <returns></returns> /// <remarks> /// Depending on the behavior of derived classes, this function /// might or might not traverse the parsing tree further. /// </remarks> protected virtual void WriteNode(Token token) { if (token is Node) { // Traverse tree WriteChildren((Node)token); } else { // Write terminal WriteToken(token); } }
public static CommentOrWhitespace Create(Token t) { var ncw = new CommentOrWhitespace(); if (t is Whitespace || t is SingleLineComment || t is MultiLineComment) { ncw.Stack.AddLast(t); } else { throw new NotImplementedException(); } return ncw; }
TreeNode GenerateToken(Token t) { TreeNode ni = new TreeNode(t.GetType().Name + " " + t.Value); ni.ForeColor = Color.Gray; return ni; }
void GenerateCodeToken(ref string code, Token t) { code += t.Value + " "; }
/// <summary> /// Writes the value of a token to the stream. /// </summary> /// <param name="token"></param> /// <remarks> /// This function is called only for terminals /// </remarks> protected void WriteToken(Token token) { writer.Write(token.Value); }
private void InitializeMembers() { this.token = null; }
public NameResolverException(string message, Token token) : base(message) { this.token = token; }
protected internal virtual bool WriteToken(Token t) { writer.Write(t.Value); return true; }
public Token(Token old) { CopyMembers(old); }
/// <summary> /// /// </summary> /// <param name="token"></param> /// <returns></returns> /// <remarks> /// Do dispatching here based on node type /// </remarks> protected override void WriteNode(Token token) { if (token is TableAlias) { WriteTableAlias((TableAlias)token); } else if (token is TableOrViewName) { WriteTableOrViewName((TableOrViewName)token); } else if (token is ColumnIdentifier) { WriteColumnIdentifier((ColumnIdentifier)token); } else if (token is ColumnExpression) { WriteColumnExpression((ColumnExpression)token); } else if (token is FunctionIdentifier) { WriteFunctionIdentifier((FunctionIdentifier)token); } else { base.WriteNode(token); } }
public ValidatorException(string message, Token token) : base(message) { this.token = token; }