public PegAstNode Add(Parser p, Object label) { PegAstNode ret = new PegAstNode(p.GetPos(), msText, this, label); mChildren.Add(ret); return(ret); }
public Parser(string s) { mIndex = 0; mData = s; mTree = new PegAstNode(0, mData, null, null); mCur = mTree; }
public PegAstNode CreateNode(Object label) { Trace.Assert(mCur != null); mCur = mCur.Add(this, label); Trace.Assert(mCur != null); return(mCur); }
public void CompleteNode() { Trace.Assert(mCur != null); mCur.Complete(this); mCur = mCur.GetParent(); Trace.Assert(mCur != null); }
public PegAstNode(int n, String text, PegAstNode p, Object label) { msText = text; mnBegin = n; mnCount = -1; mpParent = p; mLabel = label; }
public AstProgram(Peg.PegAstNode node) : base(node) { foreach (Peg.PegAstNode child in node.GetChildren()) { CatAstNode statement = CatAstNode.Create(child); mStatements.Add(statement); } }
public void AbandonNode() { Trace.Assert(mCur != null); PegAstNode tmp = mCur; mCur = mCur.GetParent(); Trace.Assert(mCur != null); mCur.Remove(tmp); }
public AstMetaDataBlock(PegAstNode node) : base(node) { CheckLabel(AstLabel.MetaDataBlock); }
public AstMetaDataLabel(PegAstNode node) : base(node) { CheckLabel(AstLabel.MetaDataLabel); CheckIsLeaf(node); Trace.Assert(children.Count == 0); }
public AstHex(PegAstNode node) : base(node) { CheckLabel(AstLabel.Hex); CheckIsLeaf(node); value = int.Parse(ToString(), NumberStyles.AllowHexSpecifier); }
public AstType(PegAstNode node) : base(node) { }
public PegAstNode Add(Parser p, Object label) { PegAstNode ret = new PegAstNode(p.GetPos(), msText, this, label); mChildren.Add(ret); return ret; }
public AstStackVar(PegAstNode node) : base(node) { CheckLabel(AstLabel.StackVar); CheckChildCount(node, 0); }
public AstStack(PegAstNode node) : base(node) { CheckLabel(AstLabel.Stack); foreach (PegAstNode child in node.GetChildren()) { CatAstNode tmp = Create(child); if (!(tmp is AstType)) throw new Exception("stack AST node should only have type AST nodes as children"); mTypes.Add(tmp as AstType); } }
public AstMacroPattern(PegAstNode node) : base(node) { CheckLabel(AstLabel.MacroPattern); foreach (PegAstNode child in node.GetChildren()) { AstMacroTerm tmp = CatAstNode.Create(child) as AstMacroTerm; if (tmp == null) throw new Exception("invalid grammar: only macro terms can be children of an ast macro mPattern"); mPattern.Add(tmp); } }
public AstMacroTerm(PegAstNode node) : base(node) { }
public AstMacroProperty(PegAstNode node) : base(node) { }
public AstMacro(PegAstNode node) : base(node) { CheckChildCount(node, 2); CheckLabel(AstLabel.MacroRule); mSrc = new AstMacroPattern(node.GetChild(0)); mDest = new AstMacroPattern(node.GetChild(1)); }
public AstFxnType(PegAstNode node) : base(node) { CheckLabel(AstLabel.FxnType); CheckChildCount(node, 3); mCons = new AstStack(node.GetChild(0)); mbSideEffects = node.GetChild(1).ToString().Equals("~>"); mProd = new AstStack(node.GetChild(2)); }
public CatAstNode(PegAstNode node) { if (node.GetLabel() != null) mLabel = (AstLabel)node.GetLabel(); else mLabel = AstLabel.AstRoot; msText = node.ToString(); }
public AstString(PegAstNode node) : base(node) { CheckLabel(AstLabel.String); CheckIsLeaf(node); // strip quotes string s = ToString(); value = s.Substring(1, s.Length - 2); }
public AstFloat(PegAstNode node) : base(node) { CheckLabel(AstLabel.Float); CheckIsLeaf(node); value = double.Parse(ToString()); }
public void Remove(PegAstNode x) { mChildren.Remove(x); }
public AstSimpleType(PegAstNode node) : base(node) { CheckLabel(AstLabel.TypeName); CheckChildCount(node, 0); }
public AstMacroQuote(PegAstNode node) : base(node) { CheckLabel(AstLabel.MacroQuote); foreach (PegAstNode child in node.GetChildren()) { AstMacroTerm term = Create(child) as AstMacroTerm; if (term == null) throw new Exception("internal grammar error: macro quotations can only contain macro terms"); mTerms.Add(term); } }
public AstChar(PegAstNode node) : base(node) { CheckLabel(AstLabel.Char); CheckIsLeaf(node); string s = ToString(); s = s.Substring(1, s.Length - 2); switch (s) { case "\\t": value = '\t'; break; case "\\n": value = '\n'; break; case "\\'": value = '\''; break; case "\\\"": value = '\"'; break; case "\\r": value = '\r'; break; default: value = char.Parse(s); break; } }
public AstMacroTypeVar(PegAstNode node) : base(node) { CheckChildCount(node, 1); msName = node.GetChild(0).ToString(); CheckLabel(AstLabel.MacroTypeVar); }
public AstMacroStackVar(PegAstNode node) : base(node) { if (node.GetNumChildren() < 1) throw new Exception("invalid macro stack variable"); if (node.GetNumChildren() > 2) throw new Exception("invalid macro stack variable"); msName = node.GetChild(0).ToString(); if (node.GetNumChildren() == 2) { AstFxnType typeNode = new AstFxnType(node.GetChild(1)); mType = CatFxnType.Create(typeNode) as CatFxnType; if (mType == null) throw new Exception("expected function type " + typeNode.ToString()); } CheckLabel(AstLabel.MacroStackVar); }
public AstMacroName(PegAstNode node) : base(node) { CheckChildCount(node, 0); CheckLabel(AstLabel.MacroName); }
public AstMetaData(PegAstNode node) : base(node) { foreach (PegAstNode child in node.GetChildren()) { AstMetaData x = Create(child) as AstMetaData; if (x == null) throw new Exception("Meta data-nodes can only have meta-data nodes as children"); children.Add(x); } }
public AstMetaDataContent(PegAstNode node) : base(node) { CheckLabel(AstLabel.MetaDataContent); }
public PegAstNode CreateNode(Object label) { Trace.Assert(mCur != null); mCur = mCur.Add(this, label); Trace.Assert(mCur != null); return mCur; }
public AstBin(PegAstNode node) : base(node) { CheckLabel(AstLabel.Bin); CheckIsLeaf(node); string s = ToString(); int n = 0; int place = 1; for (int i = s.Length; i > 0; --i) { if (s[i - 1] == '1') { n += place; } else { if (s[i - 1] != '0') throw new Exception("Invalid binary number"); } place *= 2; } value = n; }