ReaderNestedComment.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (c) 2016 Per M.A. Bothner
  2. // This is free software; for terms and warranty disclaimer see ./COPYING.
  3. package gnu.kawa.lispexpr;
  4. import gnu.kawa.io.InPort;
  5. import gnu.mapping.Values;
  6. import gnu.text.Lexer;
  7. import gnu.text.SyntaxException;
  8. public class ReaderNestedComment extends ReadTableEntry {
  9. char start1;
  10. char start2;
  11. char end1;
  12. char end2;
  13. static ReaderNestedComment lispInstance
  14. = new ReaderNestedComment('#', '|', '|', '#');
  15. public static ReaderNestedComment getLispInstance() { return lispInstance; }
  16. public ReaderNestedComment(char start1, char start2, char end1, char end2) {
  17. this.start1 = start1;
  18. this.start2 = start2;
  19. this.end1 = end1;
  20. this.end2 = end2;
  21. }
  22. public Object read(Lexer in, int ch, int count)
  23. throws java.io.IOException, SyntaxException {
  24. readNestedComment((LispReader) in);
  25. return Values.empty;
  26. }
  27. public void readNestedComment(LispReader reader)
  28. throws java.io.IOException, SyntaxException {
  29. InPort port = reader.getPort();
  30. char saveReadState = '\0';
  31. if (port instanceof InPort) {
  32. saveReadState = ((InPort) port).readState;
  33. ((InPort) port).readState = start1;
  34. }
  35. try {
  36. reader.readNestedComment(start1, start2, end1, end2);
  37. } finally {
  38. if (port instanceof InPort)
  39. ((InPort) port).readState = saveReadState;
  40. }
  41. }
  42. }