예제 #1
0
        public HamlDocument ParseHamlFile(HamlFile hamlFile)
        {
            var result = new HamlDocument(hamlFile.FileName);

            ParseNode(result, hamlFile);

            return result;
        }
예제 #2
0
        private void ReadHamlLine(TextReader reader, HamlFile result)
        {
            string currentLine = ReadLine(reader);
            while (_lineLexer.GetEndOfTagIndex(currentLine) < 0)
            {
                if (_eof)
                    throw new HamlMalformedTagException("Multi-line tag found with no end token.", _sourceFileLineIndex);
                currentLine += " " + ReadLine(reader);
            }

            result.AddRange(new HamlLineLexer().ParseHamlLine(currentLine, _sourceFileLineIndex - 1));
        }
예제 #3
0
        private void ReadHamlLine(TextReader reader, HamlFile result)
        {
            string currentLine = ReadLine(reader);

            while (_lineLexer.GetEndOfTagIndex(currentLine) < 0)
            {
                if (_eof)
                {
                    throw new HamlMalformedTagException("Multi-line tag found with no end token.", _sourceFileLineIndex);
                }
                currentLine += " " + ReadLine(reader);
            }

            result.AddRange(new HamlLineLexer().ParseHamlLine(currentLine, _sourceFileLineIndex - 1));
        }
예제 #4
0
        public HamlFile Read(TextReader reader, string fileName)
        {
            _sourceFileLineIndex = 1;

            if (reader == null)
                throw new ArgumentNullException("reader");

            var result = new HamlFile(fileName);
            _eof = (reader.Peek() < 0);

            while (_eof == false)
                ReadHamlLine(reader, result);

            return result;
        }
예제 #5
0
        public HamlFile Read(TextReader reader, string fileName)
        {
            _sourceFileLineIndex = 1;

            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            var result = new HamlFile(fileName);

            _eof = (reader.Peek() < 0);

            while (_eof == false)
            {
                ReadHamlLine(reader, result);
            }

            return(result);
        }
예제 #6
0
        private void ParseNode(HamlNode node, HamlFile hamlFile)
        {
            //node.IsMultiLine = true;
            while ((!hamlFile.EndOfFile) && (hamlFile.CurrentLine.IndentCount > node.IndentCount))
            {
                var nodeLine = hamlFile.CurrentLine;
                var childNode = HamlNodeFactory.GetHamlNode(nodeLine);
                node.AddChild(childNode);

                hamlFile.MoveNext();
                if (hamlFile.EndOfFile == false
                    && hamlFile.CurrentLine.IndentCount > nodeLine.IndentCount)
                {
                    if (hamlFile.CurrentLine.IsInline == false) childNode.AppendInnerTagNewLine();
                    ParseNode(childNode, hamlFile);
                }

                if (hamlFile.EndOfFile == false
                    && hamlFile.CurrentLine.IndentCount >= nodeLine.IndentCount)
                {
                    node.AppendPostTagNewLine(childNode, hamlFile.CurrentLine.Metrics.LineNo);
                }
            }
        }
예제 #7
0
        public void ParseHamlFile_UnknownRuleType_ThrowsUnknownRuleException()
        {
            var line = new HamlLine("", HamlRuleEnum.Unknown, indent: "");

            var file = new HamlFile("");
            file.AddLine(line);
            Assert.Throws<HamlParserUnknownRuleException>(() => _parser.ParseHamlFile(file));
        }