IScanner.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /// Spart License (zlib/png)
  2. ///
  3. ///
  4. /// Copyright (c) 2003 Jonathan de Halleux
  5. ///
  6. /// This software is provided 'as-is', without any express or implied warranty.
  7. /// In no event will the authors be held liable for any damages arising from
  8. /// the use of this software.
  9. ///
  10. /// Permission is granted to anyone to use this software for any purpose,
  11. /// including commercial applications, and to alter it and redistribute it
  12. /// freely, subject to the following restrictions:
  13. ///
  14. /// 1. The origin of this software must not be misrepresented; you must not
  15. /// claim that you wrote the original software. If you use this software in a
  16. /// product, an acknowledgment in the product documentation would be
  17. /// appreciated but is not required.
  18. ///
  19. /// 2. Altered source versions must be plainly marked as such, and must not be
  20. /// misrepresented as being the original software.
  21. ///
  22. /// 3. This notice may not be removed or altered from any source distribution.
  23. ///
  24. /// Author: Jonathan de Halleux
  25. namespace Spart.Scanners
  26. {
  27. using System;
  28. using Spart.Parsers;
  29. /// <summary>
  30. /// Input scanner interface
  31. /// </summary>
  32. public interface IScanner
  33. {
  34. /// <summary>
  35. /// Return true if all input is consummed
  36. /// </summary>
  37. bool AtEnd {get;}
  38. /// <summary>
  39. /// Reads one character of the input
  40. /// </summary>
  41. /// <returns>true if not at end</returns>
  42. bool Read();
  43. /// <summary>
  44. /// Current character
  45. /// </summary>
  46. /// <returns></returns>
  47. char Peek();
  48. /// <summary>
  49. /// Scanner cursor position
  50. /// </summary>
  51. long Offset{get;set;}
  52. /// <summary>
  53. /// Move cursor position to the offset
  54. /// </summary>
  55. /// <param name="offset"></param>
  56. void Seek(long offset);
  57. /// <summary>
  58. /// Extracts a substring of the input
  59. /// </summary>
  60. /// <param name="offset"></param>
  61. /// <param name="length"></param>
  62. /// <returns></returns>
  63. String Substring(long offset, int length);
  64. /// <summary>
  65. /// Sets the input filter
  66. /// </summary>
  67. IFilter Filter{get;set;}
  68. /// <summary>
  69. /// Create a failure match
  70. /// </summary>
  71. ParserMatch NoMatch {get;}
  72. /// <summary>
  73. /// Create an empty match
  74. /// </summary>
  75. ParserMatch EmptyMatch {get;}
  76. /// <summary>
  77. /// Create a match out of the intput
  78. /// </summary>
  79. /// <param name="offset"></param>
  80. /// <param name="length"></param>
  81. /// <returns></returns>
  82. ParserMatch CreateMatch(long offset, int length);
  83. bool IsSkipping {get; set;}
  84. Parser SkipParser {get; set;}
  85. }
  86. }