public static StringBuilder AccessModifiers(Parser psr) { var status = psr.SaveStatus(); try { var sb = new StringBuilder(); switch (psr.GetNextTextOrEmpty()) { case @"protected": sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); if (psr.GetNextTextOrEmpty() == @"internal") { sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); } break; case @"public": case @"private": case @"internal": sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); break; } return sb; } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }
public static StringBuilder AsIs(Parser psr) { var status = psr.SaveStatus(); var sb = new StringBuilder(); try { switch (psr.GetNextTextOrEmpty()) { case @"as": case @"is": sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Type(psr)); return sb; } } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }
private static StringBuilder Query(Parser psr) { var status = psr.SaveStatus(); try { var sb = new StringBuilder(); var doExit = false; var n = 0; while (!doExit) { switch (psr.GetNextTextOrEmpty()) { case @"let": if (0 < n) { sb.Append(psr.SpaceToken()); } sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); if (psr.GetNextTypeOrUnknown() == TokenType.Identifier && psr.GetNextTextOrEmpty(1) == @"=") { sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); } break; case @"where": if (0 < n) { sb.Append(psr.SpaceToken()); } sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); break; case @"orderby": if (0 < n) { sb.Append(psr.SpaceToken()); } sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); while (true) { sb.Append(Expr(psr)); switch (psr.GetNextTextOrEmpty()) { case @"desceding": case @"ascending": sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); break; } if (psr.GetNextTextOrEmpty() == @",") { sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); } else { break; } } break; case @"select": if (0 < n) { sb.Append(psr.SpaceToken()); } sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); if (psr.GetNextTextOrEmpty() == @"into") { sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); } break; case @"join": if (0 < n) { sb.Append(psr.SpaceToken()); } sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); if (psr.GetNextTextOrEmpty() == @"in") { sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); if (psr.GetNextTextOrEmpty() == @"on") { sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); if (psr.GetNextTextOrEmpty() == @"equals") { sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); if (psr.GetNextTextOrEmpty() == @"into") { sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); } } } } break; case @"group": if (0 < n) { sb.Append(psr.SpaceToken()); } sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); if (psr.GetNextTextOrEmpty() == @"by") { sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); if (psr.GetNextTextOrEmpty() == @"into") { sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); } } break; case @"from": if (0 < n) { sb.Append(psr.SpaceToken()); } sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); if (psr.GetNextTextOrEmpty() == @"in") { sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); } break; default: doExit = true; break; } n++; } return sb; } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }
private static StringBuilder Parentheses_Tuple(Parser psr) { var status = psr.SaveStatus(); try { var sb = new StringBuilder(); if (psr.GetNextTypeOrUnknown() == TokenType.ParenthesesOpen) { sb.Append(psr.Consume()); if (psr.GetNextTextOrEmpty(1) != @"," && psr.GetNextTypeOrUnknown(1) != TokenType.ParenthesesClose) { sb.Append(Type(psr)); sb.Append(psr.SpaceToken()); } if (psr.GetNextTypeOrUnknown() == TokenType.Identifier) { sb.Append(psr.Consume()); while (psr.GetNextTextOrEmpty() == @",") { sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); if (psr.GetNextTextOrEmpty(1) != @"," && psr.GetNextTypeOrUnknown(1) != TokenType.ParenthesesClose) { sb.Append(Type(psr)); sb.Append(psr.SpaceToken()); } if (psr.GetNextTypeOrUnknown() == TokenType.Identifier) { sb.Append(psr.Consume()); } } if (psr.GetNextTypeOrUnknown() == TokenType.ParenthesesClose) { sb.Append(psr.Consume()); return sb; } } } } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }
public static StringBuilder Attribute(Parser psr) { var sb = new StringBuilder(); var status = psr.SaveStatus(); try { if (psr.GetNextTextOrEmpty() == @"[") { sb.Append(psr.Consume()); if (psr.GetNextTextOrEmpty(1) == @":") { switch (psr.GetNextTextOrEmpty()) { case @"assembly": case @"module": case @"type": case @"field": case @"method": case @"event": case @"property": case @"param": case @"return": sb.Append(psr.Consume()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); break; } } while (psr.GetNextTextOrEmpty() != @"]") { sb.Append(Expr(psr)); if (psr.GetNextTextOrEmpty() == @",") { sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); } else if (psr.GetNextTextOrEmpty() != @"]") { throw new ResetException(); } } if (psr.GetNextTextOrEmpty() == @"]") { sb.Append(psr.Consume()); return sb; } } } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }
private static StringBuilder New(Parser psr) { var status = psr.SaveStatus(); try { var sb = new StringBuilder(); if (psr.GetNextTextOrEmpty() == @"new") { sb.Append(psr.Consume()); if (psr.GetNextTextOrEmpty() == @"[") { sb.Append(SquareBrackets(psr)); sb.Append(CurlyBrackets_Exprs(psr)); } else { try { var t = Type(psr); sb.Append(psr.SpaceToken()); sb.Append(t); } catch (ResetException) { } if (psr.GetNextTypeOrUnknown() == TokenType.ParenthesesOpen) { sb.Append(FuncArgs(psr)); } if (psr.GetNextTypeOrUnknown() == TokenType.CurlyBracketOpen) { sb.Append(CurlyBrackets_Exprs(psr)); } } return sb; } } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }
private static StringBuilder FuncArgs(Parser psr) { var status = psr.SaveStatus(); try { var sb = new StringBuilder(); while (psr.GetNextTypeOrUnknown() == TokenType.ParenthesesOpen) { sb.Append(psr.Consume()); while (psr.GetNextTypeOrUnknown() != TokenType.ParenthesesClose) { sb.Append(RefOutIn(psr)); sb.Append(Expr(psr)); if (psr.GetNextTextOrEmpty() == @"=") { sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(ParserUtils.Expr(psr)); } if (psr.GetNextTextOrEmpty() == @",") { sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); } } if (psr.GetNextTypeOrUnknown() == TokenType.ParenthesesClose) { sb.Append(psr.Consume()); return sb; } } } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }
private static StringBuilder CurlyBrackets_Exprs(Parser psr) { var status = psr.SaveStatus(); try { var sb = new StringBuilder(); while (psr.GetNextTypeOrUnknown() == TokenType.CurlyBracketOpen) { sb.Append(psr.Consume()); if (psr.GetNextTypeOrUnknown() == TokenType.CurlyBracketClose) { sb.Append(psr.Consume()); return sb; } else { sb.Append(psr.LineBreakToken()); psr.IndentDown(); while (psr.GetNextTypeOrUnknown() != TokenType.CurlyBracketClose) { sb.Append(psr.IndentToken(@"ParserUtils.CurlyBrackets_Exprs")); sb.Append(Expr(psr)); if (psr.GetNextTextOrEmpty() == @"=") { sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); } if (psr.GetNextTextOrEmpty() == @",") { sb.Append(psr.Consume()); } sb.Append(psr.LineBreakToken()); } if (psr.GetNextTypeOrUnknown() == TokenType.CurlyBracketClose) { psr.IndentUp(); sb.Append(psr.IndentToken(@"ParserUtils.CurlyBrackets_Exprs")); sb.Append(psr.Consume()); return sb; } } } } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }
private static StringBuilder Cast(Parser psr) { var status = psr.SaveStatus(); try { var sb = new StringBuilder(); if (psr.GetNextTypeOrUnknown() == TokenType.ParenthesesOpen) { sb.Append(psr.Consume()); sb.Append(Type(psr)); if (psr.GetNextTypeOrUnknown() == TokenType.ParenthesesClose) { sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); return sb; } } } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }
public static StringBuilder _Expr(Parser psr) { var status = psr.SaveStatus(); try { var sb = new StringBuilder(); sb.Append(psr.SpaceToken()); switch (psr.GetNextTextOrEmpty()) { case @"!": switch (psr.GetNextTextOrEmpty(1)) { case @"=": sb.Append(psr.Consume()); sb.Append(psr.Consume()); break; } break; case @"=": switch (psr.GetNextTextOrEmpty(1)) { case @"=": case @">": sb.Append(psr.Consume()); sb.Append(psr.Consume()); break; } break; case @"-": sb.Append(psr.Consume()); if (psr.GetNextTextOrEmpty() == @">") { sb.Append(psr.Consume()); } break; case @"+": case @"*": case @"/": case @"%": sb.Append(psr.Consume()); break; case @"|": sb.Append(psr.Consume()); if (psr.GetNextTextOrEmpty() == @"|") { sb.Append(psr.Consume()); } break; case @"&": sb.Append(psr.Consume()); if (psr.GetNextTextOrEmpty() == @"&") { sb.Append(psr.Consume()); } break; case @"<": sb.Append(psr.Consume()); switch (psr.GetNextTextOrEmpty()) { case @"<": case @"=": sb.Append(psr.Consume()); break; } break; case @">": sb.Append(psr.Consume()); switch (psr.GetNextTextOrEmpty()) { case @">": case @"=": sb.Append(psr.Consume()); break; } break; case @"?": switch (psr.GetNextTextOrEmpty(1)) { case @"?": case @".": sb.Append(psr.Consume()); sb.Append(psr.Consume()); break; } break; default: throw new ResetException(); } sb.Append(psr.SpaceToken()); sb.Append(Term(psr)); return sb; } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }
public static StringBuilder Type(Parser psr) { var status = psr.SaveStatus(); try { var sb = new StringBuilder(); if (psr.GetNextTypeOrUnknown() == TokenType.Identifier) { sb.Append(psr.Consume()); while (true) { if (psr.GetNextTextOrEmpty() == @".") { sb.Append(psr.Consume()); } else { break; } if (psr.GetNextTypeOrUnknown() == TokenType.Identifier) { sb.Append(psr.Consume()); } else { throw new ResetException(); } } } else { throw new ResetException(); } if (psr.GetNextTextOrEmpty() == @"<") { sb.Append(psr.Consume()); if (psr.GetNextTextOrEmpty() != @">") { sb.Append(Type(psr)); while (psr.GetNextTextOrEmpty() == @",") { var status2 = psr.SaveStatus(); try { var sb2 = new StringBuilder(); sb2.Append(psr.Consume()); sb2.Append(psr.SpaceToken()); sb2.Append(Type(psr)); sb.Append(sb2); } catch (ResetException) { psr.LoadStatus(status2); break; } } } if (psr.GetNextTextOrEmpty() == @">") { sb.Append(psr.Consume()); } else { throw new ResetException(); } } if (psr.GetNextTextOrEmpty() == @"[" && psr.GetNextTextOrEmpty(1) == @"]") { sb.Append(psr.Consume()); sb.Append(psr.Consume()); } if (psr.GetNextTextOrEmpty() == @"?") { sb.Append(psr.Consume()); } return sb; } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }
public static StringBuilder RefOutIn(Parser psr) { var status = psr.SaveStatus(); try { var sb = new StringBuilder(); switch (psr.GetNextTextOrEmpty()) { case @"ref": case @"out": case @"in": sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); break; } return sb; } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }
public static StringBuilder ConditionalOprator(Parser psr) { var status = psr.SaveStatus(); var sb = new StringBuilder(); try { if (psr.GetNextTextOrEmpty() == @"?") { sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); if (psr.GetNextTextOrEmpty() == @":") { sb.Append(psr.SpaceToken()); sb.Append(psr.Consume()); sb.Append(psr.SpaceToken()); sb.Append(Expr(psr)); return sb; } } } catch (ResetException) { } psr.LoadStatus(status); throw new ResetException(); }