Change special mark colour in Sublime Text 3? - sublimetext3

I would like to change color of single '=' (equality sign) but leave the multi marks '==' or '===' alone.
Same with '!' mark, but I don't want to change '!=' or similar.
How to do that? I'm fighting with (Adaptive.sublime.color.scheme):
{
"name": "Keyword",
"scope": "keyword - (source.c keyword.operator | source.c++ keyword.operator | source.objc keyword.operator | source.objc++ keyword.operator), keyword.operator.word",
"foreground": "var(green)" // if, else, new, ,in, return, '=', '+', '&', '|', '!=', etc.
},
to no avail. Is there option to change single special mark color?

Related

VIM replace in part of pattern

I would like to replace spaces with underscores inside quotes in part of a pattern.
Example input:
select
"AA" as "Long descriptive name",
"BB" as "Another long name",
"CC" as "There are many spaces here"
from
sometable;
Wanted output:
select
"AA" as "Long_descriptive_name",
"BB" as "Another_long_name",
"CC" as "There_are_many_spaces_here"
from
sometable;
I have tried doing this with the substitute() and submatch() functions like this but I can't get it to quite work (The \= part is not interpreted the substitute command is written into the file). Something is missing.
:%s/ as "\(.*\)"/ as \=substitute(submatch(1),' ', '_', 'g')/g
well you were close:
:%s/ as "\zs\(.*\)\ze"/\=substitute(submatch(1),' ', '_', 'g')/g
\= only is interpreted as expression if the string starts with it. see :h sub-replace-special. You can solve that problem by just matching the part you want to replace (using \zs and \ze in my example).
This does of course not always work. Then you will have to build a string again in the \= part. Which would look like that:
:%s/ as "\(.*\)"/\=' as "'.substitute(submatch(1),' ', '_', 'g').'"'/g

How to parse a list of text separated by multi-character delimeters

To parse a comma separated list of text (no comma escapes allowed) I can use this,
main: Text (Sep Text)*;
Sep: ',';
Text: ~','*;
Now I'd like to modify the parser to use two commas instead of one as a separator.
Clearly this doesn't work,
main: Text (Sep Text)*;
Sep: ',,';
Text: ~',,'*;
How can I accomplish this? Is it possible for the lexer to return a single token with the text? And is it possible without actions\predicates?
No, you can't negate 2 (or more) characters (~',,' is invalid).
You could do this:
main : Text (sep Text)* EOF;
sep : Comma Comma;
Comma : ',';
Text : ~',' ( ~',' | ',' ~',' )*;
Where Text matches a non-comma (~','), followed by zero or more:
non-commas (~','), or
a single comma, followed by a non-comma (',' ~',')

Notepad++ remove text between string+bracket and another bracket

So, I've seen that you can remove between two characters and remove between two strings but I haven't been able to find a system that works between a string and a character.
I need to remove the numbers between the two brackets in...
provinces= {
923 6862 9794 9904 11751 11846 11882
}
Keep in mind that these files also contains other brackets which are needed. I've looked around for a solution for this but none seem to work :/
Thanks for the help.
This one will do the job:
Ctrl+H
Find what: \b(provinces\s*=\s*\{)[^}]+(\})
Replace with: $1$2
Replace all
Explanation:
\b : a word boundary
( : start group 1
provinces : literally "provinces"
\s* : 0 or more spaces
= : equal sign
\s* : 0 or more spaces
\{ : an open curly bracket, must be escaped because it has special meaning in regex
) : end group 1
[^}]+ : any character that is not a close curly bracket
(\}) : group 2, a close curly bracket, escaped.
Replacement:
$1$2 : group 1 then group 2

ANTLRv4 : Read double quotes escaped with both \ and "

I'm trying to implement a parser using ANTLRv4 for a language that accepts both "" and \" as a way escaping " characters in " delimited strings.
The answers to this question show how to do it for "" escaping. However when I try to extend it to also cover the \" case, it almost works but becomes too greedy when two strings are on the same line.
Here is my grammar:
grammar strings;
strings : STRING (',' STRING )* ;
STRING
: '"' (~[\r\n"] | '""' | '\"' )* '"'
;
Here is my input of three strings:
"This is ""my string\"",
"cat","fish"
This correctly recognises "This is ""my string\"", but thinks that "cat","fish" is all one string.
If I move "fish" down on to the next line it works correctly.
Can anyone figure out how to make it work if "cat" and "fish" are on the same line?
Make your STRING rule non greedy to stop at the first quote char it encounters, instead of trying to get as much as possible:
STRING
: '"' (~[\r\n"] | '""' | '\"' )*? '"'
;
I've found what I need to do to get this to work as I wanted, though to be honest I'm still not entirely sure why Antlr was doing what it did.
Simply by adding another backslash character to the '\"' clause it works!
So my final STRINGS definition is : '"' (~[\r\n"] | '""' | '\\"' )* '"'
Going back to first principles, I hand drew a state transition diagram of the problem and then realised that the two escaping mechanism sequences are not the same and cannot be treated similarly. Then trying to implement the two patterns in AntlrWorks it became apparent that I needed to add the second backslash at which point it all started working.
Does a single backslash followed by some arbitrary character simply mean that character?

How do I break a string in YAML over multiple lines?

In YAML, I have a string that's very long. I want to keep this within the 80-column (or so) view of my editor, so I'd like to break the string. What's the syntax for this?
In other words, I have this:
Key: 'this is my very very very very very very long string'
and I'd like to have this (or something to this effect):
Key: 'this is my very very very ' +
'long string'
I'd like to use quotes as above, so I don't need to escape anything within the string.
There are 5 6 NINE (or 63*, depending how you count) different ways to write multi-line strings in YAML.
TL;DR
Use > most of the time: interior line breaks are stripped out, although you get one at the end:
key: >
Your long
string here.
Use | if you want those linebreaks to be preserved as \n (for instance, embedded markdown with paragraphs).
key: |
### Heading
* Bullet
* Points
Use >- or |- instead if you don't want a linebreak appended at the end.
Use "..." if you need to split lines in the middle of words or want to literally type linebreaks as \n:
key: "Antidisestab\
lishmentarianism.\n\nGet on it."
YAML is crazy.
Block scalar styles (>, |)
These allow characters such as \ and " without escaping, and add a new line (\n) to the end of your string.
> Folded style removes single newlines within the string (but adds one at the end, and converts double newlines to singles):
Key: >
this is my very very very
long string
→ this is my very very very long string\n
Extra leading space is retained and causes extra newlines. See note below.
Advice: Use this. Usually this is what you want.
| Literal style
turns every newline within the string into a literal newline, and adds one at the end:
Key: |
this is my very very very
long string
→ this is my very very very\nlong string\n
Here's the official definition from the YAML Spec 1.2
Scalar content can be written in block notation, using a literal style (indicated by “|”) where all line breaks are significant. Alternatively, they can be written with the folded style (denoted by “>”) where each line break is folded to a space unless it ends an empty or a more-indented line.
Advice: Use this for inserting formatted text (especially Markdown) as a value.
Block styles with block chomping indicator (>-, |-, >+, |+)
You can control the handling of the final new line in the string, and any trailing blank lines (\n\n) by adding a block chomping indicator character:
>, |: "clip": keep the line feed, remove the trailing blank lines.
>-, |-: "strip": remove the line feed, remove the trailing blank lines.
>+, |+: "keep": keep the line feed, keep trailing blank lines.
"Flow" scalar styles ( , ", ')
These have limited escaping, and construct a single-line string with no new line characters. They can begin on the same line as the key, or with additional newlines first, which are stripped. Doubled newline characters become one newline.
plain style (no escaping, no # or : combinations, first character can't be ", ' or many other punctuation characters ):
Key: this is my very very very
long string
Advice: Avoid. May look convenient, but you're liable to shoot yourself in the foot by accidentally using forbidden punctuation and triggering a syntax error.
double-quoted style (\ and " must be escaped by \, newlines can be inserted with a literal \n sequence, lines can be concatenated without spaces with trailing \):
Key: "this is my very very \"very\" loooo\
ng string.\n\nLove, YAML."
→ "this is my very very \"very\" loooong string.\n\nLove, YAML."
Advice: Use in very specific situations. This is the only way you can break a very long token (like a URL) across lines without adding spaces. And maybe adding newlines mid-line is conceivably useful.
single-quoted style (literal ' must be doubled, no special characters, possibly useful for expressing strings starting with double quotes):
Key: 'this is my very very "very"
long string, isn''t it.'
→ "this is my very very \"very\" long string, isn't it."
Advice: Avoid. Very few benefits, mostly inconvenience.
Block styles with indentation indicators
Just in case the above isn't enough for you, you can add a "block indentation indicator" (after your block chomping indicator, if you have one):
- >8
My long string
starts over here
- |+1
This one
starts here
Note: Leading spaces in Folded style (>)
If you insert extra spaces at the start of not-the-first lines in Folded style, they will be kept, with a bonus newline. (This doesn't happen with flow styles.) Section 6.5:
In addition, folding does not apply to line breaks surrounding text lines that contain leading white space. Note that such a more-indented line may consist only of such leading white space.
- >
my long
string
many spaces above
- my long
string
many spaces above
→ ["my long\n string\n \nmany spaces above\n","my long string\nmany spaces above"]
Summary
In this table, _ means space character. \n means "newline character" (\n in JavaScript) except under "Other features". "Leading space" applies after the first line (which establishes the indent)
>
|
"
'
>-
>+
|-
|+
Spaces/newlines converted as:
Trailing space →
_
_
_
_
_
_
Leading space →
\n_
\n_
\n_
\n_
\n_
\n_
Single newline →
_
\n
_
_
_
_
_
\n
\n
Double newline →
\n
\n\n
\n
\n
\n
\n
\n
\n\n
\n\n
Final newline →
\n
\n
\n
\n
Final double newline →
\n\n
\n\n
How to create a literal:
Single quote
'
'
'
'
''
'
'
'
'
Double quote
"
"
"
\"
"
"
"
"
"
Backslash
\
\
\
\\
\
\
\
\
\
Other features
In-line newlines with \n
🚫
🚫
🚫
✅
🚫
🚫
🚫
🚫
🚫
Spaceless newlines with \
🚫
🚫
🚫
✅
🚫
🚫
🚫
🚫
🚫
# or : in value
✅
✅
🚫
✅
✅
✅
✅
✅
✅
Can start on sameline as key
🚫
🚫
✅
✅
✅
🚫
🚫
🚫
🚫
Examples
Note the trailing spaces on the line before "spaces."
- >
very "long"
'string' with
paragraph gap, \n and
spaces.
- |
very "long"
'string' with
paragraph gap, \n and
spaces.
- very "long"
'string' with
paragraph gap, \n and
spaces.
- "very \"long\"
'string' with
paragraph gap, \n and
s\
p\
a\
c\
e\
s."
- 'very "long"
''string'' with
paragraph gap, \n and
spaces.'
- >-
very "long"
'string' with
paragraph gap, \n and
spaces.
[
"very \"long\" 'string' with\nparagraph gap, \\n and spaces.\n",
"very \"long\"\n'string' with\n\nparagraph gap, \\n and \nspaces.\n",
"very \"long\" 'string' with\nparagraph gap, \\n and spaces.",
"very \"long\" 'string' with\nparagraph gap, \n and spaces.",
"very \"long\" 'string' with\nparagraph gap, \\n and spaces.",
"very \"long\" 'string' with\nparagraph gap, \\n and spaces."
]
*2 block styles, each with 2 possible block chomping indicators (or none), and with 9 possible indentation indicators (or none), 1 plain style and 2 quoted styles: 2 x (2 + 1) x (9 + 1) + 1 + 2 = 63
Some of this information has also been summarised here.
Using yaml folded style. The indention in each line will be ignored. A line break will be inserted at the end.
Key: >
This is a very long sentence
that spans several lines in the YAML
but which will be rendered as a string
with only a single carriage return appended to the end.
http://symfony.com/doc/current/components/yaml/yaml_format.html
You can use the "block chomping indicator" to eliminate the trailing line break, as follows:
Key: >-
This is a very long sentence
that spans several lines in the YAML
but which will be rendered as a string
with NO carriage returns.
In either case, each line break is replaced by a space.
There are other control tools available as well (for controlling indentation for example).
See https://yaml-multiline.info/
To preserve newlines use |, for example:
|
This is a very long sentence
that spans several lines in the YAML
but which will be rendered as a string
with newlines preserved.
is translated to "This is a very long sentence‌\n that spans several lines in the YAML‌\n but which will be rendered as a string‌\n with newlines preserved.\n"
1. Block Notation(plain, flow-style, scalar): Newlines become spaces and extra newlines after the block are removed
---
# Note: It has 1 new line after the string
content:
Arbitrary free text
over multiple lines stopping
after indentation changes...
...
Equivalent JSON
{
"content": "Arbitrary free text over multiple lines stopping after indentation changes..."
}
2. Literal Block Scalar: A Literal Block Scalar | will include the newlines and any trailing spaces. but removes extra
newlines after the block.
---
# After string we have 2 spaces and 2 new lines
content1: |
Arbitrary free text
over "multiple lines" stopping
after indentation changes...
...
Equivalent JSON
{
"content1": "Arbitrary free text\nover \"multiple lines\" stopping\nafter indentation changes... \n"
}
3. + indicator with Literal Block Scalar: keep extra newlines after block
---
# After string we have 2 new lines
plain: |+
This unquoted scalar
spans many lines.
...
Equivalent JSON
{
"plain": "This unquoted scalar\nspans many lines.\n\n\n"
}
4. – indicator with Literal Block Scalar: – means that the newline at the end of the string is removed.
---
# After string we have 2 new lines
plain: |-
This unquoted scalar
spans many lines.
...
Equivalent JSON
{
"plain": "This unquoted scalar\nspans many lines."
}
5. Folded Block Scalar(>):
will fold newlines to spaces and but removes extra newlines after the block.
---
folded_newlines: >
this is really a
single line of text
despite appearances
...
Equivalent JSON
{
"fold_newlines": "this is really a single line of text despite appearances\n"
}
for more you can visit my Blog
To concatenate long lines without whitespace, use double quotes and escape the newlines with backslashes:
key: "Loremipsumdolorsitamet,consecteturadipiscingelit,seddoeiusmodtemp\
orincididuntutlaboreetdoloremagnaaliqua."
You might not believe it, but YAML can do multi-line keys too:
?
>
multi
line
key
:
value
In case you're using YAML and Twig for translations in Symfony, and want to use multi-line translations in Javascript, a carriage return is added right after the translation. So even the following code:
var javascriptVariable = "{{- 'key'|trans -}}";
Which has the following yml translation:
key: >
This is a
multi line
translation.
Will still result into the following code in html:
var javascriptVariable = "This is a multi line translation.
";
So, the minus sign in Twig does not solve this. The solution is to add this minus sign after the greater than sign in yml:
key: >-
This is a
multi line
translation.
Will have the proper result, multi line translation on one line in Twig:
var javascriptVariable = "This is a multi line translation.";
For situations were the string might contain spaces or not, I prefer double quotes and line continuation with backslashes:
key: "String \
with long c\
ontent"
But note about the pitfall for the case that a continuation line begins with a space, it needs to be escaped (because it will be stripped away elsewhere):
key: "String\
\ with lon\
g content"
If the string contains line breaks, this needs to be written in C style \n.
See also this question.
None of the above solutions worked for me, in a YAML file within a Jekyll project. After trying many options, I realized that an HTML injection with <br> might do as well, since in the end everything is rendered to HTML:
name: |
In a village of La Mancha <br> whose name I don't <br> want to remember.
At least it works for me. No idea on the problems associated to this approach.

Resources