Source: mvc/parser/parserModule.js

  1. define(
  2. /**
  3. * This module holds functions / classes for template parsing.
  4. *
  5. * <p>
  6. * This module contains definitions for constants used in the Template Parser and Renderer.
  7. *
  8. *
  9. *
  10. * @namespace
  11. * @name mmir.parser
  12. * @example
  13. * //access the parser module
  14. * var someConst = mmir.require('mmirf/parserModule').element.INCLUDE_SCRIPT;
  15. * ...
  16. *
  17. */
  18. function(
  19. ){
  20. var parser = {
  21. /**
  22. * the root path for stylesheets:
  23. * will be prepended to file-paths when rendering <code>@style(file-path)</code>
  24. *
  25. * @static
  26. * @type String
  27. * @default ""
  28. * @memberOf mmir.parser
  29. */
  30. stylesRoot: '',
  31. /**
  32. * @class
  33. * @name mmir.parser.Element
  34. * @static
  35. */
  36. element: {
  37. //TODO detect&use Object.defineProperty (if positively detected), e.g.:
  38. // Object.defineProperty(parser.element, 'INCLUDE_SCRIPT', {value : 0, writable : false, configurable : false, enumerable : true});
  39. /**
  40. * Constant for template expression type <tt>include script</tt>.
  41. *
  42. * <p>
  43. * The template expression generates a script TAG.
  44. *
  45. * <p>
  46. * Properties of {@link mmir.parser.ParsingResult} objects with type INCLUDE_SCRIPT:
  47. * <ul>
  48. * <li><strong>scriptPath</strong>: the path / URL to the resource</li>
  49. * <li><strong>scriptPathType</strong>: the type of the <tt>scriptPath</tt>
  50. * field: one of <code>StringLiteral</code>, <code>Identifier</code>, <code>IdentifierNameAmpersatStart</code></li>
  51. * </ul>
  52. *
  53. * @memberOf mmir.parser.Element
  54. * @constant
  55. * @type Number
  56. * @public
  57. */
  58. INCLUDE_SCRIPT : 0,
  59. /**
  60. * Constant for template expression type <tt>include style</tt>.
  61. *
  62. * <p>
  63. * The template expression generates a style reference, i.e.
  64. * a link TAG with <tt>rel</tt> attribute <code>stylesheet</code>.
  65. *
  66. * <p>
  67. * Properties of {@link mmir.parser.ParsingResult} objects with type INCLUDE_STYLE:
  68. * <ul>
  69. * <li><strong>stylePath</strong>: </li>
  70. * <li><strong>stylePathType</strong>: the type of the <tt>stylePath</tt>
  71. * field: one of <code>StringLiteral</code>, <code>Identifier</code>, <code>IdentifierNameAmpersatStart</code></li>
  72. * </ul>
  73. *
  74. * @memberOf mmir.parser.Element
  75. * @constant
  76. * @type Number
  77. * @public
  78. */
  79. INCLUDE_STYLE : 2,
  80. /**
  81. * Constant for template expression type <tt>localize</tt>.
  82. *
  83. * <p>
  84. * The template expression inserts a localized String.
  85. *
  86. * <p>
  87. * Properties of {@link mmir.parser.ParsingResult} objects with type LOCALIZE:
  88. * <ul>
  89. * <li><strong>name</strong>: the name/identifier for the localized String</li>
  90. * <li><strong>nameType</strong>: the type of the <tt>name</tt>
  91. * field: one of <code>StringLiteral</code>, <code>Identifier</code>, <code>IdentifierNameAmpersatStart</code></li>
  92. * </ul>
  93. *
  94. * @memberOf mmir.parser.Element
  95. * @constant
  96. * @type Number
  97. * @public
  98. */
  99. LOCALIZE : 4,
  100. /**
  101. * Constant for template expression type <tt>yield declaration</tt>.
  102. *
  103. * <p>
  104. * The template expression declares a yield section.
  105. *
  106. * <p>
  107. * Properties of {@link mmir.parser.ParsingResult} objects with type YIELD_DECLARATION:
  108. * <ul>
  109. * <li><strong>name</strong>: the name/identifier for the yield section</li>
  110. * <li><strong>nameType</strong>: the type of the <tt>name</tt>
  111. * field: one of <code>StringLiteral</code>, <code>Identifier</code>, <code>IdentifierNameAmpersatStart</code></li>
  112. * </ul>
  113. *
  114. * @memberOf mmir.parser.Element
  115. * @constant
  116. * @type Number
  117. * @public
  118. */
  119. YIELD_DECLARATION : 8,
  120. /**
  121. * Constant for template expression type <tt>yield content</tt>.
  122. *
  123. * <p>
  124. * The template expression specifies the content of a yield section.
  125. *
  126. * <p>
  127. * A yield section corresponds to a {@link ContentElement}:
  128. * Its content can itself contain HTML content as well as template expressions.
  129. *
  130. * @memberOf mmir.parser.Element
  131. * @constant
  132. * @type Number
  133. * @public
  134. */
  135. YIELD_CONTENT : 16,
  136. /**
  137. * Constant for template expression type <tt>code block</tt>.
  138. *
  139. * <p>
  140. * The template expression represents a compiled code block (script).
  141. *
  142. * <p>
  143. * Properties of {@link mmir.parser.ParsingResult} objects with type BLOCK:
  144. * <ul>
  145. * <li><strong>scriptContent</strong> {String}: <tt>OPTIONALLY</tt> the script code as a String</li>
  146. * <li><strong>scriptEval</strong> {Function}: the compiled script code in form of a function. The
  147. * function takes one argument: the current data-object.</li>
  148. * </ul>
  149. *
  150. * @memberOf mmir.parser.Element
  151. * @constant
  152. * @type Number
  153. * @public
  154. */
  155. BLOCK : 32,
  156. /**
  157. * Constant for template expression type <tt>code statement</tt>.
  158. *
  159. * <p>
  160. * The template expression represents a compiled code statement (script).
  161. *
  162. * <p>
  163. * Properties of {@link mmir.parser.ParsingResult} objects with type STATEMENT:
  164. * <ul>
  165. * <li><strong>scriptContent</strong> {String}: <tt>OPTIONALLY</tt> the script code as a String</li>
  166. * <li><strong>scriptEval</strong> {Function}: the compiled script code in form of a function. The
  167. * function takes one argument: the current data-object.</li>
  168. * </ul>
  169. *
  170. * @memberOf mmir.parser.Element
  171. * @constant
  172. * @type Number
  173. * @public
  174. */
  175. STATEMENT : 64,
  176. /**
  177. * Constant for template expression type <tt>helper</tt>.
  178. *
  179. * <p>
  180. * The template expression will invoke a function in the {@link Helper} instance
  181. * (depending of the {@link Controller}, in which's view definition this template expression is used).
  182. *
  183. * <p>
  184. * Properties of {@link mmir.parser.ParsingResult} objects with type HELPER:
  185. * <ul>
  186. * <li><strong>helper</strong>: the name of the helper function</li>
  187. * <li><strong>helperType</strong>: the type of the <tt>helper</tt>
  188. * field: one of <code>StringLiteral</code>, <code>Identifier</code>, <code>IdentifierNameAmpersatStart</code></li>
  189. * <li><strong>argsEval</strong> {Function}: OPTIONALLY compiled getter Function for retrieving the current ARGS
  190. * (optional argument) of the helper expression. The function takes one argument: the current data-object.</li>
  191. * </ul>
  192. *
  193. * @memberOf mmir.parser.Element
  194. * @constant
  195. * @type Number
  196. * @public
  197. */
  198. HELPER : 128,
  199. /**
  200. * Constant for template expression type <tt>if</tt>.
  201. *
  202. * <p>
  203. * The template expression represents an if-expression, including the content-block
  204. * that follows the condition-statement of the if-expression.
  205. *
  206. * <p>
  207. * Properties of {@link mmir.parser.ParsingResult} objects with type IF:
  208. * <ul>
  209. * <li><strong>ifEval</strong> {Function}: the condition statement, that was compiled into a Function. The
  210. * function takes one argument: the current data-object.</li>
  211. * <li><strong>content</strong> {ContentElement}: the HTML / template content that should be render, in case the
  212. * if-expression evaluates to <code>true</code>.</li>
  213. * <li><strong>elseContent</strong> {@link mmir.parser.ParsingResult}: OPTIONALLY a ParsingResult
  214. * representing an else-expression, see {@link mmir.parser.Element.ELSE}.</li>
  215. * </ul>
  216. *
  217. * @memberOf mmir.parser.Element
  218. * @constant
  219. * @type Number
  220. * @public
  221. */
  222. IF : 256,
  223. /**
  224. * Constant for template expression type <tt>else</tt>.
  225. *
  226. * <p>
  227. * The template expression represents an else-expression (including its content-block);
  228. * an else-expression may occur in combination with an if-expression, see {@link mmir.parser.Element.IF}.
  229. *
  230. * <p>
  231. * Properties of {@link mmir.parser.ParsingResult} objects with type ELSE:
  232. * <ul>
  233. * <li><strong>content</strong> {ContentElement}: the HTML / template content that should be render, in case the
  234. * if-expression (to which the else-expression belongs) evaluates to <code>false</code>.</li>
  235. * </ul>
  236. *
  237. * @memberOf mmir.parser.Element
  238. * @constant
  239. * @type Number
  240. * @public
  241. */
  242. ELSE : 512,
  243. /**
  244. * Constant for template expression type <tt>for</tt>.
  245. *
  246. * <p>
  247. * The template expression represents for-expression (including its content-block);
  248. *
  249. * <p>
  250. * Properties of {@link mmir.parser.ParsingResult} objects with type FOR:
  251. * <ul>
  252. * <li><strong>forControlType</strong> {String}: the type of for-loop, either <code>FORITER</code> or <code>FORSTEP</code></li>
  253. * <li><strong>forInitEval</strong> {Function}: the initialization statement of the for-expression, compiled into
  254. * a Function. The function takes one argument: the current data-object.</li>
  255. *
  256. * <li><code>FORITER</code>: <code>@for(PROP in OBJ){ ... }@</code>
  257. * <ul>
  258. * <li><strong>forIterator</strong> {Object}: an iterator object with functions <code>hasNext() : Boolean</code> and
  259. * <code>next() : String</code> (which returns the name of the property currently iterated).</li>
  260. * <li><strong>forPropName</strong> {String}: the variable name for the property which is currently iterated over.</li>
  261. * </ul>
  262. * </li>
  263. * <li><code>FORSTEP</code>: <code>@for(INIT; CONDITION; INCREMENT){ ... }@</code>
  264. * <ul>
  265. * <li><strong>forConditionEval</strong> {Function}: the condition statement of the for-expression, compiled into
  266. * a Function. The function takes one argument: the current data-object.</li>
  267. * <li><strong>forIncrementEval</strong> {Function}: the increment statement of the for-expression, compiled into
  268. * a Function. The function takes one argument: the current data-object.</li>
  269. * </ul>
  270. * </li>
  271. * <li><strong>content</strong> {ContentElement}: the HTML / template content that should be rendered
  272. * during each iteration of the for-loop.</li>
  273. * </ul>
  274. *
  275. * @memberOf mmir.parser.Element
  276. * @constant
  277. * @type Number
  278. * @public
  279. */
  280. FOR : 1024,
  281. /**
  282. * Constant for template expression type <tt>render</tt>.
  283. *
  284. * <p>
  285. * The template expression renders a <tt>partial view</tt> into a view.
  286. *
  287. *
  288. * <p>
  289. * Properties of {@link mmir.parser.ParsingResult} objects with type RENDER:
  290. * <ul>
  291. * <li><strong>partial</strong>: the name of the partial view</li>
  292. * <li><strong>partialType</strong>: the type of the <tt>partial</tt>
  293. * field: one of <code>StringLiteral</code>, <code>Identifier</code>, <code>IdentifierNameAmpersatStart</code></li>
  294. * <li><strong>controller</strong>: the name of the controller, to which the partial view definition belongs</li>
  295. * <li><strong>controllerType</strong>: the type of the <tt>controller</tt>
  296. * field: one of <code>StringLiteral</code>, <code>Identifier</code>, <code>IdentifierNameAmpersatStart</code></li>
  297. * <li><strong>argsEval</strong> {Function}: OPTIONALLY compiled getter Function for retrieving the current ARGS
  298. * (optional argument) of the render expression. The function takes one argument: the current data-object.</li>
  299. * </ul>
  300. *
  301. * @memberOf mmir.parser.Element
  302. * @constant
  303. * @type Number
  304. * @public
  305. */
  306. RENDER : 2048,
  307. /**
  308. * Constant for template expression type <tt>escape enter</tt>.
  309. *
  310. * <p>
  311. * The template expression represents an escape statement (when entering a template expression);
  312. * escaping means, that the following sequence is not interpreted as template expression.
  313. *
  314. * <p>
  315. * Properties of {@link mmir.parser.ParsingResult} objects with type ESCAPE_ENTER:
  316. * <ul>
  317. * <li><strong>text</strong> {String}: the text that will be rendered (i.e. without the escape-character(s) itself).</li>
  318. * </ul>
  319. *
  320. * @memberOf mmir.parser.Element
  321. * @constant
  322. * @type Number
  323. * @public
  324. */
  325. ESCAPE_ENTER : 4096,
  326. /**
  327. * Constant for template expression type <tt>escape exit</tt>.
  328. *
  329. * <p>
  330. * The template expression represents an escape statement (when exiting a template expression);
  331. * escaping means, that the following sequence is not interpreted as template expression.
  332. *
  333. * <p>
  334. * Properties of {@link mmir.parser.ParsingResult} objects with type ESCAPE_EXIT:
  335. * <ul>
  336. * <li><strong>text</strong> {String}: the text that will be rendered (i.e. without the escape-character(s) itself).</li>
  337. * </ul>
  338. *
  339. * @memberOf mmir.parser.Element
  340. * @constant
  341. * @type Number
  342. * @public
  343. */
  344. ESCAPE_EXIT : 8192,
  345. /**
  346. * Constant for for-expression type <tt>iter</tt> ("iteration").
  347. *
  348. * <p>
  349. * This type identifies an ITERATION type for-expression.
  350. *
  351. *
  352. * @memberOf mmir.parser.Element
  353. * @constant
  354. * @type Number
  355. * @public
  356. *
  357. * @see parser.element.FOR
  358. */
  359. FOR_TYPE_ITER : 16384,
  360. /**
  361. * Constant for for-expression type <tt>step</tt> ("step-wise").
  362. *
  363. * <p>
  364. * This type identifies an STEP-wise type for-expression.
  365. *
  366. *
  367. * @memberOf mmir.parser.Element
  368. * @constant
  369. * @type Number
  370. * @public
  371. *
  372. * @see parser.element.FOR
  373. */
  374. FOR_TYPE_STEP : 32768,
  375. /**
  376. * Constant for template expression type <tt>variable declaration</tt>.
  377. *
  378. * <p>
  379. * The template expression represents a variable declaration.
  380. *
  381. * <p>
  382. * Properties of {@link mmir.parser.ParsingResult} objects with type VAR_DECLARATION:
  383. * <ul>
  384. * <li><strong>name</strong>: the name for the variable (without the leading <tt>@</tt> of template variables)</li>
  385. * <li><strong>nameType</strong>: the type of the <tt>name</tt> field: <code>StringLiteral</code></li>
  386. * </ul>
  387. *
  388. * @memberOf mmir.parser.Element
  389. * @constant
  390. * @type Number
  391. * @public
  392. */
  393. VAR_DECLARATION : 65536,
  394. /**
  395. * Constant for template expression type <tt>variable reference</tt>.
  396. *
  397. * <p>
  398. * This template expression is used within JavaScript code blocks / statements,
  399. * in order to replace the occurrence of the <tt>template variable</tt> by an
  400. * appropriate getter function, that retrieves the current value of the variable
  401. * during the execution of the script code.
  402. *
  403. * <p>
  404. * NOTE: this is used during compilation of the Function objects, used e.g. by BLOCK, STATEMENT, FOR etc.
  405. *
  406. * <p>
  407. * NOTE: the name of the variable is extracted from the raw-template text during processing/compilation
  408. * of the Functions.
  409. *
  410. * @memberOf mmir.parser.Element
  411. * @constant
  412. * @type Number
  413. * @public
  414. */
  415. VAR_REFERENCE : 131072,
  416. /**
  417. * Constant for template expression type <tt>comment</tt>.
  418. *
  419. * <p>
  420. * The template expression represents a template-comment: the content of the comment will be ignored
  421. * (that is: removed during processing of the template).
  422. *
  423. * @memberOf mmir.parser.Element
  424. * @constant
  425. * @type Number
  426. * @public
  427. */
  428. COMMENT : 262144,
  429. /**
  430. * Constant for <tt>data</tt> name that is used to hold the <tt>current data</tt>:
  431. * this name will be used for the argument name of generated/compiled Functions, and in the Function code block
  432. * appropriate getter/setter expression will be inserted.
  433. *
  434. * @memberOf mmir.parser.Element
  435. * @constant
  436. * @type String
  437. * @public
  438. */
  439. DATA_NAME : '__$$DATA$$__',
  440. /**
  441. * Constant for the name of the reserved <tt>data</tt> variable: the optional data argument is passed in
  442. * into rendering-calls for views, layouts etc. (see PresentationManager)
  443. *
  444. * @memberOf mmir.parser.Element
  445. * @constant
  446. * @type String
  447. * @public
  448. */
  449. DATA_ARGUMENT_NAME : '@data',
  450. /**
  451. * Constant for the name of the reserved <tt>argument</tt> variable: some template expressions
  452. * have an (optional) <tt>argument</tt> argument, which can be accessed using the variable name
  453. * within the template expressions inner content-/code-blocks.
  454. *
  455. * @memberOf mmir.parser.Element
  456. * @constant
  457. * @type String
  458. * @public
  459. */
  460. ARGUMENT_ARGUMENT_NAME : '@argument'
  461. }//END element: {...
  462. };//END: parser: {...
  463. return parser;
  464. });