Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nodes.js 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. 'use strict';
  2. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  3. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  4. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
  5. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  6. var _require = require('./object'),
  7. Obj = _require.Obj;
  8. function traverseAndCheck(obj, type, results) {
  9. if (obj instanceof type) {
  10. results.push(obj);
  11. }
  12. if (obj instanceof Node) {
  13. obj.findAll(type, results);
  14. }
  15. }
  16. var Node = /*#__PURE__*/function (_Obj) {
  17. _inheritsLoose(Node, _Obj);
  18. function Node() {
  19. return _Obj.apply(this, arguments) || this;
  20. }
  21. var _proto = Node.prototype;
  22. _proto.init = function init(lineno, colno) {
  23. var _arguments = arguments,
  24. _this = this;
  25. for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  26. args[_key - 2] = arguments[_key];
  27. }
  28. this.lineno = lineno;
  29. this.colno = colno;
  30. this.fields.forEach(function (field, i) {
  31. // The first two args are line/col numbers, so offset by 2
  32. var val = _arguments[i + 2]; // Fields should never be undefined, but null. It makes
  33. // testing easier to normalize values.
  34. if (val === undefined) {
  35. val = null;
  36. }
  37. _this[field] = val;
  38. });
  39. };
  40. _proto.findAll = function findAll(type, results) {
  41. var _this2 = this;
  42. results = results || [];
  43. if (this instanceof NodeList) {
  44. this.children.forEach(function (child) {
  45. return traverseAndCheck(child, type, results);
  46. });
  47. } else {
  48. this.fields.forEach(function (field) {
  49. return traverseAndCheck(_this2[field], type, results);
  50. });
  51. }
  52. return results;
  53. };
  54. _proto.iterFields = function iterFields(func) {
  55. var _this3 = this;
  56. this.fields.forEach(function (field) {
  57. func(_this3[field], field);
  58. });
  59. };
  60. return Node;
  61. }(Obj); // Abstract nodes
  62. var Value = /*#__PURE__*/function (_Node) {
  63. _inheritsLoose(Value, _Node);
  64. function Value() {
  65. return _Node.apply(this, arguments) || this;
  66. }
  67. _createClass(Value, [{
  68. key: "typename",
  69. get: function get() {
  70. return 'Value';
  71. }
  72. }, {
  73. key: "fields",
  74. get: function get() {
  75. return ['value'];
  76. }
  77. }]);
  78. return Value;
  79. }(Node); // Concrete nodes
  80. var NodeList = /*#__PURE__*/function (_Node2) {
  81. _inheritsLoose(NodeList, _Node2);
  82. function NodeList() {
  83. return _Node2.apply(this, arguments) || this;
  84. }
  85. var _proto2 = NodeList.prototype;
  86. _proto2.init = function init(lineno, colno, nodes) {
  87. _Node2.prototype.init.call(this, lineno, colno, nodes || []);
  88. };
  89. _proto2.addChild = function addChild(node) {
  90. this.children.push(node);
  91. };
  92. _createClass(NodeList, [{
  93. key: "typename",
  94. get: function get() {
  95. return 'NodeList';
  96. }
  97. }, {
  98. key: "fields",
  99. get: function get() {
  100. return ['children'];
  101. }
  102. }]);
  103. return NodeList;
  104. }(Node);
  105. var Root = NodeList.extend('Root');
  106. var Literal = Value.extend('Literal');
  107. var Symbol = Value.extend('Symbol');
  108. var Group = NodeList.extend('Group');
  109. var ArrayNode = NodeList.extend('Array');
  110. var Pair = Node.extend('Pair', {
  111. fields: ['key', 'value']
  112. });
  113. var Dict = NodeList.extend('Dict');
  114. var LookupVal = Node.extend('LookupVal', {
  115. fields: ['target', 'val']
  116. });
  117. var If = Node.extend('If', {
  118. fields: ['cond', 'body', 'else_']
  119. });
  120. var IfAsync = If.extend('IfAsync');
  121. var InlineIf = Node.extend('InlineIf', {
  122. fields: ['cond', 'body', 'else_']
  123. });
  124. var For = Node.extend('For', {
  125. fields: ['arr', 'name', 'body', 'else_']
  126. });
  127. var AsyncEach = For.extend('AsyncEach');
  128. var AsyncAll = For.extend('AsyncAll');
  129. var Macro = Node.extend('Macro', {
  130. fields: ['name', 'args', 'body']
  131. });
  132. var Caller = Macro.extend('Caller');
  133. var Import = Node.extend('Import', {
  134. fields: ['template', 'target', 'withContext']
  135. });
  136. var FromImport = /*#__PURE__*/function (_Node3) {
  137. _inheritsLoose(FromImport, _Node3);
  138. function FromImport() {
  139. return _Node3.apply(this, arguments) || this;
  140. }
  141. var _proto3 = FromImport.prototype;
  142. _proto3.init = function init(lineno, colno, template, names, withContext) {
  143. _Node3.prototype.init.call(this, lineno, colno, template, names || new NodeList(), withContext);
  144. };
  145. _createClass(FromImport, [{
  146. key: "typename",
  147. get: function get() {
  148. return 'FromImport';
  149. }
  150. }, {
  151. key: "fields",
  152. get: function get() {
  153. return ['template', 'names', 'withContext'];
  154. }
  155. }]);
  156. return FromImport;
  157. }(Node);
  158. var FunCall = Node.extend('FunCall', {
  159. fields: ['name', 'args']
  160. });
  161. var Filter = FunCall.extend('Filter');
  162. var FilterAsync = Filter.extend('FilterAsync', {
  163. fields: ['name', 'args', 'symbol']
  164. });
  165. var KeywordArgs = Dict.extend('KeywordArgs');
  166. var Block = Node.extend('Block', {
  167. fields: ['name', 'body']
  168. });
  169. var Super = Node.extend('Super', {
  170. fields: ['blockName', 'symbol']
  171. });
  172. var TemplateRef = Node.extend('TemplateRef', {
  173. fields: ['template']
  174. });
  175. var Extends = TemplateRef.extend('Extends');
  176. var Include = Node.extend('Include', {
  177. fields: ['template', 'ignoreMissing']
  178. });
  179. var Set = Node.extend('Set', {
  180. fields: ['targets', 'value']
  181. });
  182. var Switch = Node.extend('Switch', {
  183. fields: ['expr', 'cases', 'default']
  184. });
  185. var Case = Node.extend('Case', {
  186. fields: ['cond', 'body']
  187. });
  188. var Output = NodeList.extend('Output');
  189. var Capture = Node.extend('Capture', {
  190. fields: ['body']
  191. });
  192. var TemplateData = Literal.extend('TemplateData');
  193. var UnaryOp = Node.extend('UnaryOp', {
  194. fields: ['target']
  195. });
  196. var BinOp = Node.extend('BinOp', {
  197. fields: ['left', 'right']
  198. });
  199. var In = BinOp.extend('In');
  200. var Is = BinOp.extend('Is');
  201. var Or = BinOp.extend('Or');
  202. var And = BinOp.extend('And');
  203. var Not = UnaryOp.extend('Not');
  204. var Add = BinOp.extend('Add');
  205. var Concat = BinOp.extend('Concat');
  206. var Sub = BinOp.extend('Sub');
  207. var Mul = BinOp.extend('Mul');
  208. var Div = BinOp.extend('Div');
  209. var FloorDiv = BinOp.extend('FloorDiv');
  210. var Mod = BinOp.extend('Mod');
  211. var Pow = BinOp.extend('Pow');
  212. var Neg = UnaryOp.extend('Neg');
  213. var Pos = UnaryOp.extend('Pos');
  214. var Compare = Node.extend('Compare', {
  215. fields: ['expr', 'ops']
  216. });
  217. var CompareOperand = Node.extend('CompareOperand', {
  218. fields: ['expr', 'type']
  219. });
  220. var CallExtension = Node.extend('CallExtension', {
  221. init: function init(ext, prop, args, contentArgs) {
  222. this.parent();
  223. this.extName = ext.__name || ext;
  224. this.prop = prop;
  225. this.args = args || new NodeList();
  226. this.contentArgs = contentArgs || [];
  227. this.autoescape = ext.autoescape;
  228. },
  229. fields: ['extName', 'prop', 'args', 'contentArgs']
  230. });
  231. var CallExtensionAsync = CallExtension.extend('CallExtensionAsync'); // This is hacky, but this is just a debugging function anyway
  232. function print(str, indent, inline) {
  233. var lines = str.split('\n');
  234. lines.forEach(function (line, i) {
  235. if (line && (inline && i > 0 || !inline)) {
  236. process.stdout.write(' '.repeat(indent));
  237. }
  238. var nl = i === lines.length - 1 ? '' : '\n';
  239. process.stdout.write("" + line + nl);
  240. });
  241. } // Print the AST in a nicely formatted tree format for debuggin
  242. function printNodes(node, indent) {
  243. indent = indent || 0;
  244. print(node.typename + ': ', indent);
  245. if (node instanceof NodeList) {
  246. print('\n');
  247. node.children.forEach(function (n) {
  248. printNodes(n, indent + 2);
  249. });
  250. } else if (node instanceof CallExtension) {
  251. print(node.extName + "." + node.prop + "\n");
  252. if (node.args) {
  253. printNodes(node.args, indent + 2);
  254. }
  255. if (node.contentArgs) {
  256. node.contentArgs.forEach(function (n) {
  257. printNodes(n, indent + 2);
  258. });
  259. }
  260. } else {
  261. var nodes = [];
  262. var props = null;
  263. node.iterFields(function (val, fieldName) {
  264. if (val instanceof Node) {
  265. nodes.push([fieldName, val]);
  266. } else {
  267. props = props || {};
  268. props[fieldName] = val;
  269. }
  270. });
  271. if (props) {
  272. print(JSON.stringify(props, null, 2) + '\n', null, true);
  273. } else {
  274. print('\n');
  275. }
  276. nodes.forEach(function (_ref) {
  277. var fieldName = _ref[0],
  278. n = _ref[1];
  279. print("[" + fieldName + "] =>", indent + 2);
  280. printNodes(n, indent + 4);
  281. });
  282. }
  283. }
  284. module.exports = {
  285. Node: Node,
  286. Root: Root,
  287. NodeList: NodeList,
  288. Value: Value,
  289. Literal: Literal,
  290. Symbol: Symbol,
  291. Group: Group,
  292. Array: ArrayNode,
  293. Pair: Pair,
  294. Dict: Dict,
  295. Output: Output,
  296. Capture: Capture,
  297. TemplateData: TemplateData,
  298. If: If,
  299. IfAsync: IfAsync,
  300. InlineIf: InlineIf,
  301. For: For,
  302. AsyncEach: AsyncEach,
  303. AsyncAll: AsyncAll,
  304. Macro: Macro,
  305. Caller: Caller,
  306. Import: Import,
  307. FromImport: FromImport,
  308. FunCall: FunCall,
  309. Filter: Filter,
  310. FilterAsync: FilterAsync,
  311. KeywordArgs: KeywordArgs,
  312. Block: Block,
  313. Super: Super,
  314. Extends: Extends,
  315. Include: Include,
  316. Set: Set,
  317. Switch: Switch,
  318. Case: Case,
  319. LookupVal: LookupVal,
  320. BinOp: BinOp,
  321. In: In,
  322. Is: Is,
  323. Or: Or,
  324. And: And,
  325. Not: Not,
  326. Add: Add,
  327. Concat: Concat,
  328. Sub: Sub,
  329. Mul: Mul,
  330. Div: Div,
  331. FloorDiv: FloorDiv,
  332. Mod: Mod,
  333. Pow: Pow,
  334. Neg: Neg,
  335. Pos: Pos,
  336. Compare: Compare,
  337. CompareOperand: CompareOperand,
  338. CallExtension: CallExtension,
  339. CallExtensionAsync: CallExtensionAsync,
  340. printNodes: printNodes
  341. };