index.vwf.yaml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # A-Frame & VWF simple scene
  2. # Copyright 2017 Krestianstvo.org project
  3. ---
  4. extends: http://vwf.example.com/aframe/ascene.vwf
  5. properties:
  6. assets: "assets.json"
  7. methods:
  8. initialize:
  9. body: |
  10. var calc = vwf_view.kernel.find("", "/calcResult")[0];
  11. console.log(calc);
  12. vwf_view.kernel.callMethod(calc, "calcMe");
  13. children:
  14. groundPlane:
  15. extends: http://vwf.example.com/aframe/aplane.vwf
  16. properties:
  17. height: 50
  18. width: 50
  19. rotation: [-90, 0, 0]
  20. children:
  21. material:
  22. extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
  23. properties:
  24. wireframe: false
  25. src: "#bg2"
  26. repeat: "10 10"
  27. calcResult:
  28. extends: http://vwf.example.com/aframe/atext.vwf
  29. properties:
  30. value: "no result"
  31. color: "#1d7027"
  32. position: [1, 2.5, -2]
  33. scale: [3, 3, 3]
  34. side: "double"
  35. methods:
  36. calcMe:
  37. body: |
  38. let match = this.parent.calcText.calcLang.grammar.match(this.parent.calcText.value);
  39. if (match.succeeded()){
  40. if (typeof this.parent.calcText.calcLang.semantics === 'function'){
  41. this.value = this.parent.calcText.calcLang.semantics(match).interpret()}
  42. }
  43. this.future( 0.1 ).calcMe();
  44. calcText:
  45. extends: http://vwf.example.com/aframe/atext.vwf
  46. properties:
  47. value: "1 * pi"
  48. color: "#b74217"
  49. position: [-1, 2.5, -2]
  50. scale: [2, 2, 2]
  51. side: "double"
  52. children:
  53. calcLang:
  54. extends: http://vwf.example.com/ohm/node.vwf
  55. properties:
  56. grammar:
  57. semantics:
  58. ohmLang: |
  59. Arithmetic {
  60. Exp
  61. = AddExp
  62. AddExp
  63. = AddExp "+" MulExp -- plus
  64. | AddExp "-" MulExp -- minus
  65. | MulExp
  66. MulExp
  67. = MulExp "*" ExpExp -- times
  68. | MulExp "/" ExpExp -- divide
  69. | ExpExp
  70. ExpExp
  71. = PriExp "^" ExpExp -- power
  72. | PriExp
  73. PriExp
  74. = "(" Exp ")" -- paren
  75. | "+" PriExp -- pos
  76. | "-" PriExp -- neg
  77. | ident
  78. | number
  79. ident (an identifier)
  80. = letter alnum*
  81. number (a number)
  82. = digit* "." digit+ -- fract
  83. | digit+ -- whole
  84. }
  85. methods:
  86. initLang:
  87. body: |
  88. console.log("add operations to semantics")
  89. this.addOperationLang();
  90. addOperationLang:
  91. body: |
  92. var constants = {pi: Math.PI, e: Math.E};
  93. this.semantics.addOperation('interpret', {
  94. Exp: function(e) {
  95. return e.interpret();
  96. },
  97. AddExp: function(e) {
  98. return e.interpret();
  99. },
  100. AddExp_plus: function(x, _, y) {
  101. return x.interpret() + y.interpret();
  102. },
  103. AddExp_minus: function(x, _, y) {
  104. return x.interpret() - y.interpret();
  105. },
  106. MulExp: function(e) { return e.interpret(); },
  107. MulExp_times: function(x, _, y) { return x.interpret() * y.interpret(); },
  108. MulExp_divide: function(x, _, y) { return x.interpret() / y.interpret(); },
  109. ExpExp: function(e) { return e.interpret(); },
  110. ExpExp_power: function(x, _, y) { return Math.pow(x.interpret(), y.interpret()); },
  111. PriExp: function(e) { return e.interpret(); },
  112. PriExp_paren: function(_l, e, _r) { return e.interpret(); },
  113. PriExp_pos: function(_, e) { return e.interpret(); },
  114. PriExp_neg: function(_, e) { return -e.interpret(); },
  115. ident: function(_l, _ns) {
  116. // Look up the value of a named constant, e.g., 'pi'.
  117. return constants[this.sourceString] || 0;
  118. },
  119. number: function(_) {
  120. // Use `parseFloat` to convert (e.g.) the string '123' to the number 123.
  121. return parseFloat(this.sourceString);
  122. }
  123. })
  124. testLang:
  125. body: |
  126. var match = this.grammar.match('2+2');
  127. console.log(match);
  128. var res = this.semantics(match).interpret();
  129. console.log(res);
  130. sky:
  131. extends: http://vwf.example.com/aframe/asky.vwf
  132. properties:
  133. children:
  134. material:
  135. extends: http://vwf.example.com/aframe/aMaterialComponent.vwf
  136. properties:
  137. color: "#ECECEC"
  138. side: "back"