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.

parser.jison 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* description: Parses expressions. */
  2. %options case-insensitive
  3. /* lexical grammar */
  4. %lex
  5. %%
  6. \s+ /* skip whitespace */
  7. (\-(webkit|moz)\-)?calc\b return 'CALC';
  8. [a-z][a-z0-9-]*\s*\((?:(?:\"(?:\\.|[^\"\\])*\"|\'(?:\\.|[^\'\\])*\')|\([^)]*\)|[^\(\)]*)*\) return 'FUNCTION';
  9. "*" return 'MUL';
  10. "/" return 'DIV';
  11. "+" return 'ADD';
  12. "-" return 'SUB';
  13. ([0-9]+("."[0-9]+)?|"."[0-9]+)em\b return 'LENGTH'; // em
  14. ([0-9]+("."[0-9]+)?|"."[0-9]+)ex\b return 'LENGTH'; // ex
  15. ([0-9]+("."[0-9]+)?|"."[0-9]+)ch\b return 'LENGTH'; // ch
  16. ([0-9]+("."[0-9]+)?|"."[0-9]+)rem\b return 'LENGTH'; // rem
  17. ([0-9]+("."[0-9]+)?|"."[0-9]+)vw\b return 'LENGTH'; // vw
  18. ([0-9]+("."[0-9]+)?|"."[0-9]+)vh\b return 'LENGTH'; // vh
  19. ([0-9]+("."[0-9]+)?|"."[0-9]+)vmin\b return 'LENGTH'; // vmin
  20. ([0-9]+("."[0-9]+)?|"."[0-9]+)vmax\b return 'LENGTH'; // vmax
  21. ([0-9]+("."[0-9]+)?|"."[0-9]+)vm\b return 'LENGTH'; // vm (non-standard name)
  22. ([0-9]+("."[0-9]+)?|"."[0-9]+)px\b return 'LENGTH'; // px
  23. ([0-9]+("."[0-9]+)?|"."[0-9]+)mm\b return 'LENGTH'; // mm
  24. ([0-9]+("."[0-9]+)?|"."[0-9]+)cm\b return 'LENGTH'; // cm
  25. ([0-9]+("."[0-9]+)?|"."[0-9]+)in\b return 'LENGTH'; // in
  26. ([0-9]+("."[0-9]+)?|"."[0-9]+)pt\b return 'LENGTH'; // pt
  27. ([0-9]+("."[0-9]+)?|"."[0-9]+)pc\b return 'LENGTH'; // pc
  28. ([0-9]+("."[0-9]+)?|"."[0-9]+)Q\b return 'LENGTH'; // Q
  29. ([0-9]+("."[0-9]+)?|"."[0-9]+)fr\b return 'LENGTH'; // fr
  30. ([0-9]+("."[0-9]+)?|"."[0-9]+)deg\b return 'ANGLE'; // deg
  31. ([0-9]+("."[0-9]+)?|"."[0-9]+)grad\b return 'ANGLE'; // grad
  32. ([0-9]+("."[0-9]+)?|"."[0-9]+)turn\b return 'ANGLE'; // turn
  33. ([0-9]+("."[0-9]+)?|"."[0-9]+)rad\b return 'ANGLE'; // rad
  34. ([0-9]+("."[0-9]+)?|"."[0-9]+)s\b return 'TIME'; // s
  35. ([0-9]+("."[0-9]+)?|"."[0-9]+)ms\b return 'TIME'; // ms
  36. ([0-9]+("."[0-9]+)?|"."[0-9]+)Hz\b return 'FREQ'; // Hz
  37. ([0-9]+("."[0-9]+)?|"."[0-9]+)kHz\b return 'FREQ'; // kHz
  38. ([0-9]+("."[0-9]+)?|"."[0-9]+)dpi\b return 'RES'; // dpi
  39. ([0-9]+("."[0-9]+)?|"."[0-9]+)dpcm\b return 'RES'; // dpcm
  40. ([0-9]+("."[0-9]+)?|"."[0-9]+)dppx\b return 'RES'; // dppm
  41. ([0-9]+("."[0-9]+)?|"."[0-9]+)\% return 'PERCENTAGE';
  42. ([0-9]+("."[0-9]+)?|"."[0-9]+)\b return 'NUMBER';
  43. "(" return 'LPAREN';
  44. ")" return 'RPAREN';
  45. #\{([\s\S]*?)\} return 'UNKNOWN'; // scss interpolation
  46. @\{([\s\S]*?)\} return 'UNKNOWN'; // less interpolation
  47. \S[^\s()*/+-]* return 'UNKNOWN';
  48. <<EOF>> return 'EOF';
  49. /lex
  50. %left ADD SUB
  51. %left MUL DIV
  52. %left UPREC
  53. %start expression
  54. %%
  55. expression
  56. : math_expression EOF { return $1; }
  57. ;
  58. math_expression
  59. : CALC LPAREN math_expression RPAREN {
  60. $$ = $3;
  61. $$.source.start = { index: @1.range[0] };
  62. $$.source.end = { index: @4.range[1] };
  63. }
  64. | math_expression ADD math_expression {
  65. $$ = {
  66. type: 'MathExpression', operator: $2, left: $1, right: $3,
  67. source: {
  68. start: $1.source.start, end: $3.source.end,
  69. operator: { start: { index: @2.range[0] }, end: { index: @2.range[1] } }
  70. }
  71. };
  72. }
  73. | math_expression SUB math_expression {
  74. $$ = {
  75. type: 'MathExpression', operator: $2, left: $1, right: $3,
  76. source: {
  77. start: $1.source.start, end: $3.source.end,
  78. operator: { start: { index: @2.range[0] }, end: { index: @2.range[1] } }
  79. }
  80. };
  81. }
  82. | math_expression MUL math_expression {
  83. $$ = {
  84. type: 'MathExpression', operator: $2, left: $1, right: $3,
  85. source: {
  86. start: $1.source.start, end: $3.source.end,
  87. operator: { start: { index: @2.range[0] }, end: { index: @2.range[1] } }
  88. }
  89. };
  90. }
  91. | math_expression DIV math_expression {
  92. $$ = {
  93. type: 'MathExpression', operator: $2, left: $1, right: $3,
  94. source: {
  95. start: $1.source.start, end: $3.source.end,
  96. operator: { start: { index: @2.range[0] }, end: { index: @2.range[1] } }
  97. }
  98. };
  99. }
  100. | SUB math_expression %prec UPREC {
  101. if (@1.range[1] !== $2.source.start.index) {
  102. throw new Error('Unexpected spaces was found between sign and value');
  103. }
  104. if (typeof $2.value !== 'number') {
  105. throw new Error('Unexpected sign');
  106. }
  107. if ($2.sign) {
  108. throw new Error('Unexpected continuous sign');
  109. }
  110. $$ = $2;
  111. $$.sign = '-'
  112. $$.value = -$2.value;
  113. $$.source.start.index = @1.range[0];
  114. }
  115. | ADD math_expression %prec UPREC {
  116. if (@1.range[1] !== $2.source.start.index) {
  117. throw new Error('Unexpected spaces was found between sign and value');
  118. }
  119. if (typeof $2.value !== 'number') {
  120. throw new Error('Unexpected sign');
  121. }
  122. if ($2.sign) {
  123. throw new Error('Unexpected continuous sign');
  124. }
  125. $$ = $2;
  126. $$.sign = '+'
  127. $$.source.start.index = @1.range[0];
  128. }
  129. | LPAREN math_expression RPAREN {
  130. $$ = $2;
  131. $$.source.start = { index: @1.range[0] };
  132. $$.source.end = { index: @3.range[1] };
  133. }
  134. | function { $$ = $1; }
  135. | css_value { $$ = $1; }
  136. | value { $$ = $1; }
  137. ;
  138. value
  139. : NUMBER { $$ = { type: 'Value', value: parseFloat($1), source: { start: { index: @1.range[0] }, end: { index: @1.range[1] } } }; }
  140. ;
  141. function
  142. : FUNCTION { $$ = { type: 'Function', value: $1, source: { start: { index: @1.range[0] }, end: { index: @1.range[1] } } }; }
  143. ;
  144. css_value
  145. : LENGTH { $$ = { type: 'LengthValue', value: parseFloat($1), unit: /[a-z]+/i.exec($1)[0], source: { start: { index: @1.range[0] }, end: { index: @1.range[1] } } }; }
  146. | ANGLE { $$ = { type: 'AngleValue', value: parseFloat($1), unit: /[a-z]+/i.exec($1)[0], source: { start: { index: @1.range[0] }, end: { index: @1.range[1] } } }; }
  147. | TIME { $$ = { type: 'TimeValue', value: parseFloat($1), unit: /[a-z]+/i.exec($1)[0], source: { start: { index: @1.range[0] }, end: { index: @1.range[1] } } }; }
  148. | FREQ { $$ = { type: 'FrequencyValue', value: parseFloat($1), unit: /[a-z]+/i.exec($1)[0], source: { start: { index: @1.range[0] }, end: { index: @1.range[1] } } }; }
  149. | RES { $$ = { type: 'ResolutionValue', value: parseFloat($1), unit: /[a-z]+/i.exec($1)[0], source: { start: { index: @1.range[0] }, end: { index: @1.range[1] } } }; }
  150. | PERCENTAGE { $$ = { type: 'PercentageValue', value: parseFloat($1), unit: '%', source: { start: { index: @1.range[0] }, end: { index: @1.range[1] } } }; }
  151. | UNKNOWN { $$ = { type: 'UnknownValue', value: $1, unit: '', source: { start: { index: @1.range[0] }, end: { index: @1.range[1] } } }; }
  152. ;