コード例 #1
0
ファイル: SourceGenerator.cs プロジェクト: sethyuan/dcg
        private void ProcessStaticText(StaticText directive, string writerKey)
        {
            GenerateDebugLine(this.builder, directive.Line);
            this.builder.Append("this.writers[\"");
            this.builder.Append(writerKey);
            this.builder.Append("\"].Write(@\"");

            if (directive.IsStartOfLine)
            {
                if (this.isNewLine)
                {
                    this.builder.Append(EscapeStaticText(IndentDirective(directive, directive.Value)));
                }
                else
                {
                    this.builder.Append(EscapeStaticText(directive.Value));
                }
            }
            else
            {
                this.builder.Append(EscapeStaticText(directive.Value));
            }

            this.builder.AppendLine("\");");

            this.isNewLine = directive.IsNewLine;
        }
コード例 #2
0
ファイル: AtParser.cs プロジェクト: sethyuan/dcg
        private void ParseTextLine(string line)
        {
            bool isNewLine = true;
            string textLine = HandleLineEnding(line);

            if (whiteHandlingExpr.IsMatch(textLine))
            {
                isNewLine = false;
                textLine = textLine.Substring(0, textLine.LastIndexOf(WhiteDirective));
            }

            List<IDirectiveParser> parsers = MatchDirectives(textLine);

            parsers.Sort(
                delegate(IDirectiveParser x, IDirectiveParser y)
                {
                    if (x.Index < y.Index)
                    {
                        return -1;
                    }
                    else if (x.Index > y.Index)
                    {
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }
                });

            int index = 0;
            StaticText staticText;

            for (int i = 0; i < parsers.Count; i++)
            {
                IDirectiveParser parser = parsers[i];

                staticText =
                    new StaticText(
                        textLine.Substring(index, parser.Index - index).Replace("@@", "@"),
                        this.lineCount);

                if (i == 0)
                {
                    staticText.IsStartOfLine = true;
                }

                this.currentDirective.Directives.Add(staticText);
                parser.Parse();
                index = parser.Index + parser.Length;
            }

            staticText =
                new StaticText(
                    textLine.Substring(index, textLine.Length - index).Replace("@@", "@"),
                    this.lineCount);
            staticText.IsNewLine = isNewLine;

            if (parsers.Count == 0)
            {
                staticText.IsStartOfLine = true;
            }

            this.currentDirective.Directives.Add(staticText);

            ParseBetweenStartIfAny(line);
        }