|
|
@@ -0,0 +1,42 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Text;
|
|
|
+
|
|
|
+namespace Larkdown.Parser.Lexer
|
|
|
+{
|
|
|
+ class BlockLexer
|
|
|
+ {
|
|
|
+ private IList<string> _lines;
|
|
|
+ private IEnumerator<string> _enumerator;
|
|
|
+
|
|
|
+ public BlockLexer(string source)
|
|
|
+ {
|
|
|
+ _lines = source.Split(new[] { "\n" }, 0);
|
|
|
+ _enumerator = _lines.GetEnumerator();
|
|
|
+ }
|
|
|
+
|
|
|
+ public BlockToken NextToken()
|
|
|
+ {
|
|
|
+ if (!_enumerator.MoveNext())
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ var line = _enumerator.Current;
|
|
|
+ var indent = 0;
|
|
|
+ while (indent < line.Length && IsIndent(line[indent++])) { }
|
|
|
+
|
|
|
+ if (indent > 0)
|
|
|
+ {
|
|
|
+ line = line.Substring(indent);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new BlockToken(BlockTokenType.Line, indent, line);
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool IsIndent(char c)
|
|
|
+ {
|
|
|
+ return c == ' ' || c == '\t';
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|