I want this resource to work with the !Sub (or Fn::Sub) intrinsic function
Resource: !Sub 'arn:aws:iam::${AWS::AccountId}:user/${aws:username}'
The aws:username is a pollicy variable that mustn't be replaced.
One solution would be to use Fn::Join instead and write a bit more boilerplate code.
Better: Can you escape the ${aws:username} so that !Sub will work here? Unfortunately, the documentation does not mention anything about escaping.
You actually can escape $ characters with ${!}.
So your resource would look like this:
Resource: !Sub 'arn:aws:iam::${AWS::AccountId}:user/${!aws:username}'
It is mentioned in the docs under the string parameter section.
To write a dollar sign and curly braces (${}) literally, add an
exclamation point (!) after the open curly brace, such as ${!Literal}.
AWS CloudFormation resolves this text as ${Literal}.
Related
When I run swiftlint I get a printout saying that some rules have an invalid configuration.
Invalid configuration for custom rule 'commented_out_code'.
Invalid configuration for custom rule 'avoid_multiline_comment_markers'.
Invalid configuration for custom rule 'avoid_background_color'.
No other custom rules are marked as such, and the rules themselves still work in the project. These are the configurations in question:
commented_out_code:
regex: '(?<!:|\/)\/\/\h*[a-z.](?!wiftlint)'
message: "Comment starting with lowercase letter - did you forget to delete old code?"
avoid_multiline_comment_markers:
regex: '*/'
message: "Avoid using multi-line comment markers like */ and /* - use // and /// instead."
avoid_background_color:
regex: '.background(Color.'
message: "Avoid using .background(Color), use .backgroundColor() instead."
The last one is my own, the other 2 are default custom rules however, that come in a basic swiftlint config file.
Here is a "valid" rule to show the formatting is the same:
use_int_zero_property_in_single_check:
regex: ' == 0[^( {)]'
message: "Avoid checking for '0' in single check, use '== .zero' instead."
What could be invalid about these?
Things I've tried that had no result:
Swapping single and double quotation marks
Moving the blocks around
Re-indent the lines with both spaces and tabs
The problem here is incorrect regex syntax, mainly not escaping characters properly.
So for avoid_background_color it should be
regex: '\.background\(Color\.'
And for avoid_multiline_comment_markers
regex: '\*/'
commented_out_code is hard for me to understand but it looks like you missed a = at the beginning
regex: '(?=<!:|\/)\/\/\h*[a-z.](?!wiftlint)'
I would recommend the site https://regex101.com for testing and verifying your regex syntax.
I noticed that when using the Pubspec Assist plugin, it wraps the description line when updating a dependency.
description: Have you been turned into a newt? Would you like to be? This
package can help. It has all of the newt-transmogrification functionality you
have been looking for.
In researching this wrapping, I found that yaml supports wrapping, but indicates to use > (or | for keeping newlines, which probably isn't recommended for Flutter apps?).
The pubspec page on dart.dev shows an example using >-, but its own description doesn't mention anything about long descriptions or wrapping.
description: >-
Have you been turned into a newt? Would you like to be?
This package can help. It has all of the
newt-transmogrification functionality you have been looking
for.
Does it matter, in a Flutter project, say from an app store's perspective, which method is used for wrapping long descriptions in the pubspec.yaml file? I've always just kept them as one long line.
Wrapping is a YAML syntax feature. Flutter applies semantics to the parsed content of your YAML file.
This means that it doesn't matter to Flutter how you represent your YAML scalars, as long as the result – as defined by the YAML syntax you use – yields a valid value for Flutter.
With some scalars, YAML employs line folding: Single line breaks are transformed into a space, while empty lines are transformed into line breaks. This happens both with plain scalars and folded block scalars:
droggeljug: This is a plain scalar.
It spans multiple lines but when parsed, contains a single line.
baked_beans: >-
This is a folded block scalar.
It also spans multiple lines.
The previous empty line yields a line break in the parsed value.
There are some differences to consider:
plain scalars get ended by various special characters, such as : (when followed by whitespace). This should be obvious seeing that it forms an implicit key.
folded block scalars only end when content at the indentation of a parent node is encountered. You can savely write any character into a folded block scalar, even # which would otherwise starte a comment.
some scalars may be parsed a non-strings when given as plain scalar. For example, true might be a boolean and 42 might be a number. Folded block scalars always yield strings no matter the content.
Apart from these, there are also single- and double-quoted scalars, and literal block scalars (starting with | instead of >). Literal block scalars parse line breaks as-is. Double-quoted scalars parse escape sequences. Single-quoted scalars just don't end until the second ' is encountered. All of these scalar types may be multiline and all except literal block scalars do line folding. You can choose any of them to encode your string value.
As to the question which one you should use, I'd say the folded block scalar >- is the right tool for the job: You can write anything without worrying about YAML special characters, escape sequences, etc.
I'm implementing a syntax highlighter in Apple's Swift language by parsing .tmlanguage files and applying styles to a NSMutableAttributtedString.
I'm testing with javascript code, a javascript.tmlanguage file, and the monokai.tmtheme theme (both last included in sublime text 3) to check that the syntax get highlighted correctly. By applying each rule (patterns) in the .tmlanguage file in the same order they come, the syntax is almost perfectly highlighted.
The problem I'm having right now is that I don't know how to know that a quote (") should be escaped when it has a backslash before it (\"). Am I missing something in the .tmlanguage file that specifies that?. Other problem is that I have no idea how to know that other rules should be ignored when inside others, for example:
I'm getting double slashes taken as comments when inside strings: "http://stackoverflow.com/" a url is recognised as comment after //
Also double or single quotes are taken as strings when inside comments: // press "Enter" to continue, the word "Enter" gets highlighted as string when should be same color as comments
So, I don't know if there is some priority for some rules over others in the convention, or if there is something in the files that I haven't noticed.
Help please!
Update:
Here is a better example of what I meant by escape quotes:
I'm getting this: while all the letters should be yellow except for the escaped sequence (/") which should be blue.
The question is. How do I know that /" should be escaped? The rule for that piece of code is:
Maybe I am late to answer this. You can apply the following method.
(Ugly) In your end regex, use ([^/])(") and in your endCaptures, it would be
1 = string.quote.double.js
2 = punctuation.definition.string.end.js
If the string must be single line, you can use match=(")(.*)("), captures=
1 = punctuation.definition.string.begin.js
2 = string.quote.double.js
3 = punctuation.definition.string.end.js
and use your patterns
You can try applyEndPatternLast and see if it is allowed. Set applyEndPatternLast=1 will do.
The priority is that earlier rules in the file are prioritized over later rules. As an example, in my Python Improved language definition, I have a scope that contains a series of all-caps constants used in Django, a popular Python web framework. I also have a generic constant.other.allcaps.python scope that recognizes (just about) anything in all caps. Since the Django constants rule is before the allcaps rule in the .tmLanguage file, I can color it with a theme using one color, while the later-occurring "highlight everything in all caps" only grabs identifiers that are NOT part of the first list.
Because of this, you should put your "comments" scope(s) as early in the file as possible, then write your parser in such a way that it obeys the rule I described above. However, it's slightly more complicated than that, as I believe items in the repository are prioritized based on where their include line is, not where the repository rule is defined in the file. You may want to do some testing to verify that, though.
Unfortunately I'm not sure what you mean about the escaped quotes - could you expand on that, and maybe add an example or two?
Hope this helps.
Assuming that / is the correct character for escaping a double quote mark, the following should work:
"str_double_quote": {
"begin": "\"",
"end": "\"",
"name": "string.quoted.double.swift",
"patterns": [
{
"name": "constant.character.escape.swift",
"match": "/[\"/]"
}
]
}
You can match an escaped double quote mark (/") and a literal forward slash (//) in the patterns to consume them before the end marker is used to handle them.
If the character for escaping is actually a backslash, then the tricky bit is that there are two levels of escaping, for the JSON encoding as well as the regular expression syntax. To match \", the regular expression requires you to escape the backslash (\\"). JSON requires you to escape backslashes and double quotes, resulting in \\\\\" in a TextMate JSON grammar file. The match expression would thus be \\\\[\"\\\\].
Could anyone please suggest a method to surround a region that contains a leading \$ and surround it with a snippet. In latex-mode, I am frequently underlining or double-underlining monies due and the yasnippet being used removes the backslash. I'd like to be able to use the same snippet for all situations -- with or without a leading \$.
# -*- mode: snippet -*-
# contributor: lawlist
# key: underline_selected
# group: font
# name: underline_selected
# binding: C-I u s
# --
\uline{`yas/selected-text`}
There are few problems that cause the behavior described by the original poster, who uses a custom modified version of tex-mode.el, not AUCTeX.
First, the function yas--snippet-parse-create contains, among other codes, the following functions that do not play well with LaTeX escaped dollar signs:
(yas--protect-escapes nil `(?\\ ?` ?'))
(yas--protect-escapes)
(yas--restore-escapes)
(yas--delete-regions ys--dollar-regions)
Second, the variable yas--simple-mirror-regexp catches dollar amounts, in addition to the standard yasnippet fields such as $1. When the above-mentioned (yas--delete-regions yas--dollar-regions) is called by yas--snippet-parse-create, the result is an erroneous deletion. The author of this answer has modified the regexp to exclude a dollar-sign with a preceding backslash:
(setq yas--simple-mirror-regexp "[^\\]$\\([0-9]+\\)")
The author of this answer does not presently have a fix for yas--protect-escapes and yas--restore-escapes, and has merely commented them out in the meantime. [This would obviously be problematic for anyone doing programming, but appears to be sufficient for merely writing LaTeX documents.] An issue has been opened on Github and the author of this answer will update this thread if a solution is found there.
I've trying to write a Bibtex parser with flex/bison. Here are the rules for strings in bibtex:
Strings can be enclosed in double quotes "..." or in braces {...}
In a string, braces can be nested
Inside a string, the braces should be balanced (invalid string: {this is a { test})
Inside an "internet" {}, you can have any characters. So this string is valid: {This is a string {test"} and it is valid}
Any ideas on how to do this?
Now you're going into the field of a text parser. Surprisingly, nobody has made a bibtex library for Actionscript that I could find, so it's an interesting problem. If you do make one, do the community a favor and open source it :)
It won't be easy to do since you essentially have to go character by character and check for the chars that you need and do logic around that. However, I recommend you look at as3corelib's implementation of the JSON parser which is somewhat similar to what you're trying to accomplish. You'll at least get an idea of how to do it using a tokenizer and it's a very good start on your project.
Good luck.