OpenSCAD parser error in the *middle* of a comment when last line accidentally uncommented? - error-handling

I have the following segment of comment in my code file (the last line is intentionally missing the slash characters - that the error):
// * Cube Back Text from Méi guī
// 一颗 心 怕 摔倒 打破
//"yī kē xīn pà shuāi dǎo dǎ pò"
// "It's the heart afraid of breaking"
// 不敢 起舞 欢 歌
// "bù gǎn qǐwǔ huāngē"
// "that never learns to dance."
不敢起舞欢歌 (dance)
But the red error dot appears on the second character of the second line (second slash of the line "// * Cube Back Text from Méi guī".
Stranger, if I remove various quotes in the comment, the character that is hilited changes.
I assume this has something to do with a recursive structure somewhere in the parser that is continuing to parse the quotes inside the comment itself and ultimately figures out where to signal the error.
I suppose this is a bug ("semi-bug") that I should post to the GitHub list - to completely ignore anything past the second slash on a commented line, or some other change so that the error tag shows up on the line where the error actually is?
As it is, I futzed around about 10 minutes wondering if OpenSCAD just didn't like files longer than 575 lines.

I get the same problem when I try your example or modify it slightly but it worked perfectly when I replaced everything with random Latin characters so I think the bug has a lot to do with the Chinese ideographs you used.
In any case, I only copied the small sample you gave so it probably have nothing to do with the length of the file.

Related

Intellij is incorrectly formatting my `.yml` file, I cannot see any errors in my style settings. how can I fix it?

Intellij keeps formatting my spotbugs.yml file incorrectly, and so breaking the github action.
I cannot figure out why it's doing this:
It was working fine last week, I haven't made any changes to the formatting config, but now, every time I change focus from the file Intellij auto-formats like this, then saves it. How can I fix it?
The thing I don't get is what it's formatting to appears to be invalid yaml, right?
YAML has a syntax that makes it incompatible with indentation that is not 2 spaces. With 4 spaces, you have:
droggel:
jug:
- sequence item: with indentation
this line: isn't aligned to four spaces
nor are further indented lines:
if you indent relative four spaces
spam:
- same: problem
without: indenting the sequence item
This makes it hard for code formatters to get it right. Proper alignment would mean:
droggel:
jug:
- three spaces after the sequence item indicator.
that's horrible, nobody does that.
spam:
- alternatively this.
nobody does this either and it breaks
- - with nested sequences
I assume some bug in IntelliJ causes the formatter to be confused because of this. Generally it would be better to just use 2 space indentation which seems far more natural due to the problems described above. That should avoid confusing the formatter.

In Vim can I automatically soft wrap comments with alignment at the first character

I'm currently using vim to take notes and the way I'll usually do that is as follows:
- First line of info
- Sub line of info
- More sub information
- Second point
- Third point, etc
However, when writing long lines the output will look as follows:
- First line of info that is really long
goes down to here
- Subpoint line of info that is short
- Subpoint line that is really long goes to
here and continues
- Subpoint line that is short again
- Second point that is really long goes to
here, etc, etc
What I'd really like is if it looked like this:
- First line of info that is really long
goes down to here
- Subpoint line of info that is short
- Subpoint line that is really long goes to
here and continues
- Subpoint line that is short again
- Second point that is really long goes to
here, etc, etc
This would make it easier to see when each new point or subpoint was started because of the "-" sticks out more.
If possible I'd like:
automatic inserting of the leading character (doesn't have to be a dash) on enter
automatic inserting of the leading character (doesn't have to be a dash) on o and O
automatic soft wrapping of the text to the correct indentation level
automatic soft wrapping of the text to the first character after the leading character
I've been able to achieve the first three using the following:
set formatoptions=ro
set comments=b:-
set breakindent
set autoindent
However, when trying to get the soft wrapping at the first character after the "-" I am having trouble.
I've tried using set formatoptions+=n with an accompanying formatlistpat=^\s*-\s*. However, then it is not automatic and I need to use gq which seems like it makes a second line instead of just soft wrapping. If using set formatoptions+=wan I can get it sometimes automatically wrapping but it is once again a hard line break, not a soft wrapping.
If anyone could help that would be greatly appreciated!
So I've finally figured it out. The answer was breakindentopt :help breakindentopt
Specifically set breakindentopt=shift:2
This causes the line that is wrapped due to breakindent to shift two spaces two the right which lines everything up the way I wanted.
The full settings which achieve what I was going for are:
set formatoptions=ro
set comments=b:-
set breakindent
set autoindent
set breakindentopt=shift:2

How to strip single-line comments in obj-c properly

I know there are a lot of resources with regex for it. But I could not find the one I want.
My problem is:
I want to remove one line comments (//) from obj-c sources, but I don't want to break the code in it. For instance, with this regex: #"//.*" I can remove all comments, but it also corrupts string literal:
#"bsdv//sdfsdf"
I played with non-capturing parentheses (?:(\"*\")*+), but without success.
Also I found this expression for Python:
r'(\".*?\"|\'.*?\')|(/\*.*?\*/|//[^\r\n]*$)'
It should cover my case, but I've not figure out how to make it work with obj-c.
Please, help me to build proper regex.
UPDATE: Yeah, that's a tough one, I know there're a lot of caveats, other than the one I described. I would appreciate if someone post regex that only fix my issue. Anyway, I gonna post my solution, without regex soon, I hope it will be helpful for anyone who struggling with such problem too.
Try this regex:
(?:^|.*;(?!.*")|#(?:define|endif|ifn?def|import|undef|...).*)\s*(//[^\r\n]+$)
Demo
http://regex101.com/r/jT4xC8
Description
Discussion
Besides all the warnings expressed in the comments, I assume that a single line can appear in two distinct cases:
Case 1: Alone on its line preceded or not by blank chars
Case 2: Not Alone on its line preceded or not by blank chars, and other chars.
In the first case, we match the beginning of the line (^ with /m flag). Then we search zero or more blank chars (\s*) and finally the single line comment: //[$\r\n]+$.
In the second case, if there are other chars on the line, they form statements. Any statement is ended by a semicolon ;. So we search the last statement and its corresponding semicolon .*;(?!.*"). Then we search the single line comment. Those other chars can be also preprocessor statements. In this case, they are introduced by a sharp #.
One important keypoint is that I assume the code passed to the regex is a code that compiles.
There is more
Don't forget also to add some other pre-processor directives that may apply in your case. Check this SO answer: https://stackoverflow.com/a/18014883/363573

How are error messages in StringTemplate to be interpreted?

I got this error message while using StringTemplate:
line 94:26: unexpected char: ')'
And after about 15 minutes of randomly adding and removing blank lines in my template, and observing how the number in that message changed, I finally isolated the line that caused trouble. It was line #152, position #35.
Is the value after "line " just normally totally wrong, or is there a way of deducing the real line number from that output?
In StringTemplate (ST) 4, it appears that the first number is the line number, within the specific template at issue and not the line number within the .stg file if that's what you're using (which most of us do).
When I'm using vim, this means I need to mentally offset that from the line number of the first line of the template (add them together) to get the actual line number within the .stg file.
The second number in the ST error is the character position within that line of the template. But wait, there's more - you know you love it...
When an error is on the first line of a multi-line template: since ST elides the starting newline in multi-line templates, ST effectively combines the first/ declaration line (ending in "<<") with the second (actual start of the template) line, in multi-line templates;
so at least with ST-4.0.8 I need to subtract the length of the template declaration line from the character position, to get the actual character position.
The first "\n" eliding (for multi-line templates only) also means the line number may appear to be offset by 1, and possibly the character position, for an error on the "first line".
The error should include the filename and template name, so it's enough information for an automated script or tool, but a bit cumbersome for us mere humans.
Good luck.

Error 2 'If', 'ElseIf', 'Else', 'End If', 'Const', or 'Region' expected

I've made some function that generates an email template. Code it generates is pure HTML with CSS. Problem is compiler does this odd error and highlights each time '#' sign appears which is needed to define colors in CSS. I did try to change '#' to '/pound/' and then string.Replace() on RETURN but no luck. I'm more into C# so there i can escape special characters by using '\' before them but something f$#$ed up there... Once i remove '#' all back to normal and compiles well.
Any guesses ?
btw, i'm using StringBuilder to generate lines of code with sb.Append().
ie.
sb.Append("<div style=""color:#333"">some text</div>")
I think it's a bug,
to reproduce it I used VB.NET 2 (VS 2005), I wrote your instruction:
sb.Append("<div style=""color:#333"">some text</div>")
no problem,
I added some extra " to have the error message you got,
I then fixed everything, all errors disappeared except yours.
Solution: Delete that line, error disappeared, ctrl-z (undo) --> all ok!
I was receiving this same exact error and was able to simply copy the line, delete the line out, re-add a new line, and paste.