Beispiel #1
0
        private void ProcessLine(string line)
        {
            var sectionPattern   = new MatchState("^" + _Prefix + "section (.+)$");
            var helperPattern    = new MatchState("^" + _Prefix + "helper (.+)$");
            var statementPattern = new MatchState("^" + _Prefix + "((?:if|for|foreach|while)\\s*\\(.+\\))$");
            var callPattern      = new MatchState("^" + _Prefix + "(.*)$");

            if (_CodeBlockIndentationLevel.HasValue)
            {
                ProcessCodeBlockLine(line);
            }
            else if (line == _ScopeStart)
            {
                MergeAndEmitLiterals();
                _Builder.IncreaseIndentation();
            }
            else if (line == _ScopeEnd)
            {
                MergeAndEmitLiterals();
                _Builder.DecreaseIndentation();
            }
            else if (sectionPattern.Matches(line))
            {
                MergeAndEmitLiterals();
                string section        = sectionPattern.GetGroup(1);
                string escapedSection = EscapeString(section);
                _Builder.AppendLine($"DefineSection(\"{escapedSection}\", () =>");
                _Builder.EnterSection();
            }
            else if (helperPattern.Matches(line))
            {
                MergeAndEmitLiterals();
                string signature = helperPattern.GetGroup(1);
                _Builder.EnterHelper();
                _Builder.AppendLine($"public void {signature}");
            }
            else if (statementPattern.Matches(line))
            {
                MergeAndEmitLiterals();
                string block = statementPattern.GetGroup(1);
                _Builder.AppendLine(block);
            }
            else if (line == _Prefix + _ScopeStart)
            {
                MergeAndEmitLiterals();
                if (_CodeBlockIndentationLevel.HasValue)
                {
                    throw new CompilerException("Nesting code blocks is not permitted.");
                }
                _CodeBlockIndentationLevel = 1;
            }
            else if (callPattern.Matches(line))
            {
                MergeAndEmitLiterals();
                string call = callPattern.GetGroup(1);
                _Builder.AppendLine($"{call};");
            }
            else
            {
                ProcesLiteralsAndInlineStatements(line);
            }
        }