AntlrParserToken.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package de.jplag.text;
  2. import antlr.Token;
  3. /**
  4. * Token of the ANTLR grammar, needs to be converted into a JPlag token by the parser adapter.
  5. */
  6. public class AntlrParserToken extends Token {
  7. /**
  8. * This variable holds the line number of the current token.
  9. */
  10. private int line = -1;
  11. /**
  12. * This variable holds the column of the current token in its line.
  13. */
  14. private int column = -1;
  15. /**
  16. * This variable holds the label of the current token.
  17. */
  18. private String text = null;
  19. /**
  20. * This variable holds the identifier of the current token.
  21. */
  22. private int id = -1;
  23. public AntlrParserToken() {
  24. super();
  25. }
  26. @Override
  27. public void setLine(int line) {
  28. this.line = line;
  29. }
  30. @Override
  31. public void setColumn(int column) {
  32. this.column = column;
  33. }
  34. public void setID(int id) {
  35. this.id = id;
  36. }
  37. @Override
  38. public void setText(String text) {
  39. this.text = (text != null ? text.intern() : null);
  40. }
  41. @Override
  42. public int getColumn() {
  43. return column;
  44. }
  45. @Override
  46. public int getLine() {
  47. return line;
  48. }
  49. @Override
  50. public String getText() {
  51. return text;
  52. }
  53. public int getID() {
  54. return id;
  55. }
  56. public int getLength() {
  57. return text.length();
  58. }
  59. @Override
  60. public String toString() {
  61. return "{\"" + getText() + "\", <" + getType() + ">, " + getLine() + " " + getColumn() + "}";
  62. }
  63. }