public ModuleBase Load() { ModuleBase m; switch (Path.GetExtension(FileName).ToLowerInvariant()) { case ".frm": m = new FormModule(); break; case ".cls": m = new ClassModule(); break; case ".bas": m = new StandardModule(); break; default: throw new NotSupportedException(); } _States = new Stack <ISourceReadingState>(); _States.Push(new ModuleReadingState(m)); using (var sr = new StreamReader(FileName)) using (var tp = new TokenParser(sr)) { Encoding = sr.CurrentEncoding; while (_States.Any() && tp.Read()) { if (!tp.Tokens.Any()) { continue; } if (!_States.Peek().Accept(this, tp.Tokens)) { _States.Pop(); } } } _States = null; return(m); }
IVbModule IAnalyzer.Analyze(TokenStreamReader reader) { var attributes = AnalyzerTools.GetAttributes(reader).ToDictionary(_ => _.Name); ClassModule mod = new ClassModule(); mod.Visibility = MemberVisibility.Default; mod.Name = attributes[AnalyzerConstants.AttributeName_Name].Value; foreach (IVbAttribute attribute in attributes.Values) { mod.AddMember(attribute); } foreach (IVbField field in AnalyzerTools.GetFields(reader.Rewind())) { mod.AddMember(field); } foreach (IVbMethod method in AnalyzerTools.GetMethods(reader.Rewind())) { mod.AddMember(method); } return mod; }
IVbModule IAnalyzer.Analyze(TokenStreamReader reader) { var attributes = AnalyzerTools.GetAttributes(reader).ToDictionary(_ => _.Name); ClassModule mod = new ClassModule(); mod.Visibility = MemberVisibility.Default; mod.Name = attributes[AnalyzerConstants.AttributeName_Name].Value; foreach (IVbAttribute attribute in attributes.Values) { mod.AddMember(attribute); } foreach (IVbField field in AnalyzerTools.GetFields(reader.Rewind())) { mod.AddMember(field); } foreach (IVbMethod method in AnalyzerTools.GetMethods(reader.Rewind())) { mod.AddMember(method); } return(mod); }
private ISyntaxTreeNode ParseFileHeader(string fileName, string[] content, ref int currentLine) { ISyntaxTreeNode result; var firstLine = content[0].Trim(); if (firstLine == "VERSION 1.0 CLASS") { var multiUse = content[2].Trim(); var persistable = content[3].Trim(); var dataBindingBehavior = content[4].Trim(); var dataSourceBehavior = content[5].Trim(); var mtsTransactionMode = content[6].Trim(); var regex = new Regex(@"\=\s\-?(?<IntValue>\d+)\s"); result = new ClassModule(fileName) { DataBindingBehavior = int.Parse(regex.Match(dataBindingBehavior).Groups["IntValue"].Value), DataSourceBehavior = int.Parse(regex.Match(dataSourceBehavior).Groups["IntValue"].Value), MTSTransactionMode = int.Parse(regex.Match(mtsTransactionMode).Groups["IntValue"].Value), MultiUse = int.Parse(regex.Match(multiUse).Groups["IntValue"].Value), Persistable = int.Parse(regex.Match(persistable).Groups["IntValue"].Value) }; result.Nodes.Add(AttributeNode.Parse(content[8].Trim())); result.Nodes.Add(AttributeNode.Parse(content[9].Trim())); result.Nodes.Add(AttributeNode.Parse(content[10].Trim())); result.Nodes.Add(AttributeNode.Parse(content[11].Trim())); result.Nodes.Add(AttributeNode.Parse(content[12].Trim())); currentLine = 13; } else { result = new CodeModule(fileName); result.Nodes.Add(AttributeNode.Parse(content[0].Trim())); currentLine = 1; } return result; }