public CodeCompletion(MainWindow host) { Envirment.Initial(); Symbols = new List <Envirment>(); Temp = new List <Envirment>(); parser = new Parser(); Global = new Envirment(null); Window = host; }
public List <CompletionInfo> Find(char startChar) { List <CompletionInfo> Id = new List <CompletionInfo>(); Envirment iter = this; while (iter != null) { foreach (var i in iter.dict) { if (i.Info.Length > 0 && i.Info[0] == startChar) { Id.Add(i); } } iter = iter.prev; } return(Id); }
private void UpdateSymbols(AstNode Root, Envirment prev) { try { if (Root == null) { return; } Envirment env = new Envirment(prev) { Start = Root.Left.Location }; AstNode constDefine = Root.Left.Left.Left, varDefine = Root.Left.Left.Right, procDefine = Root.Left.Right, stmt = Root.Right; List <AstNode> consts = constDefine.Info as List <AstNode>, vars = varDefine.Info as List <AstNode>, procs = procDefine.Info as List <AstNode>, stmts = (List <AstNode>)stmt?.Info; if (consts != null) { foreach (var i in consts) { env.Reserve((string)i.Left.Info, EType.Const); Global.Reserve((string)i.Left.Info, EType.Const); } env.End = constDefine.Location; } if (vars != null) { foreach (var i in vars) { env.Reserve((string)i.Left.Info, EType.Var); Global.Reserve((string)i.Left.Info, EType.Var); } env.End = varDefine.Location; } if (procs != null) { foreach (var i in procs) { env.Reserve((string)i.Left.Info, EType.Proc); Global.Reserve((string)i.Left.Info, EType.Proc); UpdateSymbols(i.Right, env); } env.End = procDefine.Location; } if (stmts != null) { if (stmts.Count > 0) { if (stmt.Type == AstType.Statements) { try { env.End = stmts[stmts.Count - 1].Location; } catch (Exception) { } } } } else { if (stmt != null) { env.End = stmt.Location; } } if (stmt != null) { env.End = stmt.Location; AstNode node = stmt; bool Loop = true; while (Loop) { switch (node.Type) { case AstType.WhileDo: case AstType.RepeatUntil: env.End = node.Location; node = node.Right; break; case AstType.IfElse: if (node.Right != null) { env.End = node.Location; node = node.Right; } else { env.End = node.Location; node = node.Left.Right; } break; case AstType.Statements: List <AstNode> list = node.Info as List <AstNode>; if (list.Count > 0) { node = list[list.Count - 1]; env.End = node.Location; } else { Loop = false; } break; default: if (node != null) { env.End = node.Location; } Loop = false; break; } } } Temp.Add(env);//避免排序 } catch (Exception) { } }
public Envirment(Envirment prevEnv) { prev = prevEnv; dict = new HashSet <CompletionInfo>(); }