Skip to content

Commit

Permalink
SCSS: new parser based on @Roy-Orbison's work
Browse files Browse the repository at this point in the history
Close universal-ctags#801.

This is derrived from https://gist.github.com/Roy-Orbison/71bc81f488f85adaeacfb76a7967eda0.
Some modifications are done to align the kind and the behavior of this parser
to our css parser.

Noteworthy changes from the original version:
* The name of kind for "identifier" is changed to "id",
* The pseudo kind is removed, (my comments at universal-ctags#801)
* The parameter kind is added and
* The parser captures variables defined at @for ... and @each ...

TODO:
* table optimizations, and
* adding scope for parameters
  • Loading branch information
masatake committed Sep 11, 2019
1 parent 2614dbe commit e1f9334
Show file tree
Hide file tree
Showing 22 changed files with 459 additions and 0 deletions.
1 change: 1 addition & 0 deletions Units/parser-scss.r/function.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
10 changes: 10 additions & 0 deletions Units/parser-scss.r/function.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
remove-where input.scss /^@function remove-where($list, $condition) {$/;" f
list input.scss /^@function remove-where($list, $condition) {$/;" z
condition input.scss /^@function remove-where($list, $condition) {$/;" z
new-list input.scss /^ $new-list: ();$/;" v
separator input.scss /^ $separator: list-separator($list);$/;" v
element input.scss /^ @each $element in $list {$/;" v
new-list input.scss /^ $new-list: append($new-list, $element, $separator: $separator);$/;" v
fonts input.scss /^$fonts: Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif;$/;" v
contains-helvetica input.scss /^ @function contains-helvetica($string) {$/;" f
string input.scss /^ @function contains-helvetica($string) {$/;" z
22 changes: 22 additions & 0 deletions Units/parser-scss.r/function.d/input.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Taken from https://sass-lang.com/documentation/values/functions
/// Return a copy of $list with all elements for which $condition returns `true`
/// removed.
@function remove-where($list, $condition) {
$new-list: ();
$separator: list-separator($list);
@each $element in $list {
@if not call($condition, $element) {
$new-list: append($new-list, $element, $separator: $separator);
}
}
@return $new-list;
}

$fonts: Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif;

content {
@function contains-helvetica($string) {
@return str-index($string, "Helvetica");
}
font-family: remove-where($fonts, get-function("contains-helvetica"));
}
1 change: 1 addition & 0 deletions Units/parser-scss.r/mixin.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
2 changes: 2 additions & 0 deletions Units/parser-scss.r/mixin.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
reset-list input.scss /^@mixin reset-list {$/;" m
horizontal-list input.scss /^@mixin horizontal-list {$/;" m
22 changes: 22 additions & 0 deletions Units/parser-scss.r/mixin.d/input.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Taken from https://sass-lang.com/documentation/at-rules/mixin
@mixin reset-list {
margin: 0;
padding: 0;
list-style: none;
}

@mixin horizontal-list {
@include reset-list;

li {
display: inline-block;
margin: {
left: -2px;
right: 2em;
}
}
}

nav ul {
@include horizontal-list;
}
1 change: 1 addition & 0 deletions Units/parser-scss.r/placeholder.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
6 changes: 6 additions & 0 deletions Units/parser-scss.r/placeholder.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.alert:hover input.scss /^.alert:hover, %strong-alert {$/;" c
%strong-alert input.scss /^.alert:hover, %strong-alert {$/;" P
%strong-alert:hover input.scss /^%strong-alert:hover {$/;" P
%toolbelt input.scss /^%toolbelt {$/;" P
.action-buttons input.scss /^.action-buttons {$/;" c
.reset-buttons input.scss /^.reset-buttons {$/;" c
26 changes: 26 additions & 0 deletions Units/parser-scss.r/placeholder.d/input.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.alert:hover, %strong-alert {
font-weight: bold;
}

%strong-alert:hover {
color: red;
}

%toolbelt {
box-sizing: border-box;
border-top: 1px rgba(#000, .12) solid;
padding: 16px 0;
width: 100%;

&:hover { border: 2px rgba(#000, .5) solid; }
}

.action-buttons {
@extend %toolbelt;
color: #4285f4;
}

.reset-buttons {
@extend %toolbelt;
color: #cddc39;
}
1 change: 1 addition & 0 deletions Units/parser-scss.r/selectors.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
5 changes: 5 additions & 0 deletions Units/parser-scss.r/selectors.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.alert input.scss /^.alert, .warning {$/;" c
.warning input.scss /^.alert, .warning {$/;" c
.modal-open input.scss /^.modal-open {$/;" c
.modal input.scss /^ .modal {$/;" c
foo input.scss /^ #foo {$/;" i
23 changes: 23 additions & 0 deletions Units/parser-scss.r/selectors.d/input.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Taken from https://sass-lang.com/documentation/style-rules */
.alert, .warning {
ul, p {
margin-right: 0;
margin-left: 0;
padding-bottom: 0;
}
}

/* Taken from _bodal.scss of bootstrap */
.modal-open {
// Kill the scroll on the body
overflow: hidden;

.modal {
overflow-x: hidden;
overflow-y: auto;
}

#foo {
color: red;
}
}
1 change: 1 addition & 0 deletions Units/parser-scss.r/variable.d/args.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sort=no
7 changes: 7 additions & 0 deletions Units/parser-scss.r/variable.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
base-color input.scss /^$base-color: #c6538c;$/;" v
border-dark input.scss /^$border-dark: rgba($base-color, 0.88);$/;" v
.alert input.scss /^.alert {$/;" c
i input.scss /^@for $i from 1 through 3 {$/;" v
sizes input.scss /^$sizes: 40px, 50px, 80px;$/;" v
size input.scss /^@each $size in $sizes {$/;" v
.icon- input.scss /^ .icon-#{$size} {$/;" c
25 changes: 25 additions & 0 deletions Units/parser-scss.r/variable.d/input.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Taken from https://sass-lang.com/documentation/variables
$base-color: #c6538c;
$border-dark: rgba($base-color, 0.88);

.alert {
border: 1px solid $border-dark;
}

// Taken from https://sass-lang.com/documentation/at-rules/control/for
@for $i from 1 through 3 {
ul:nth-child(3n + #{$i}) {
background-color: lighten($base-color, $i * 5%);
}
}

// Taken from https://sass-lang.com/documentation/at-rules/control/each
$sizes: 40px, 50px, 80px;

@each $size in $sizes {
.icon-#{$size} {
font-size: $size;
height: $size;
width: $size;
}
}
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ The following parsers have been added:
* RpmSpec
* RSpec *optlib*
* Rust
* SCSS *optlib*
* SystemdUnit
* SystemTap *optlib*
* SystemVerilog
Expand Down
1 change: 1 addition & 0 deletions main/parsers_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
RubyParser, \
RustParser, \
SchemeParser, \
SCSSParser, \
ShParser, \
SlangParser, \
SmlParser, \
Expand Down
1 change: 1 addition & 0 deletions makefiles/optlib2c_input.mak
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ OPTLIB2C_INPUT = \
optlib/pod.ctags \
optlib/qemuhx.ctags \
optlib/puppetManifest.ctags \
optlib/scss.ctags \
optlib/systemtap.ctags \
\
$(NULL)
Loading

0 comments on commit e1f9334

Please sign in to comment.