125 lines
14 KiB
Go
125 lines
14 KiB
Go
|
package s
|
||
|
|
||
|
import (
|
||
|
. "github.com/alecthomas/chroma" // nolint
|
||
|
"github.com/alecthomas/chroma/lexers/internal"
|
||
|
)
|
||
|
|
||
|
// Scss lexer.
|
||
|
var Scss = internal.Register(MustNewLexer(
|
||
|
&Config{
|
||
|
Name: "SCSS",
|
||
|
Aliases: []string{"scss"},
|
||
|
Filenames: []string{"*.scss"},
|
||
|
MimeTypes: []string{"text/x-scss"},
|
||
|
NotMultiline: true,
|
||
|
DotAll: true,
|
||
|
CaseInsensitive: true,
|
||
|
},
|
||
|
Rules{
|
||
|
"root": {
|
||
|
{`\s+`, Text, nil},
|
||
|
{`//.*?\n`, CommentSingle, nil},
|
||
|
{`/\*.*?\*/`, CommentMultiline, nil},
|
||
|
{`@import`, Keyword, Push("value")},
|
||
|
{`@for`, Keyword, Push("for")},
|
||
|
{`@(debug|warn|if|while)`, Keyword, Push("value")},
|
||
|
{`(@mixin)( [\w-]+)`, ByGroups(Keyword, NameFunction), Push("value")},
|
||
|
{`(@include)( [\w-]+)`, ByGroups(Keyword, NameDecorator), Push("value")},
|
||
|
{`@extend`, Keyword, Push("selector")},
|
||
|
{`(@media)(\s+)`, ByGroups(Keyword, Text), Push("value")},
|
||
|
{`@[\w-]+`, Keyword, Push("selector")},
|
||
|
{`(\$[\w-]*\w)([ \t]*:)`, ByGroups(NameVariable, Operator), Push("value")},
|
||
|
Default(Push("selector")),
|
||
|
},
|
||
|
"attr": {
|
||
|
{`[^\s:="\[]+`, NameAttribute, nil},
|
||
|
{`#\{`, LiteralStringInterpol, Push("interpolation")},
|
||
|
{`[ \t]*:`, Operator, Push("value")},
|
||
|
Default(Pop(1)),
|
||
|
},
|
||
|
"inline-comment": {
|
||
|
{`(\\#|#(?=[^{])|\*(?=[^/])|[^#*])+`, CommentMultiline, nil},
|
||
|
{`#\{`, LiteralStringInterpol, Push("interpolation")},
|
||
|
{`\*/`, Comment, Pop(1)},
|
||
|
},
|
||
|
"value": {
|
||
|
{`[ \t]+`, Text, nil},
|
||
|
{`[!$][\w-]+`, NameVariable, nil},
|
||
|
{`url\(`, LiteralStringOther, Push("string-url")},
|
||
|
{`[a-z_-][\w-]*(?=\()`, NameFunction, nil},
|
||
|
{Words(``, `\b`, `align-content`, `align-items`, `align-self`, `alignment-baseline`, `all`, `animation`, `animation-delay`, `animation-direction`, `animation-duration`, `animation-fill-mode`, `animation-iteration-count`, `animation-name`, `animation-play-state`, `animation-timing-function`, `appearance`, `azimuth`, `backface-visibility`, `background`, `background-attachment`, `background-blend-mode`, `background-clip`, `background-color`, `background-image`, `background-origin`, `background-position`, `background-repeat`, `background-size`, `baseline-shift`, `bookmark-label`, `bookmark-level`, `bookmark-state`, `border`, `border-bottom`, `border-bottom-color`, `border-bottom-left-radius`, `border-bottom-right-radius`, `border-bottom-style`, `border-bottom-width`, `border-boundary`, `border-collapse`, `border-color`, `border-image`, `border-image-outset`, `border-image-repeat`, `border-image-slice`, `border-image-source`, `border-image-width`, `border-left`, `border-left-color`, `border-left-style`, `border-left-width`, `border-radius`, `border-right`, `border-right-color`, `border-right-style`, `border-right-width`, `border-spacing`, `border-style`, `border-top`, `border-top-color`, `border-top-left-radius`, `border-top-right-radius`, `border-top-style`, `border-top-width`, `border-width`, `bottom`, `box-decoration-break`, `box-shadow`, `box-sizing`, `box-snap`, `box-suppress`, `break-after`, `break-before`, `break-inside`, `caption-side`, `caret`, `caret-animation`, `caret-color`, `caret-shape`, `chains`, `clear`, `clip`, `clip-path`, `clip-rule`, `color`, `color-interpolation-filters`, `column-count`, `column-fill`, `column-gap`, `column-rule`, `column-rule-color`, `column-rule-style`, `column-rule-width`, `column-span`, `column-width`, `columns`, `content`, `counter-increment`, `counter-reset`, `counter-set`, `crop`, `cue`, `cue-after`, `cue-before`, `cursor`, `direction`, `display`, `dominant-baseline`, `elevation`, `empty-cells`, `filter`, `flex`, `flex-basis`, `flex-direction`, `flex-flow`, `flex-grow`, `flex-shrink`, `flex-wrap`, `float`, `float-defer`, `float-offset`, `float-reference`, `flood-color`, `flood-opacity`, `flow`, `flow-from`, `flow-into`, `font`, `font-family`, `font-feature-settings`, `font-kerning`, `font-language-override`, `font-size`, `font-size-adjust`, `font-stretch`, `font-style`, `font-synthesis`, `font-variant`, `font-variant-alternates`, `font-variant-caps`, `font-variant-east-asian`, `font-variant-ligatures`, `font-variant-numeric`, `font-variant-position`, `font-weight`, `footnote-display`, `footnote-policy`, `glyph-orientation-vertical`, `grid`, `grid-area`, `grid-auto-columns`, `grid-auto-flow`, `grid-auto-rows`, `grid-column`, `grid-column-end`, `grid-column-gap`, `grid-column-start`, `grid-gap`, `grid-row`, `grid-row-end`, `grid-row-gap`, `grid-row-start`, `grid-template`, `grid-template-areas`, `grid-template-columns`, `grid-template-rows`, `hanging-punctuation`, `height`, `hyphenate-character`, `hyphenate-limit-chars`, `hyphenate-limit-last`, `hyphenate-limit-lines`, `hyphenate-limit-zone`, `hyphens`, `image-orientation`, `image-resolution`, `initial-letter`, `initial-letter-align`, `initial-letter-wrap`, `isolation`, `justify-content`, `justify-items`, `justify-self`, `left`, `letter-spacing`, `lighting-color`, `line-break`, `line-grid`, `line-height`, `line-snap`, `list-style`, `list-style-image`, `list-style-position`, `list-style-type`, `margin`, `margin-bottom`, `margin-left`, `margin-right`, `margin-top`, `marker-side`, `marquee-direction`, `marquee-loop`, `marquee-speed`, `marquee-style`, `mask`, `mask-border`, `mask-border-mode`, `mask-border-outset`, `mask-border-repeat`, `mask-border-slice`, `mask-border-source`, `mask-border-width`, `mask-clip`, `mask-composite`, `mask-image`, `mask-mode`, `mask-origin`, `mask-position`, `mask-repeat`, `mask-size`, `mask-type`, `max-height`, `max-lines`, `max-width`, `min-height`, `min-width`, `mix-blend-mode`, `motion`, `motion-offset`, `motion-path`, `motion-rotation`, `move-to`, `nav-down`, `nav-left`, `nav-right`, `nav-up`, `obje
|
||
|
{Words(``, `\b`, `aliceblue`, `antiquewhite`, `aqua`, `aquamarine`, `azure`, `beige`, `bisque`, `black`, `blanchedalmond`, `blue`, `blueviolet`, `brown`, `burlywood`, `cadetblue`, `chartreuse`, `chocolate`, `coral`, `cornflowerblue`, `cornsilk`, `crimson`, `cyan`, `darkblue`, `darkcyan`, `darkgoldenrod`, `darkgray`, `darkgreen`, `darkgrey`, `darkkhaki`, `darkmagenta`, `darkolivegreen`, `darkorange`, `darkorchid`, `darkred`, `darksalmon`, `darkseagreen`, `darkslateblue`, `darkslategray`, `darkslategrey`, `darkturquoise`, `darkviolet`, `deeppink`, `deepskyblue`, `dimgray`, `dimgrey`, `dodgerblue`, `firebrick`, `floralwhite`, `forestgreen`, `fuchsia`, `gainsboro`, `ghostwhite`, `gold`, `goldenrod`, `gray`, `green`, `greenyellow`, `grey`, `honeydew`, `hotpink`, `indianred`, `indigo`, `ivory`, `khaki`, `lavender`, `lavenderblush`, `lawngreen`, `lemonchiffon`, `lightblue`, `lightcoral`, `lightcyan`, `lightgoldenrodyellow`, `lightgray`, `lightgreen`, `lightgrey`, `lightpink`, `lightsalmon`, `lightseagreen`, `lightskyblue`, `lightslategray`, `lightslategrey`, `lightsteelblue`, `lightyellow`, `lime`, `limegreen`, `linen`, `magenta`, `maroon`, `mediumaquamarine`, `mediumblue`, `mediumorchid`, `mediumpurple`, `mediumseagreen`, `mediumslateblue`, `mediumspringgreen`, `mediumturquoise`, `mediumvioletred`, `midnightblue`, `mintcream`, `mistyrose`, `moccasin`, `navajowhite`, `navy`, `oldlace`, `olive`, `olivedrab`, `orange`, `orangered`, `orchid`, `palegoldenrod`, `palegreen`, `paleturquoise`, `palevioletred`, `papayawhip`, `peachpuff`, `peru`, `pink`, `plum`, `powderblue`, `purple`, `rebeccapurple`, `red`, `rosybrown`, `royalblue`, `saddlebrown`, `salmon`, `sandybrown`, `seagreen`, `seashell`, `sienna`, `silver`, `skyblue`, `slateblue`, `slategray`, `slategrey`, `snow`, `springgreen`, `steelblue`, `tan`, `teal`, `thistle`, `tomato`, `turquoise`, `violet`, `wheat`, `white`, `whitesmoke`, `yellow`, `yellowgreen`, `transparent`), NameEntity, nil},
|
||
|
{Words(``, `\b`, `black`, `silver`, `gray`, `white`, `maroon`, `red`, `purple`, `fuchsia`, `green`, `lime`, `olive`, `yellow`, `navy`, `blue`, `teal`, `aqua`), NameBuiltin, nil},
|
||
|
{`\!(important|default)`, NameException, nil},
|
||
|
{`(true|false)`, NamePseudo, nil},
|
||
|
{`(and|or|not)`, OperatorWord, nil},
|
||
|
{`/\*`, CommentMultiline, Push("inline-comment")},
|
||
|
{`//[^\n]*`, CommentSingle, nil},
|
||
|
{`\#[a-z0-9]{1,6}`, LiteralNumberHex, nil},
|
||
|
{`(-?\d+)(\%|[a-z]+)?`, ByGroups(LiteralNumberInteger, KeywordType), nil},
|
||
|
{`(-?\d*\.\d+)(\%|[a-z]+)?`, ByGroups(LiteralNumberFloat, KeywordType), nil},
|
||
|
{`#\{`, LiteralStringInterpol, Push("interpolation")},
|
||
|
{`[~^*!&%<>|+=@:,./?-]+`, Operator, nil},
|
||
|
{`[\[\]()]+`, Punctuation, nil},
|
||
|
{`"`, LiteralStringDouble, Push("string-double")},
|
||
|
{`'`, LiteralStringSingle, Push("string-single")},
|
||
|
{`[a-z_-][\w-]*`, Name, nil},
|
||
|
{`\n`, Text, nil},
|
||
|
{`[;{}]`, Punctuation, Pop(1)},
|
||
|
},
|
||
|
"interpolation": {
|
||
|
{`\}`, LiteralStringInterpol, Pop(1)},
|
||
|
Include("value"),
|
||
|
},
|
||
|
"selector": {
|
||
|
{`[ \t]+`, Text, nil},
|
||
|
{`\:`, NameDecorator, Push("pseudo-class")},
|
||
|
{`\.`, NameClass, Push("class")},
|
||
|
{`\#`, NameNamespace, Push("id")},
|
||
|
{`[\w-]+`, NameTag, nil},
|
||
|
{`#\{`, LiteralStringInterpol, Push("interpolation")},
|
||
|
{`&`, Keyword, nil},
|
||
|
{`[~^*!&\[\]()<>|+=@:;,./?-]`, Operator, nil},
|
||
|
{`"`, LiteralStringDouble, Push("string-double")},
|
||
|
{`'`, LiteralStringSingle, Push("string-single")},
|
||
|
{`\n`, Text, nil},
|
||
|
{`[;{}]`, Punctuation, Pop(1)},
|
||
|
},
|
||
|
"string-double": {
|
||
|
{`(\\.|#(?=[^\n{])|[^\n"#])+`, LiteralStringDouble, nil},
|
||
|
{`#\{`, LiteralStringInterpol, Push("interpolation")},
|
||
|
{`"`, LiteralStringDouble, Pop(1)},
|
||
|
},
|
||
|
"string-single": {
|
||
|
{`(\\.|#(?=[^\n{])|[^\n'#])+`, LiteralStringDouble, nil},
|
||
|
{`#\{`, LiteralStringInterpol, Push("interpolation")},
|
||
|
{`'`, LiteralStringDouble, Pop(1)},
|
||
|
},
|
||
|
"string-url": {
|
||
|
{`(\\#|#(?=[^\n{])|[^\n#)])+`, LiteralStringOther, nil},
|
||
|
{`#\{`, LiteralStringInterpol, Push("interpolation")},
|
||
|
{`\)`, LiteralStringOther, Pop(1)},
|
||
|
},
|
||
|
"pseudo-class": {
|
||
|
{`[\w-]+`, NameDecorator, nil},
|
||
|
{`#\{`, LiteralStringInterpol, Push("interpolation")},
|
||
|
Default(Pop(1)),
|
||
|
},
|
||
|
"class": {
|
||
|
{`[\w-]+`, NameClass, nil},
|
||
|
{`#\{`, LiteralStringInterpol, Push("interpolation")},
|
||
|
Default(Pop(1)),
|
||
|
},
|
||
|
"id": {
|
||
|
{`[\w-]+`, NameNamespace, nil},
|
||
|
{`#\{`, LiteralStringInterpol, Push("interpolation")},
|
||
|
Default(Pop(1)),
|
||
|
},
|
||
|
"for": {
|
||
|
{`(from|to|through)`, OperatorWord, nil},
|
||
|
Include("value"),
|
||
|
},
|
||
|
},
|
||
|
))
|