static TokenData ScanNewLine(TextInputRange input) { input.NewLine(); input.ExtendWhitespaces(); return(new TokenData { Range = input.Clone(), Type = Token.NewLineIndentation }); }
// Scan basic double quoted strings public static IStringLiteral Scan(TextInputRange input) { var chr = input.EndChar; if (!IsDoubleQuote(chr)) { return(null); } input.Extend(); var result = new StringBuilder(); while (true) { chr = input.EndChar; if (chr == '\0') { return(null); // file end or invalid input } if (IsDoubleQuote(chr)) { break; } if (input.IsEndNewline) { input.NewLine(); } else { if (!IsTab(chr) && char.IsControl(chr)) { HandleControl(input); } else { if (IsBackslash(chr)) { if (!HandleEscape(input, result)) { return(null); } } else { result.Append(chr); input.Extend(); } } } } input.Extend(); return(new StringLiteral { Content = result.ToString(), Range = input.Clone() }); }
/** * # single line * * #<optional># * block comments * #<optional># */ public static bool Scan(TextInputRange range) { if (range.EndChar != '#') { return(false); } do { range.Extend(); } while (range.IsEndValid && !range.IsEndNewline && !range.IsEndWhitespace && range.EndChar != '#'); // single line comment if (range.IsEndNewline) { return(true); } // is block comment if (range.EndChar == '#') { range.Extend(); var commentMarker = range.Text; while (range.IsEndValid && range.EndString(commentMarker.Length) != commentMarker) { if (range.IsEndNewline) { range.NewLine(); } else { range.Extend(); } } if (range.EndString(commentMarker.Length) != commentMarker) { throw new Exception(message: "Line Comment not Escaped."); } range.Extend(commentMarker.Length); } else { do { range.Extend(); } while (range.IsEndValid && !range.IsEndNewline); } return(true); }