sourceInfo.js 1004 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. export class SourceInfo {
  2. /**
  3. * @param {moo.Token} token
  4. *
  5. * @return {SourceInfo}
  6. * **/
  7. static createSourceInfo (token) {
  8. return new SourceInfo(token.line, token.col, token.text, token.text.length);
  9. }
  10. /**
  11. * @param {moo.Token} tokenA
  12. * @param {moo.Token} tokenB
  13. *
  14. * @return {SourceInfo}
  15. * **/
  16. static createSourceInfoFromList (tokenA, tokenB) {
  17. const line = tokenA.line;
  18. const column = tokenA.col;
  19. // adapted from https://github.com/UNIVALI-LITE/Portugol-Studio/blob/master/core/src/main/java/br/univali/portugol/nucleo/analise/sintatica/Portugol.g
  20. // No idea why...
  21. const size = tokenB.offset + 1 - tokenA.offset
  22. return new SourceInfo(line, column, "", size);
  23. }
  24. /**
  25. * @param {number} line
  26. * @param {number} column
  27. * @param {string} text
  28. * @param {number} size
  29. * **/
  30. constructor (line, column, text, size) {
  31. this.line = line;
  32. this.column = column;
  33. this.text = text;
  34. this.size = size;
  35. }
  36. }