Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Comments

Tokenise backslash in escape sequences#116

Merged
winstliu merged 3 commits intoatom:masterfrom
Cutlery-Drawer:slash-token
Mar 10, 2017
Merged

Tokenise backslash in escape sequences#116
winstliu merged 3 commits intoatom:masterfrom
Cutlery-Drawer:slash-token

Conversation

@Alhadis
Copy link
Contributor

@Alhadis Alhadis commented Feb 28, 2017

Decided to do this before the JSDoc grammar starts getting hairy. It enables a user to style the first backslash of a double-escape with their stylesheet:

.@{_}coffee{
	&.@{_}string{
		.@{_}punctuation.@{_}definition.@{_}escape.@{_}backslash{
			opacity: .2;
		}
	}
}

Which yields noticeable improvement to readability when you're working with CSON grammars:

Figure 1

Caveats

I haven't added specs because I want to focus on atom/language-javascript#495. I figured if I was going through the trouble of forking and dev-linking another package to make another job easier, I may as well share it.

Let me know if you still want me to add specs; but I won't get to it instantly.

EDIT: Belay that, specs added.

Addendum

FTR, it actually is possible to target the first character using the ::first-letter pseudo-element, but it's very limited in what properties can be applied: and that excludes opacity. Alternative would've been to squabble with text-colour, and... yeah, nah thanks.

@Alhadis
Copy link
Contributor Author

Alhadis commented Feb 28, 2017

Hey look, something even hairier than I am:

Figure 2

@50Wliu There's some odd double-escaping issue with my specsaver function; hence the reason spitting out specs isn't as quick as it would be. As such, the reason I deferred touching any coffee-specs.

(The snippet I tried tokenising is real, BTW...)

@winstliu
Copy link
Contributor

I would like another spec that tests for a normal backslash sequence, such as \a, rather than only testing for double-backslashes.

expect(tokens[10]).toEqual value: '"', scopes: ['source.coffee', 'string.quoted.double.coffee', 'punctuation.definition.string.end.coffee']

it "tokenises leading backslashes in single-quoted strings", ->
{tokens} = grammar.tokenizeLine("'a\\\\b\\\\\\\\c'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why I love how YAML has a string sequence that doesn't allow escape characters, to avoid shenanigans like this and your other example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAML doesn't allow tabs, so fuck YAML. =)

@Alhadis
Copy link
Contributor Author

Alhadis commented Mar 10, 2017

Done and done! 👍

expect(tokens[9]).toEqual value: 'c', scopes: ['source.coffee', 'string.quoted.double.coffee']
expect(tokens[10]).toEqual value: '"', scopes: ['source.coffee', 'string.quoted.double.coffee', 'punctuation.definition.string.end.coffee']

{tokens} = grammar.tokenizeLine('"\\\\a\\\\t\\\\a\\\\b"')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a slight misunderstanding - what I'm asking for is something like '"\\a\\t\\a\\b"'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops.

Force-pushed an amended commit, my bad.

@winstliu winstliu merged commit f117dc3 into atom:master Mar 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants