Console.js 979 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * @author Bart McLeod, [email protected]
  3. * @since 2016-05-10
  4. *
  5. * The VrmlParser/Renderer/Console renders the node tree as text output to the console,
  6. * so that one can see what it is parsing.
  7. */
  8. module.exports = {
  9. depth: 0,
  10. decoration: '',
  11. /**
  12. * Render method, that takes the output from the VrmlParser as input and
  13. * writes a textual representation of the node tree to the console.
  14. *
  15. * @param nodeTree
  16. */
  17. render: function (tree) {
  18. this.decoration = '';
  19. // determine decoration base on depth
  20. for (var j = 0; j < this.depth; j++) {
  21. this.decoration += '-';
  22. }
  23. for (var a in tree) {
  24. if ('string' === typeof a) {
  25. var value = tree[a];
  26. if ('object' === typeof value) {
  27. this.depth++;
  28. console.log(this.decoration + a);
  29. this.render(value);
  30. this.depth--;
  31. } else {
  32. console.log(this.decoration + a + ': ' + tree[a]);
  33. }
  34. }
  35. }
  36. }
  37. };