예제 #1
0
        private Node parseTextBlock()
        {
            TextNode textNode = new TextNode();

            textNode.setLineNumber(line());
            textNode.setFileName(filename);
            Token  token       = expect(typeof(Indent));
            Indent indentToken = (Indent)token;
            int    spaces      = indentToken.getIndents();

            if (null == this._spaces)
            {
                this._spaces = spaces;
            }
            String indentStr = StringUtils.repeat(" ", spaces - this._spaces.Value);

            while (!(peek() is Outdent))
            {
                if (peek() is Eos)
                {
                    break;
                }

                if (peek() is Newline)
                {
                    textNode.appendText("\n");
                    this.nextToken();
                }
                else if (peek() is Indent)
                {
                    textNode.appendText("\n");
                    textNode.appendText(this.parseTextBlock().getValue());
                    textNode.appendText("\n");
                }
                else
                {
                    textNode.appendText(indentStr + this.nextToken().getValue());
                }
            }

            if (spaces == this._spaces)
            {
                this._spaces = null;
            }

            if (peek() is Eos)
            {
                return(textNode);
            }
            token = expect(typeof(Outdent));
            return(textNode);
        }
예제 #2
0
파일: JadeParser.cs 프로젝트: rnrn/Jade4Net
        private Node parseTextBlock()
        {
            TextNode textNode = new TextNode();
            textNode.setLineNumber(line());
            textNode.setFileName(filename);
            Token token = expect(typeof (Indent));
            Indent indentToken = (Indent) token;
            int spaces = indentToken.getIndents();
            if (null == this._spaces)
                this._spaces = spaces;
            String indentStr = StringUtils.repeat(" ", spaces - this._spaces.Value);
            while (!(peek() is Outdent))
            {
                if (peek() is Eos)
                    break;

                if (peek() is Newline)
                {
                    textNode.appendText("\n");
                    this.nextToken();
                }
                else if (peek() is Indent)
                {
                    textNode.appendText("\n");
                    textNode.appendText(this.parseTextBlock().getValue());
                    textNode.appendText("\n");
                }
                else
                {
                    textNode.appendText(indentStr + this.nextToken().getValue());
                }
            }

            if (spaces == this._spaces)
                this._spaces = null;

            if (peek() is Eos)
                return textNode;
            token = expect(typeof(Outdent));
            return textNode;
        }