@@ -11,6 +11,8 @@ class CSS < RegexLexer
1111 filenames '*.css'
1212 mimetypes 'text/css'
1313
14+ lazy { require_relative 'css/builtins' }
15+
1416 # Documentation: https://www.w3.org/TR/CSS21/syndata.html#characters
1517
1618 # [jneen] workaround for:
@@ -28,211 +30,11 @@ class CSS < RegexLexer
2830
2931 number = /-?(?:[0-9]+(\. [0-9]+)?|\. [0-9]+)/
3032
31- def self . properties
32- @properties ||= Set . new %w(
33- additive-symbols align-content align-items align-self
34- alignment-adjust alignment-baseline all anchor-point animation
35- animation-composition animation-delay animation-direction
36- animation-duration animation-fill-mode animation-iteration-count
37- animation-name animation-play-state animation-timing-function
38- appearance aspect-ratio azimuth backface-visibility background
39- background-attachment background-blend-mode
40- background-clip background-color background-image
41- background-origin background-position
42- background-repeat background-size baseline-shift
43- binding bleed bookmark-label bookmark-level bookmark-state
44- bookmark-target border border-bottom border-bottom-color
45- border-bottom-left-radius border-bottom-right-radius
46- border-bottom-style border-bottom-width border-collapse
47- border-color border-image border-image-outset border-image-repeat
48- border-image-slice border-image-source border-image-width
49- border-left border-left-color border-left-style border-left-width
50- border-radius border-right border-right-color border-right-style
51- border-right-width border-spacing border-style border-top
52- border-top-color border-top-left-radius border-top-right-radius
53- border-top-style border-top-width border-width bottom box-align
54- box-decoration-break box-direction box-flex box-flex-group
55- box-lines box-ordinal-group box-orient box-pack box-shadow
56- box-sizing break-after break-before break-inside caption-side
57- clear clip clip-path clip-rule color color-profile column-count
58- column-fill column-gap column-rule column-rule-color
59- column-rule-style column-rule-width column-span column-width
60- columns content container container-name container-type
61- counter-increment counter-reset counter-set crop cue
62- cue-after cue-before cursor direction display dominant-baseline
63- drop-initial-after-adjust drop-initial-after-align
64- drop-initial-before-adjust drop-initial-before-align
65- drop-initial-size drop-initial-value elevation empty-cells fallback
66- filter fit fit-position flex flex-basis flex-direction flex-flow
67- flex-grow flex-shrink flex-wrap float float-offset font
68- font-display font-family font-feature-settings font-kerning
69- font-language-override font-size font-size-adjust font-stretch
70- font-style font-synthesis font-variant font-variant-alternates
71- font-variant-caps font-variant-east-asian font-variant-ligatures
72- font-variant-numeric font-variant-position font-weight gap
73- grid-area grid-auto-columns grid-auto-flow grid-auto-rows
74- grid-column grid-column-end grid-column-start grid-row
75- grid-row-end grid-row-start grid-template grid-template-areas
76- grid-template-columns grid-template-rows hanging-punctuation
77- height hyphenate-after hyphenate-before hyphenate-character
78- hyphenate-lines hyphenate-resource hyphens icon image-orientation
79- image-rendering image-resolution ime-mode inherits initial-value
80- inline-box-align inset isolation justify-content justify-items
81- justify-self left letter-spacing line-break line-height
82- line-stacking line-stacking-ruby line-stacking-shift
83- line-stacking-strategy list-style list-style-image
84- list-style-position list-style-type margin margin-bottom
85- margin-left margin-right margin-top mark mark-after mark-before
86- marker-offset marks marquee-direction marquee-loop
87- marquee-play-count marquee-speed marquee-style
88- mask mask-clip mask-composite mask-image mask-mode
89- mask-origin mask-position mask-repeat mask-size mask-type
90- max-height max-width min-height min-width mix-blend-mode
91- move-to nav-down nav-index nav-left nav-right nav-up negative
92- object-fit object-position offset offset-anchor offset-distance
93- offset-path offset-position offset-rotate opacity order orphans
94- outline outline-color outline-offset outline-style outline-width
95- overflow overflow-style overflow-wrap overflow-x overflow-y pad
96- padding padding-bottom padding-left padding-right padding-top page
97- page-break-after page-break-before page-break-inside page-policy
98- pause pause-after pause-before perspective perspective-origin
99- phonemes pitch pitch-range place-content place-items place-self
100- play-during pointer-events position prefix presentation-level
101- punctuation-trim quotes range rendering-intent resize rest
102- rest-after rest-before richness right rotate rotation rotation-point
103- row-gap ruby-align ruby-overhang ruby-position ruby-span scale
104- scroll-behavior scroll-margin scroll-margin-block
105- scroll-margin-block-end scroll-margin-block-start
106- scroll-margin-bottom scroll-margin-inline scroll-margin-inline-end
107- scroll-margin-inline-start scroll-margin-left scroll-margin-right
108- scroll-margin-top scroll-padding-top scroll-padding-right
109- scroll-padding-bottom scroll-padding-left scroll-padding
110- scroll-padding-block-end scroll-padding-block-start
111- scroll-padding-block scroll-padding-inline-end
112- scroll-padding-inline-start scroll-padding-inline
113- scroll-snap-type scroll-snap-align scroll-snap-stop
114- shape-outside shape-margin shape-image-threshold shape-rendering
115- size speak speak-as speak-header speak-numeral speak-punctuation
116- speech-rate src stress string-set suffix symbols syntax system
117- tab-size table-layout target target-name target-new target-position
118- text-align text-align-last text-combine-horizontal
119- text-decoration text-decoration-color text-decoration-line
120- text-decoration-skip text-decoration-style text-emphasis
121- text-emphasis-color text-emphasis-position text-emphasis-style
122- text-height text-indent text-justify text-orientation
123- text-outline text-overflow text-rendering text-shadow
124- text-space-collapse text-transform text-underline-position
125- text-wrap top transform transform-origin transform-style
126- transition transition-delay transition-duration
127- transition-property transition-timing-function translate
128- unicode-bidi vertical-align visibility voice-balance
129- voice-duration voice-family voice-pitch voice-pitch-range
130- voice-range voice-rate voice-stress voice-volume volume
131- white-space widows width word-break word-spacing word-wrap
132- writing-mode z-index
133- )
134- end
135-
136- def self . builtins
137- @builtins ||= Set . new %w(
138- above absolute accumulate add additive all alpha alphabetic
139- alternate alternate-reverse always armenian aural auto auto-fill
140- auto-fit avoid backwards balance baseline behind below bidi-override
141- blink block bold bolder border-box both bottom break-spaces
142- capitalize center center-left center-right circle cjk-ideographic
143- close-quote closest-corner closest-side collapse
144- color color-burn color-dodge column column-reverse
145- condensed contain content content-box continuous cover crop cross
146- crosshair cursive cyclic darken dashed decimal decimal-leading-zero
147- default difference digits disc dotted double e-resize
148- ease ease-in ease-in-out ease-out embed end exclude exclusion
149- expanded extends extra-condensed extra-expanded fantasy
150- farthest-corner farthest-side far-left far-right
151- fast faster fill fixed flat flex flex-end flex-start
152- forwards georgian grid groove hard-light hebrew help hidden
153- hide high higher hiragana hiragana-iroha horizontal hue icon
154- infinite inherit inline inline-block inline-flex inline-grid
155- inline-size inline-table inset inside intersect isolate italic
156- justify katakana katakana-iroha landscape large larger left
157- left-side leftwards level lighten lighter line-through linear
158- list-item loud low lower lower-alpha lower-greek lower-roman
159- lowercase ltr luminance luminosity mandatory match-source medium
160- message-box middle mix monospace multiply n-resize narrower
161- ne-resize no-close-quote no-open-quote no-repeat none normal
162- nowrap numeric nw-resize oblique once open-quote outset outside
163- overlay overline paused pointer portrait pre preserve-3d pre-line
164- pre-wrap proximity px relative repeat-x repeat-y replace reverse
165- ridge right right-side rightwards row row-reverse rtl running
166- s-resize sans-serif saturation scale-down screen scroll
167- se-resize semi-condensed semi-expanded separate serif show
168- sides silent size slow slower small-caps small-caption smaller
169- smooth soft soft-light solid space-around space-between
170- space-evenly span spell-out square start static status-bar sticky
171- stretch sub subtract super sw-resize swap symbolic table
172- table-caption table-cell table-column table-column-group
173- table-footer-group table-header-group table-row table-row-group
174- text text-bottom text-top thick thin top transparent
175- ultra-condensed ultra-expanded underline upper-alpha upper-latin
176- upper-roman uppercase vertical visible w-resize wait wider wrap
177- wrap-reverse x x-fast x-high x-large x-loud x-low x-small x-soft
178- xx-large xx-small yes y z
179- )
180- end
181-
182- def self . colors
183- @colors ||= Set . new %w(
184- aliceblue antiquewhite aqua aquamarine azure beige bisque black
185- blanchedalmond blue blueviolet brown burlywood cadetblue
186- chartreuse chocolate coral cornflowerblue cornsilk crimson cyan
187- darkblue darkcyan darkgoldenrod darkgray darkgreen darkkhaki
188- darkmagenta darkolivegreen darkorange darkorchid darkred
189- darksalmon darkseagreen darkslateblue darkslategray darkturquoise
190- darkviolet deeppink deepskyblue dimgray dodgerblue firebrick
191- floralwhite forestgreen fuchsia gainsboro ghostwhite gold
192- goldenrod gray green greenyellow honeydew hotpink indianred
193- indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon
194- lightblue lightcoral lightcyan lightgoldenrodyellow lightgreen
195- lightgrey lightpink lightsalmon lightseagreen lightskyblue
196- lightslategray lightsteelblue lightyellow lime limegreen linen
197- magenta maroon mediumaquamarine mediumblue mediumorchid
198- mediumpurple mediumseagreen mediumslateblue mediumspringgreen
199- mediumturquoise mediumvioletred midnightblue mintcream mistyrose
200- moccasin navajowhite navy oldlace olive olivedrab orange
201- orangered orchid palegoldenrod palegreen paleturquoise
202- palevioletred papayawhip peachpuff peru pink plum powderblue
203- purple red rosybrown royalblue saddlebrown salmon sandybrown
204- seagreen seashell sienna silver skyblue slateblue slategray snow
205- springgreen steelblue tan teal thistle tomato
206- turquoise violet wheat white whitesmoke yellow yellowgreen
207- rebeccapurple
208- )
209- end
210-
211- def self . functions
212- @functions ||= Set . new %w(
213- abs acos annotation asin atan atan2 attr blur brightness calc
214- character-variant circle clamp color color-mix conic-gradient
215- contrast cos counter counters cubic-bezier drop-shadow ellipse
216- env exp fit-content format grayscale hsl hsla hue-rotate hwb hypot
217- image-set inset invert lab lch linear linear-gradient log matrix
218- matrix3d max min minmax mod oklab oklch opacity ornaments path
219- perspective polygon pow radial-gradient ray rect rem repeat
220- repeating-conic-gradient repeating-linear-gradient
221- repeating-radial-gradient rgb rgba rotate rotate3d rotatex
222- rotatey rotatez round saturate scale scale3d scalex scaley scalez
223- sepia sign sin skewx skewy sqrt steps styleset
224- stylistic swash tan translate translate3d translatex translatey
225- translatez url var xywh
226- )
227- end
228-
22933 # source: http://www.w3.org/TR/CSS21/syndata.html#vendor-keyword-history
230- def self . vendor_prefixes
231- @vendor_prefixes ||= Set . new %w(
232- -ah- -atsc- -hp- -khtml- -moz- -ms- -o- -rim- -ro- -tc- -wap-
233- -webkit- -xv- mso- prince-
234- )
235- end
34+ VENDOR_PREFIXES = %w(
35+ -ah- -atsc- -hp- -khtml- -moz- -ms- -o- -rim- -ro- -tc- -wap-
36+ -webkit- -xv- mso- prince-
37+ )
23638
23739 state :root do
23840 mixin :basics
@@ -262,16 +64,13 @@ def self.vendor_prefixes
26264 groups Name ::Function , Punctuation , Str ::Other , Punctuation
26365 end
26466
265- rule ( identifier ) do |m |
266- if self . class . colors . include? m [ 0 ] . downcase
267- token Name ::Other
268- elsif self . class . builtins . include? m [ 0 ] . downcase
269- token Name ::Builtin
270- elsif self . class . functions . include? m [ 0 ] . downcase
271- token Name ::Function
272- else
273- token Name
274- end
67+ keywords identifier do
68+ transform ( &:downcase )
69+
70+ rule COLORS , Name ::Other
71+ rule BUILTINS , Name ::Builtin
72+ rule FUNCTIONS , Name ::Function
73+ default Name
27574 end
27675 end
27776
@@ -308,10 +107,11 @@ def self.vendor_prefixes
308107 state :stanza do
309108 mixin :basics
310109 rule %r/}/ , Punctuation , :pop!
110+
311111 rule %r/(#{ identifier } )(\s *)(:)/m do |m |
312- name_tok = if self . class . properties . include? m [ 1 ]
112+ name_tok = if PROPERTIES . include? m [ 1 ]
313113 Name ::Label
314- elsif self . class . vendor_prefixes . any? { |p | m [ 1 ] . start_with? ( p ) }
114+ elsif VENDOR_PREFIXES . any? { |p | m [ 1 ] . start_with? ( p ) }
315115 Name ::Label
316116 else
317117 Name ::Property
0 commit comments