public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode) { base.Init(context, treeNode); if (treeNode.ChildNodes.Count == 1) { Value = new IntegerAstNode() { Value = 1 }; PeriodicType = PeriodicTypeAst.Day; } else { Value = AddChild("value", treeNode.FirstChild) as ExpressionAstNode; string periodType = treeNode.ChildNodes[1].FindTokenAndGetText().ToLower(); switch (periodType) { case "month": case "months": PeriodicType = PeriodicTypeAst.Month; break; case "days": case "day": PeriodicType = PeriodicTypeAst.Day; break; default: throw new ArgumentException("Unregconized period type:" + periodType); } } }
/// <summary> /// Convert periodic type in ast node to the type in model /// </summary> /// <param name="periodicTypeAst"></param> /// <returns></returns> private PeriodicType PeriodicTypeConvert(PeriodicTypeAst periodicTypeAst) { switch (periodicTypeAst) { case PeriodicTypeAst.Day: return PeriodicType.Day; case PeriodicTypeAst.Week: return PeriodicType.Week; case PeriodicTypeAst.Month: return PeriodicType.Month; default: throw new ArgumentException("Unexpected periodic type from AST node: " + periodicTypeAst.ToString()); } }