How do You Get Vim to Syntax Highlight Arithmetic Operators for Python? - syntax-highlighting

I found that, while in vim, if I were to give the following commands
:syn match pythonOperator "="
or
:syn match pythonOperator "+"
etc.
Vim would highlight =, and +; however, when I add this to ~/.config/nvim/after/syntax/python.vim, it doesn't work. What is the proper way to extend what Vim highlights?
EDIT:
This is the output of the command :filter /python/ scriptnames:
61: /usr/share/nvim/runtime/ftplugin/python.vim
62: /usr/share/nvim/runtime/autoload/provider/python3.vim
63: /usr/share/nvim/runtime/autoload/provider/pythonx.vim
65: /usr/share/nvim/runtime/autoload/provider/python.vim
66: /usr/share/nvim/runtime/indent/python.vim
67: /usr/share/nvim/runtime/syntax/python.vim
68: ~/.config/nvim/after/syntax/python.vim
As seen with 68:, my python syntax file is being loaded, but for some reason the commands that I put in are being ignored?
For clarification, I added litterally
syn match pythonOperator "+"
syn match pythonOperator "-"
to ~/.config/nvim/after/syntax/python.vim which was originally copied from /usr/share/nvim/runtime/syntax/python.vim. If it matters where I added it, I added it right after line 104 in the file which is after the block of keyword definitions.

Related

Why does (*.foo|bar) cause an error, but !(*.foo|bar) does not?

Error
line 852: syntax error near unexpected token `('
Line 852 is the last line of a function:
touch --reference="$KERNEL_FILE" "$moduledest"/modules.(*.bin|devname|softdep)
No error
When inserting the exclamation mark ! before (:
touch --reference="$KERNEL_FILE" "$moduledest"/modules.!(*.bin|devname|softdep)
How to touch the inverse of !(*.bin|devname|softdep)?
/modules.alias.bin
/modules.builtin.bin
/modules.dep.bin
/modules.devname
/modules.softdep
/modules.symbols.bin
Extended glob
The pattern you are trying to negate match with the exclamation mark is an "extended glob". Enabled somewhere in the script with a command alike shopt -s extglob.
The negation form with extended globbing syntax is defined as !(list):
!(list) Matches anything but the given patterns.
The inverse of that negative match in this case is the syntaxis #(list):
#(list) Matches one of the given patterns

Here document notations [duplicate]

This question already has answers here:
here-document gives 'unexpected end of file' error
(10 answers)
Closed 2 years ago.
I cannot find much explanation regarding a notation in here documents. In my shell script, I am plotting a file with gnuplot.
This code works:
gnuplot <<- EOF
set xlabel "square dimension (inches)"
set ylabel "mean survival time (seconds)"
set term png
set output "${plot_file}.png"
plot "beetle.dat" using 1:2
EOF
However, if I do not include the dash in <<- and just use <<, this code does not work and I get the following error:
./myscript: line 118: warning: here-document at line 104 delimited by end-of-file (wanted `EOF')
./myscript: line 119: syntax error: unexpected end of file
This question might have been asked before, however due to special characters not being recognized, I cannot search for it.
When you say "this code", is it that code - or is it indented ?
Heredocs by default look for a line containing ONLY the delimiter, so no leading tabs or spaces. What the "-" does is remove leading tabs, so you can indent the heredoc (both content and delimiter) prettily in line with the rest of your code.
So if your delimiter is actually indented in the code, it will only be found with the "-"
See 3.6.6 in https://www.gnu.org/software/bash/manual/html_node/Redirections.html

Why does this .BAT line split with caret fail?

Why does this .BAT line split with caret fail?
Because not only does ^ continue the line by ignoring the linefeed, it also escapes the first character of the next line. So the > is treated as a literal instead of as redirection.
You can get the exact same error result using:
type C:\temp.txt ^> C:\temp2.txt
You can fix the multiline version by putting a space before the redirection
type C:\temp.txt ^
> C:\temp2.txt
The rules are actually a bit more complex than what I have described. See jeb's explanation of how caret works at end of line

Find & replace a character in filenames from terminal

I am trying to use ren-regexp to replace a character in filenames like so:
./ren-regexp.pl "s/_/-/g" *.jpg
Which I think should replace _ with - in filenames that are jpgs, but what I get is:
./ren-regexp.pl: line 4: syntax error near unexpected token `newline'
./ren-regexp.pl: line 4: `<!DOCTYPE html>'
I also tried
perl ren-regexp.pl "s/_/-/g" *.jpg
Which resulted in lots of errors such as:
Bareword found where operator expected at ren-regexp.pl line 252, near "time class"
(Do you need to predeclare time?)
Bareword found where operator expected at ren-regexp.pl line 252, near ""js-relative-date" datetime"
(Missing operator before datetime?)
Bareword found where operator expected at ren-regexp.pl line 252, near ""2011-04-13T16:40:41-07:00" title"
(Missing operator before title?)
Number found where operator expected at ren-regexp.pl line 252, near "April 13"
(Do you need to predeclare April?)
Bareword found where operator expected at ren-regexp.pl line 262, near ""/msabramo/ren-regexp/tree/17026c762c41e2b88ed91bf78b63e54859b706e5" class"
(Missing operator before class?)
I tried using the examples shown on the GitHub page as well as here:
Mass replace characters in filenames from terminal?
Where am I going wrong? Running just 'perl ren-regexp.pl' by itself also results in the above set of errors.
It looks like you downloaded the script from
https://github.com/msabramo/ren-regexp/blob/master/ren-regexp.pl
instead of
https://raw.github.com/msabramo/ren-regexp/master/ren-regexp.pl
The former link will actually give you an HTML document that is unsuitable for passing into perl.
Or you could view the first link in a browser, and then copy and paste the Perl code to a file (and strip the line numbers).

Compiling and executing the Shakespeare Programming Language translator spl2c on Mac OS X 10.6 results in warnings/errors

I wanted to experiment with the Shakespeare programming language, so I downloaded it from here and executed the Makefile using cd spl-1.2.1 Make.
The compilation of spl2c executes with a couple warnings:
scanner.l:600: warning, rule cannot be matched
<stdout>:5808: warning: ‘yyunput’ defined but not used
And then when it attempts to compile all the examples everything goes haywire:
../spl/bin/spl2c < fibonacci.spl > fibonacci.c
Warning at line 19: equality expected
Warning at line 28: equality expected
Warning at line 30: comment expected
Warning at line 30: comment expected
Warning at line 30: comment expected
Warning at line 30: comment expected
Warning at line 32: comment expected
Warning at line 32: comment expected
Warning at line 32: comment expected
Warning at line 32: comment expected
Warning at line 34: comment expected
Warning at line 34: comment expected
Warning at line 34: comment expected
Warning at line 34: comment expected
Warning at line 36: comment expected
Warning at line 36: comment expected
Warning at line 37: comment expected
Warning at line 37: comment expected
Warning at line 37: comment expected
Warning at line 37: colon expected
Warning at line 40: equality expected
Warning at line 51: comment expected
Warning at line 51: comment expected
Warning at line 51: comment expected
Warning at line 51: comment expected
Warning at line 51: comment expected
Warning at line 51: colon expected
Error at line 59: 'act [roman number]' or 'scene [roman number]' expected
1 errors and 27 warnings found. No code output.
Can anybody point me in the right direction for fixing this? My original project was going to be learning spl, not leaning to debug compilers (I'd actually like to write my own compiler eventually, but I'd prefer to stick with my initial project for now).
I'm running OS X 10.6.2, gcc version 4.2.1 (Apple Inc. build 5646) (dot 1), flex 2.5.35, and bison (GNU Bison) 2.3.
EDIT: For simple programs not requiring gotos (e.g. hello.spl) you can get around the issue by deleting all ACT/SCENE lines except the first ACT I/SCENE I.
This is a defect in a regular expression in the lexical parser.
I forked the language.
I fixed the issue.
I notified the original authors.
Here's a release of the language that includes the fix for your enjoyment.
There are still a few warnings, but they don't seem to affect anything. Let me know if you find any other functional problems and I'll see what I can do with them.
(Roffel - this would be necromancy, if not for the fact that nobody cares about this problem.)
This problem results from a bug in Flex introduced somewhere between versions 2.5.4 and 2.5.33; that is, between the time the Shakespeare processor was written and this question was asked. The bug involves the use of the braced repetition operator with single-character arguments in a case-insensitive regular expression (e.g. i{1,3}, which is part of the Shakespeare flex specification for roman numerals); the consequence of the bug is that the case-insensitivity is lost, so that i{1,3} is expanded as though it were [iI]i?i? instead of [iI][iI]?[iI]?. That means that upper-case roman numerals with repeated characters (which is normal in Shakespeare source code) will not be correctly identified.
Kyle Cartmell's change in Marlowe uses upper-case letters in the regex instead of lower-case, which inverts the issue so that only upper-case Roman numerals work reliably.
I reported the Flex bug as https://github.com/westes/flex/issues/193. It's a one-line patch to Flex if anyone needs it in advance of the official release.
The first problem with scanner.l:600: warning, rule cannot be matched is because the word rotten has been added two times to the file include/negative_adjective.wordlist just remove it from there and the first warning will be removed. This does not fix the rest though. Having a look here if I can fix anything more.

Resources