protected virtual string createSqlQueryForGeneralSPDetails( string cusip, DateTime tradeDate, DateTime finalValuationDate, DateTime maturityDate, double notional, double initialLevel, double parAmount, EIssuer issuer, EStructure structure) { string tradeDateText = tradeDate.ToDatabaseText(); string valuationDateText = finalValuationDate.ToDatabaseText(); string maturityDateText = maturityDate.ToDatabaseText(); string issuerText = issuer.ToStringShortCode(); string structureDescription = structure.ToDescription(); string insertPortion = "INSERT INTO " + SPDatabaseUtils.TableNameGeneralDetails + " " + "(Cusip, Trade_Date, Final_Valuation_Date, Maturity_Date, Notional, Initial_Level, " + "Par_Amount, Issuer, Structure)"; string valuesPortion = string.Format(@"VALUES ('{0}', #{1}#, #{2}#, #{3}#, {4}, {5}, {6}, '{7}', '{8}')", cusip, tradeDateText, valuationDateText, maturityDateText, notional, initialLevel, parAmount, issuerText, structureDescription); return(insertPortion + " " + valuesPortion); }
public override bool Translate(string text, out Continuation result, EStructure st = EStructure.Program) { if (!base.Translate(text, out result, st)) { return(false); } if (string.IsNullOrEmpty(text)) { return(true); } _Lexer = new RhoLexer(text); _Lexer.Process(); if (_Lexer.Failed) { return(Fail(_Lexer.Error)); } _Parser = new RhoParser(_Lexer, _reg, st); _Parser.Process(); if (_Parser.Failed) { return(Fail(_Parser.Error)); } if (!Generate(_Parser.Result)) { return(false); } result = Result; return(!Failed); }
private bool Run(EStructure st) { _Stack.Push(_AstFactory.New(EPiAst.Continuation)); while (!Failed && NextSingle(Top())) { ; } return(!Failed); }
public bool Process(PiLexer lex, EStructure structure = EStructure.None) { _Current = 0; _Lexer = lex; if (_Lexer.Failed) { return(Fail(_Lexer.Error)); } RemoveWhitespace(); return(Run(structure)); }
protected Continuation RhoTranslate(string rhoScript, bool trace = false, EStructure st = EStructure.Program) { var trans = new RhoTranslator(_Registry); if (!trans.Translate(rhoScript, out var cont, st)) { WriteLine($"Error: {trans.Error}"); } if (trace) { WriteLine(trans.ToString()); } Assert.IsFalse(trans.Failed, trans.Error); return(_Continuation = cont); }
private bool Parse(EStructure st) { if (st != EStructure.Expression) { _Stack.Push(NewNode(ERhoAst.Program)); } var result = false; switch (st) { case EStructure.Program: result = Program(); break; case EStructure.Statement: result = Statement(); break; case EStructure.Expression: result = Expression(); break; } if (Failed || !result) { return(false); } ConsumeNewLines(); if (!Try(ERhoToken.Nop)) { return(FailLocation("Unexpected extra stuff found")); } return(_Stack.Count == 1 || InternalFail("Semantic stack not empty after parsing")); }
public override bool Translate( string input, out Continuation result, EStructure st = EStructure.Program) { if (!base.Translate(input, out result, st)) { return(false); } _continuation = Continuation.New(_reg); if (string.IsNullOrEmpty(input)) { return(true); } _Lexer = new PiLexer(input); if (!_Lexer.Process()) { return(Fail($"LexerError: {_Lexer.Error}")); } _Parser = new PiParser(_Lexer); if (!Parser.Process(_Lexer, EStructure.Program)) { return(Fail($"ParserError: {Parser.Error}")); } if (!TranslateNode(Parser.Root, _continuation.Code)) { return(false); } result = _continuation; return(result != null); }
protected void RhoRun(string text, bool trace = false, EStructure st = EStructure.Program) { _Exec.Clear(); _Exec.Continue(_Continuation = RhoTranslate(text, trace, st)); }
public virtual bool Translate(string text, out Continuation cont, EStructure st = EStructure.Program) { Reset(); cont = null; return(!string.IsNullOrEmpty(text) || Fail("Empty input")); }
public RhoParser(RhoLexer lexer, IRegistry reg, EStructure st) : base(lexer, reg) { _Current = 0; _structure = st; }
public static string String(this EStructure e) { return(e.ToString()); }
/// <summary> /// Central method using several methods in order to add the deal represented by the term /// sheet text it is given to the database. /// </summary> /// <param name="termSheetText"></param> public void AddToDatabase(string termSheetText) { _termSheetText = termSheetText; try { EStructure structureType = getStructureType(); string [] sqlQueries = getSqlQueriesToAddDealToDatabase(structureType); executeSqlQueriesToAddDealToDatabase(sqlQueries); } catch (System.Data.OleDb.OleDbException e) { string errorMsg = "Unhandled OleDbException exception encountered while trying to " + "update the database.\n" + e; Debug.WriteLine(errorMsg); throw; } catch (ArgumentOutOfRangeException e) { string errorMsg = "ArgumentOutOfRangeException encountered in CentralCommand. Aborting CentralCommand.\n" + e.ToString(); Debug.WriteLine(errorMsg); } catch (DealFactoryException e) { string errorMsg = "Unhandled DealFactoryException exception encountered in CentralCommand.\n" + e.ToString(); Debug.WriteLine(errorMsg); throw; } catch (DetailParsingException e) { string errorMsg = "Unhandled DetailParsingException exception encountered in CentralCommand.\n" + e.ToString(); Debug.WriteLine(errorMsg); throw; } catch (DatabaseOperationException e) { string errorMsg = "DatabaseOperationException encountered in CentralCommand.\n" + e.ToString(); Debug.WriteLine(errorMsg); throw; } catch (SqlQueryCreationException e) { string errorMsg = "Unhandled SqlQueryFactoryException exception encountered in CentralCommand.\n" + e.ToString(); Debug.WriteLine(errorMsg); throw; } catch (DealRipperFactoryException e) { string errorMsg = "Unhandled DealRipperFactoryException exception encountered in CentralCommand.\n" + e.ToString(); Debug.WriteLine(errorMsg); throw; } catch (System.IO.FileNotFoundException e) { string errorMsg = "File we wanted to parse wasn't found.\n" + e.ToString(); Debug.WriteLine(errorMsg); throw; } catch (Exception e) { string errorMsg = "UNKNOWN exception encountered in CentralCommand.\n" + e.ToString(); Debug.WriteLine(errorMsg); throw; } }
/// <summary> /// Define the sql queries that will update our database for a given structure by /// (1) Instantiating both the appropriate Factory and DealRipper that can be used to fill a container /// that will be passed to the SqlQueryFactory class. /// (2) Calling the GetSqlQueriesForAddingDealToDatabase() method of SqlQueryFactory in order to get the sql /// queries. /// </summary> private string [] getSqlQueriesToAddDealToDatabase(EStructure structureType) { ISqlQueryGenerator sqlQueryGenerator; switch (structureType) { case EStructure.PrincipalProtectedNote: PrincipalProtectedNoteRipper ppnRipper = DealRipperFactory.GetPrincipalProtectedNoteRipper(_termSheetText); PrincipalProtectedNoteFactory ppnFactory = new PrincipalProtectedNoteFactory(); PrincipalProtectedNoteContainer ppnContainer = ppnFactory.GetDealContainer(ppnRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(ppnContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.StandardPLUS: PLUSRipper plusRipper = DealRipperFactory.GetPLUSRipper(_termSheetText); PLUSFactory plusFactory = new PLUSFactory(); PLUSContainer plusContainer = plusFactory.GetDealContainer(plusRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(plusContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.BufferedPLUS: BufferedPLUSRipper bufferedPLUSRipper = DealRipperFactory.GetBufferedPLUSRipper(_termSheetText); BufferedPLUSFactory bufferedPLUSFactory = new BufferedPLUSFactory(); BufferedPLUSContainer bufferedPLUSContainer = bufferedPLUSFactory.GetDealContainer(bufferedPLUSRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(bufferedPLUSContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.TriggerPLUS: TriggerPLUSRipper triggerPLUSRipper = DealRipperFactory.GetTriggerPLUSRipper(_termSheetText); TriggerPLUSFactory triggerPLUSFactory = new TriggerPLUSFactory(); TriggerPLUSContainer triggerPLUSContainer = triggerPLUSFactory.GetDealContainer(triggerPLUSRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(triggerPLUSContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.DualDirectionalTriggerPLUS: TriggerPLUSRipper dualDirectionalTriggerPLUSRipper = DealRipperFactory.GetTriggerPLUSRipper(_termSheetText); DualDirectionalTriggerPLUSFactory dualDirectionalTriggerPLUSFactory = new DualDirectionalTriggerPLUSFactory(); TriggerPLUSContainer dualDirectionalTriggerPLUSContainer = dualDirectionalTriggerPLUSFactory.GetDealContainer(dualDirectionalTriggerPLUSRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(dualDirectionalTriggerPLUSContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.StandardJump: JumpRipper jumpRipper = DealRipperFactory.GetStandardJumpRipper(_termSheetText); JumpFactory jumpFactory = new JumpFactory(); JumpContainer jumpContainer = jumpFactory.GetDealContainer(jumpRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(jumpContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.BufferedJump: BufferedJumpRipper bufferedJumpRipper = DealRipperFactory.GetBufferedJumpRipper(_termSheetText); BufferedJumpFactory bufferedJumpFactory = new BufferedJumpFactory(); BufferedJumpContainer bufferedJumpContainer = bufferedJumpFactory.GetDealContainer(bufferedJumpRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(bufferedJumpContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.TriggerJump: TriggerJumpRipper triggerJumpRipper = DealRipperFactory.GetTriggerJumpRipper(_termSheetText); TriggerJumpFactory triggerJumpFactory = new TriggerJumpFactory(); TriggerJumpContainer triggerJumpContainer = triggerJumpFactory.GetDealContainer(triggerJumpRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(triggerJumpContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.EnhancedTriggerJump: TriggerJumpRipper enhancedTriggerJumpRipper = DealRipperFactory.GetTriggerJumpRipper(_termSheetText); EnhancedTriggerJumpFactory enhancedTriggerJumpFactory = new EnhancedTriggerJumpFactory(); EnhancedTriggerJumpContainer enhancedTriggerJumpContainer = enhancedTriggerJumpFactory.GetDealContainer(enhancedTriggerJumpRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(enhancedTriggerJumpContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.DualDirectionalTriggerJump: TriggerJumpRipper dualDirectionalTriggerJumpRipper = DealRipperFactory.GetTriggerJumpRipper(_termSheetText); DualDirectionalTriggerJumpFactory dualDirectionalTriggerJumpFactory = new DualDirectionalTriggerJumpFactory(); TriggerJumpContainer dualDirectionalTriggerJumpContainer = dualDirectionalTriggerJumpFactory.GetDealContainer(dualDirectionalTriggerJumpRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(dualDirectionalTriggerJumpContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.AutocallableStandard: AutocallableRipper autocallableRipper = DealRipperFactory.GetAutocallableRipper(_termSheetText); AutocallableFactory autocallableFactory = new AutocallableFactory(); AutocallableContainer autocallableContainer = autocallableFactory.GetDealContainer(autocallableRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(autocallableContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.AutocallableFixedCoupon: FixedCouponAutocallableRipper fixedCouponAutocallableRipper = DealRipperFactory.GetFixedCouponAutocallableRipper(_termSheetText); AutocallableFactory fixedCouponAutocallableFactory = new AutocallableFactory(); AutocallableContainer fixedCouponAutocallableContainer = fixedCouponAutocallableFactory.GetDealContainer(fixedCouponAutocallableRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(fixedCouponAutocallableContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.AutocallableStepUp: AutocallableRipper stepUpAutocallableRipper = DealRipperFactory.GetAutocallableRipper(_termSheetText); StepUpAutocallableFactory stepUpAutocallableFactory = new StepUpAutocallableFactory(); StepUpAutocallableContainer stepUpAutocallableContainer = stepUpAutocallableFactory.GetDealContainer(stepUpAutocallableRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(stepUpAutocallableContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.AutocallableStepDown: AutocallableRipper stepDownAutocallableRipper = DealRipperFactory.GetAutocallableRipper(_termSheetText); StepDownAutocallableFactory stepDownAutocallableFactory = new StepDownAutocallableFactory(); StepDownAutocallableContainer stepDownAutocallableContainer = stepDownAutocallableFactory.GetDealContainer(stepDownAutocallableRipper); sqlQueryGenerator = SqlQueryGeneratorFactory.GetSqlQueryGenerator(stepDownAutocallableContainer); return(sqlQueryGenerator.GetSqlQueriesForAddingDealToDatabase()); case EStructure.AutocallableWorstOf: string wOfErrorMsg = "defineSqlQueriesToAddDealToDatabase() method of CentralCommand unable to handle Worst-of Autocallables."; Debug.WriteLine(wOfErrorMsg); throw new ArgumentOutOfRangeException(wOfErrorMsg); default: throw new ArgumentOutOfRangeException("Unhandled structure type passed to defineSqlQueriesToAddDealToDatabase() method of CentralCommand."); } }
private void AssertEqual(string rho, object val, EStructure str = EStructure.Expression) { RhoRun(rho, false, str); Assert.AreEqual(val, Pop()); }