public ModuleNode(string projectName, string componentName, IEnumerable <SyntaxTreeNode> nodes, bool isClassModule) : base(Instruction.Empty(new LogicalCodeLine(projectName, componentName, 0, 0, string.Empty)), projectName, null, nodes) { _isClassModule = isClassModule; _projectName = projectName; _componentName = componentName; }
/// <summary> /// Splits a logical code line into a number of <see cref="Instruction"/> instances. /// </summary> /// <returns></returns> public IEnumerable <Instruction> SplitInstructions() { // return empty instruction for empty line to preserve vertical whitespace: if (string.IsNullOrWhiteSpace(_content)) { return(new[] { Instruction.Empty(this) }); } const char separator = ':'; // LabelSyntax uses instruction separator; // return entire line if there's no separator or if LabelSyntax matches: var stripped = _content.StripTrailingComment() .StripStringLiterals(); if (!stripped.Contains(separator) || Regex.Match(stripped, VBAGrammar.LabelSyntax).Success) { var indentation = stripped.TakeWhile(char.IsWhiteSpace).Count() + 1; return(new[] { new Instruction(this, indentation, stripped.Length, _content) }); } var result = new List <Instruction>(); var instructionsCount = stripped.Count(c => c == separator) + 1; var startIndex = 0; var endIndex = 0; for (var instruction = 0; instruction < instructionsCount; instruction++) { endIndex = instruction == instructionsCount - 1 ? _content.Length : _content.StripStringLiterals().IndexOf(separator, endIndex) + 1; // +1 because VBE index is 1-based, +1 because there's always a space after a ":". result.Add(new Instruction(this, startIndex, endIndex, _content.Substring(startIndex, endIndex - startIndex))); startIndex = endIndex; } return(result); }
public ProjectNode(string projectName, IEnumerable <SyntaxTreeNode> nodes) : base(Instruction.Empty(new LogicalCodeLine(projectName, projectName, 0, 0, string.Empty)), string.Empty, null, nodes) { }