logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

css.lua (12336B)


  1. -- Copyright 2006-2024 Mitchell. See LICENSE.
  2. -- CSS LPeg lexer.
  3. local lexer = lexer
  4. local P, S, B = lpeg.P, lpeg.S, lpeg.B
  5. local lex = lexer.new(..., {no_user_word_lists = true})
  6. -- Tags.
  7. local sel_prefix = B(S('#.'))
  8. local sel_suffix = lexer.space^0 * S('!>+.,:[{')
  9. lex:add_rule('tag', -sel_prefix * lex:tag(lexer.TAG, lex:word_match(lexer.TAG) * #sel_suffix))
  10. -- Properties.
  11. lex:add_rule('property', lex:tag('property', lex:word_match('property')) * #P(':'))
  12. -- Values.
  13. lex:add_rule('value',
  14. -sel_prefix * lex:tag(lexer.CONSTANT_BUILTIN, lex:word_match('value')) * -sel_suffix)
  15. -- Functions.
  16. lex:add_rule('function', lex:tag(lexer.FUNCTION_BUILTIN, lex:word_match(lexer.FUNCTION_BUILTIN)))
  17. -- Colors.
  18. local color_name = lex:tag(lexer.CONSTANT_BUILTIN, lex:word_match('color'))
  19. local xdigit = lexer.xdigit
  20. local color_value = lex:tag(lexer.NUMBER,
  21. '#' * xdigit * xdigit * xdigit * (xdigit * xdigit * xdigit)^-1)
  22. lex:add_rule('color', color_name + color_value)
  23. -- Identifiers.
  24. lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.alpha * (lexer.alnum + S('_-'))^0))
  25. -- Pseudo classes and pseudo elements.
  26. lex:add_rule('pseudoclass', ':' * lex:tag('pseudoclass', lex:word_match('pseudoclass')))
  27. lex:add_rule('pseudoelement', '::' * lex:tag('pseudoelement', lex:word_match('pseudoelement')))
  28. -- Strings.
  29. local sq_str = lexer.range("'")
  30. local dq_str = lexer.range('"')
  31. lex:add_rule('string', lex:tag(lexer.STRING, sq_str + dq_str))
  32. -- Comments.
  33. lex:add_rule('comment', lex:tag(lexer.COMMENT, lexer.range('/*', '*/')))
  34. -- Numbers.
  35. local unit = lex:word_match('unit') + '%'
  36. lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number * unit^-1))
  37. -- Operators.
  38. lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('~!#*>+=|.,:;()[]{}')))
  39. -- At rule.
  40. lex:add_rule('at_rule', lex:tag(lexer.PREPROCESSOR, '@' * lex:word_match('at_rule')))
  41. -- Fold points.
  42. lex:add_fold_point(lexer.OPERATOR, '{', '}')
  43. lex:add_fold_point(lexer.COMMENT, '/*', '*/')
  44. -- Word lists.
  45. lex:set_word_list(lexer.TAG, {
  46. 'a', 'abbr', 'address', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'blockquote', 'body',
  47. 'button', 'canvas', 'caption', 'cite', 'code', 'colgroup', 'content', 'data', 'datalist', 'dd',
  48. 'decorator', 'del', 'details', 'dfn', 'div', 'dl', 'dt', 'element', 'em', 'fieldset',
  49. 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header',
  50. 'html', 'i', 'iframe', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'menu',
  51. 'menuitem', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p',
  52. 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'shadow',
  53. 'small', 'spacer', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td',
  54. 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'u', 'ul', 'var', 'video', --
  55. 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta',
  56. 'param', 'source', 'track', 'wbr'
  57. })
  58. lex:set_word_list('property', {
  59. -- CSS 1.
  60. 'color', 'background-color', 'background-image', 'background-repeat', 'background-attachment',
  61. 'background-position', 'background', 'font-family', 'font-style', 'font-variant', 'font-weight',
  62. 'font-size', 'font', 'word-spacing', 'letter-spacing', 'text-decoration', 'vertical-align',
  63. 'text-transform', 'text-align', 'text-indent', 'line-height', 'margin-top', 'margin-right',
  64. 'margin-bottom', 'margin-left', 'margin', 'padding-top', 'padding-right', 'padding-bottom',
  65. 'padding-left', 'padding', 'border-top-width', 'border-right-width', 'border-bottom-width',
  66. 'border-left-width', 'border-width', 'border-top', 'border-right', 'border-bottom', 'border-left',
  67. 'border', 'border-color', 'border-style', 'width', 'height', 'float', 'clear', 'display',
  68. 'white-space', 'list-style-type', 'list-style-image', 'list-style-position', 'list-style',
  69. -- CSS 2.
  70. 'border-top-color', 'border-right-color', 'border-bottom-color', 'border-left-color',
  71. 'border-color', 'border-top-style', 'border-right-style', 'border-bottom-style',
  72. 'border-left-style', 'border-style', 'top', 'right', 'bottom', 'left', 'position', 'z-index',
  73. 'direction', 'unicode-bidi', 'min-width', 'max-width', 'min-height', 'max-height', 'overflow',
  74. 'clip', 'visibility', 'content', 'quotes', 'counter-reset', 'counter-increment', 'marker-offset',
  75. 'size', 'marks', 'page-break-before', 'page-break-after', 'page-break-inside', 'page', 'orphans',
  76. 'widows', 'font-stretch', 'font-size-adjust', 'unicode-range', 'units-per-em', 'src', 'panose-1',
  77. 'stemv', 'stemh', 'slope', 'cap-height', 'x-height', 'ascent', 'descent', 'widths', 'bbox',
  78. 'definition-src', 'baseline', 'centerline', 'mathline', 'topline', 'text-shadow', 'caption-side',
  79. 'table-layout', 'border-collapse', 'border-spacing', 'empty-cells', 'speak-header', 'cursor',
  80. 'outline', 'outline-width', 'outline-style', 'outline-color', 'volume', 'speak', 'pause-before',
  81. 'pause-after', 'pause', 'cue-before', 'cue-after', 'cue', 'play-during', 'azimuth', 'elevation',
  82. 'speech-rate', 'voice-family', 'pitch', 'pitch-range', 'stress', 'richness', 'speak-punctuation',
  83. 'speak-numeral',
  84. -- CSS 3.
  85. 'flex', 'flex-basis', 'flex-direction', 'flex-flow', 'flex-grow', 'flex-shrink', 'flex-wrap',
  86. 'align-content', 'align-items', 'align-self', 'justify-content', 'order', 'border-radius',
  87. 'transition', 'transform', 'box-shadow', 'filter', 'opacity', 'resize', 'word-break', 'word-wrap',
  88. 'box-sizing', 'animation', 'text-overflow'
  89. })
  90. lex:set_word_list('value', {
  91. -- CSS 1.
  92. 'auto', 'none', 'normal', 'italic', 'oblique', 'small-caps', 'bold', 'bolder', 'lighter',
  93. 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large', 'larger', 'smaller',
  94. 'transparent', 'repeat', 'repeat-x', 'repeat-y', 'no-repeat', 'scroll', 'fixed', 'top', 'bottom',
  95. 'left', 'center', 'right', 'justify', 'both', 'underline', 'overline', 'line-through', 'blink',
  96. 'baseline', 'sub', 'super', 'text-top', 'middle', 'text-bottom', 'capitalize', 'uppercase',
  97. 'lowercase', 'thin', 'medium', 'thick', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge',
  98. 'inset', 'outset', 'block', 'inline', 'list-item', 'pre', 'no-wrap', 'inside', 'outside', 'disc',
  99. 'circle', 'square', 'decimal', 'lower-roman', 'upper-roman', 'lower-alpha', 'upper-alpha', 'aqua',
  100. 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime', 'maroon', 'navy', 'olive', 'purple', 'red',
  101. 'silver', 'teal', 'white', 'yellow',
  102. -- CSS 2.
  103. 'inherit', 'run-in', 'compact', 'marker', 'table', 'inline-table', 'table-row-group',
  104. 'table-header-group', 'table-footer-group', 'table-row', 'table-column-group', 'table-column',
  105. 'table-cell', 'table-caption', 'static', 'relative', 'absolute', 'fixed', 'ltr', 'rtl', 'embed',
  106. 'bidi-override', 'visible', 'hidden', 'scroll', 'collapse', 'open-quote', 'close-quote',
  107. 'no-open-quote', 'no-close-quote', 'decimal-leading-zero', 'lower-greek', 'lower-latin',
  108. 'upper-latin', 'hebrew', 'armenian', 'georgian', 'cjk-ideographic', 'hiragana', 'katakana',
  109. 'hiragana-iroha', 'katakana-iroha', 'landscape', 'portrait', 'crop', 'cross', 'always', 'avoid',
  110. 'wider', 'narrower', 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed',
  111. 'semi-expanded', 'expanded', 'extra-expanded', 'ultra-expanded', 'caption', 'icon', 'menu',
  112. 'message-box', 'small-caption', 'status-bar', 'separate', 'show', 'hide', 'once', 'crosshair',
  113. 'default', 'pointer', 'move', 'text', 'wait', 'help', 'e-resize', 'ne-resize', 'nw-resize',
  114. 'n-resize', 'se-resize', 'sw-resize', 's-resize', 'w-resize', 'ActiveBorder', 'ActiveCaption',
  115. 'AppWorkspace', 'Background', 'ButtonFace', 'ButtonHighlight', 'ButtonShadow',
  116. 'InactiveCaptionText', 'ButtonText', 'CaptionText', 'GrayText', 'Highlight', 'HighlightText',
  117. 'InactiveBorder', 'InactiveCaption', 'InfoBackground', 'InfoText', 'Menu', 'MenuText',
  118. 'Scrollbar', 'ThreeDDarkShadow', 'ThreeDFace', 'ThreeDHighlight', 'ThreeDLightShadow',
  119. 'ThreeDShadow', 'Window', 'WindowFrame', 'WindowText', 'silent', 'x-soft', 'soft', 'medium',
  120. 'loud', 'x-loud', 'spell-out', 'mix', 'left-side', 'far-left', 'center-left', 'center-right',
  121. 'far-right', 'right-side', 'behind', 'leftwards', 'rightwards', 'below', 'level', 'above',
  122. 'higher', 'lower', 'x-slow', 'slow', 'medium', 'fast', 'x-fast', 'faster', 'slower', 'male',
  123. 'female', 'child', 'x-low', 'low', 'high', 'x-high', 'code', 'digits', 'continous',
  124. -- CSS 3.
  125. 'flex', 'row', 'column', 'ellipsis', 'inline-block'
  126. })
  127. lex:set_word_list(lexer.FUNCTION_BUILTIN, {
  128. 'attr', 'blackness', 'blend', 'blenda', 'blur', 'brightness', 'calc', 'circle', 'color-mod',
  129. 'contrast', 'counter', 'cubic-bezier', 'device-cmyk', 'drop-shadow', 'ellipse', 'gray',
  130. 'grayscale', 'hsl', 'hsla', 'hue', 'hue-rotate', 'hwb', 'image', 'inset', 'invert', 'lightness',
  131. 'linear-gradient', 'matrix', 'matrix3d', 'opacity', 'perspective', 'polygon', 'radial-gradient',
  132. 'rect', 'repeating-linear-gradient', 'repeating-radial-gradient', 'rgb', 'rgba', 'rotate',
  133. 'rotate3d', 'rotateX', 'rotateY', 'rotateZ', 'saturate', 'saturation', 'scale', 'scale3d',
  134. 'scaleX', 'scaleY', 'scaleZ', 'sepia', 'shade', 'skewX', 'skewY', 'steps', 'tint', 'toggle',
  135. 'translate', 'translate3d', 'translateX', 'translateY', 'translateZ', 'url', 'whiteness', 'var'
  136. })
  137. lex:set_word_list('color', {
  138. 'aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black',
  139. 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse',
  140. 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan',
  141. 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta',
  142. 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen',
  143. 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink',
  144. 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen',
  145. 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'grey',
  146. 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush',
  147. 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow',
  148. 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen',
  149. 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'lime',
  150. 'limegreen', 'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid',
  151. 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise',
  152. 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'navy',
  153. 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod', 'palegreen',
  154. 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue',
  155. 'purple', 'rebeccapurple', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown',
  156. 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray', 'slategrey',
  157. 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'transparent',
  158. 'turquoise', 'violet', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen'
  159. })
  160. lex:set_word_list('pseudoclass', {
  161. 'active', 'checked', 'disabled', 'empty', 'enabled', 'first-child', 'first-of-type', 'focus',
  162. 'hover', 'in-range', 'invalid', 'lang', 'last-child', 'last-of-type', 'link', 'not', 'nth-child',
  163. 'nth-last-child', 'nth-last-of-type', 'nth-of-type', 'only-of-type', 'only-child', 'optional',
  164. 'out-of-range', 'read-only', 'read-write', 'required', 'root', 'target', 'valid', 'visited'
  165. })
  166. lex:set_word_list('pseudoelement', 'after before first-letter first-line selection')
  167. lex:set_word_list('unit', {
  168. 'ch', 'cm', 'deg', 'dpcm', 'dpi', 'dppx', 'em', 'ex', 'grad', 'Hz', 'in', 'kHz', 'mm', 'ms', 'pc',
  169. 'pt', 'px', 'q', 'rad', 'rem', 's', 'turn', 'vh', 'vmax', 'vmin', 'vw'
  170. })
  171. lex:set_word_list('at_rule', 'charset font-face media page import namespace keyframes')
  172. lexer.property['scintillua.comment'] = '/*|*/'
  173. lexer.property['scintillua.word.chars'] =
  174. 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-'
  175. return lex