Skip to content

Instantly share code, notes, and snippets.

@ctkjose
Last active August 27, 2018 13:24
Show Gist options
  • Save ctkjose/f3a6c2391ea898e837e81ef10213d78b to your computer and use it in GitHub Desktop.
Save ctkjose/f3a6c2391ea898e837e81ef10213d78b to your computer and use it in GitHub Desktop.
Refactor Komodo Edit Source Tree RegEx

Refactor NST.js

Source Tree uses the LineParserJS to parse CSS and SCSS. This is the refactoring I made to improve SASS support.

p = new LineParserJS(self.lang,
    ['@name,'],
    ['name {'],
    '[\\-*#.a-zA-Z_]' +
    '[ =\\"\\]\\[\\)\\(\\->:,*#.a-zA-Z0-9_]*',
    null);

I replaced it to:

p = new LineParserJS(
	self.lang,
	[
		'<spaces>((#\\{([^\\{]+)))\\{\\s',
		'<spaces>([\\.#$&a-zA-Z](.(?!\\s\\{))+.(?=\\s*\\{))\\s'
	],
	[
		'<spaces>(@each\\s+(\\$[a-zA-Z0-9\\-_,\\$ ]+))\\s+in\\s+.*?\\{',
		'<spaces>(@media\\s+(.(?!\\s\\{))+.(?=\\s*\\{))'
	],
	'[a-zA-Z0-9_\\-]+',
	null
);

Test cases:

.jose-bold {
.class:hover {
.class-long[type="text"]{
#id {
input {
input[type="jose"] {
input[type~="jose"]{
#{&}.jose {
#{&} .jose {
& .jose {
& .class, &.classb {
&.jose {
&:hover {
#{$item-alias}
&.#{$color-name}:not(.is-disabled):active {
.root > .hello {
.root &.class {
.root &.class.#{$var} {
@each $color-name, $size, $colors in $colors-themes {
@media screen and (min-width: 900px) {
@ctkjose
Copy link
Author

ctkjose commented Jul 13, 2018

Regex test available at: https://regex101.com/r/76wXZ3/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment