DifferenceParser.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 Halleuxusing System;
  25. namespace Spart.Parsers.Composite
  26. {
  27. /// <summary>
  28. /// Summary description for DifferenceParser.
  29. /// </summary>
  30. public class DifferenceParser : BinaryTerminalParser
  31. {
  32. public DifferenceParser(Parser left, Parser right)
  33. :base(left,right)
  34. {}
  35. public override ParserMatch ParseMain(Spart.Scanners.IScanner scan)
  36. {
  37. long offset = scan.Offset;
  38. ParserMatch m = FirstParser.Parse(scan);
  39. long goodOffset= scan.Offset;
  40. if (!m.Success)
  41. {
  42. scan.Seek(offset);
  43. return scan.NoMatch;
  44. }
  45. // doing difference
  46. scan.Seek(offset);
  47. ParserMatch d = SecondParser.Parse(scan);
  48. if (d.Success)
  49. {
  50. scan.Seek(offset);
  51. return scan.NoMatch;
  52. }
  53. // ok
  54. scan.Seek(goodOffset);
  55. return m;
  56. }
  57. public override Parser Clone()
  58. {
  59. return base.Clone();
  60. }
  61. }
  62. }