How do I get nest syntax highlight in Vim to actually highlight the syntax?
I'm working on a syntax file for a language where strings can contain code from other languages, specifically, SQL, Groovy, JavaScript, PHP and AppleScript. I'm just trying to get the first one working and hoping to make it easy on myself by beginning such strings with a comment in the embedded language that specifies what the language is. Here's an example:
ExecuteSQL( "/*lang=sql*/ SELECT *
FROM table
WHERE id = ?";
""; "";
456
)
In my syntax file I have the following lines of code:
runtime! syntax/sql.vim
unlet b:current_syntax
syntax include #sql_code syntax/sql.vim
syntax region fm_sql_code start /"\/\*lang=sql\*\// keepend end=/\v"/ contains=#sql_code
At the moment this code is at the end of my syntax/plugin.vim file. But I've also tried putting the code in ftplugin/plugin.vim but using autocmds to execute it:
au FileType fmcalc runtime! syntax/sql.vim
au FileType fmcalc unlet b:current_syntax
au FileType fmcalc syntax include #sql_code syntax/sql.vim
au FileType fmcalc syntax region fm_sql_code start /"\/\*lang=sql\*\// keepend end=/\v"/ contains=#sql_code
So far the location of the code hasn't changed the result.
I have a mapping that allows me to see the syntax stack for the current character by pressing <c-s-p>.
The result is that with the above, when my cursor is in the string I see the stack as ['fm_sql_code', 'sqlString']. So it's detecting the embedded syntax but flagging it as a string. The problem is that the text isn't highlighted as SQL language code, just as a string literal.
My first thought was that it was doing this because the regex I'm using for the region is including the double-quotes, so I tried changing that to the following:
syntax region fm_sql_code start=/"\#=\/\*lang=sql\*\// keepend end=/"\#=/ contains=#sql_code
But that fails to see the strings as SQL at all. The syntax stack for the above example returns ['fm_string_literal'], which is the default syntax name for strings.
Any help would be appreciated.
let csyn = b:current_syntax
unlet b:current_syntax
syntax include #sql syntax/sql.vim
syntax region sqlSnip start='\(\)\(/\* *lang=sql *\*/\)\#=' end='\(\)"\#=' contains=#sql containedin=ALL
let b:current_syntax = csyn
unlet csyn
EDIT:
Temporarily unsetting b:current_syntax is required since Vim syntax files are usually not loaded when the variable exists. For example, syntax/sql.vim starts as follows:
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
Related
I'm brand new to using PBI but as far as I can tell, I should be able to substitute a parameter as part of a Direct Query in place of a hard-coded variable...ie
let
Source = Sql.Database("NAMEOFDB", "CMUtility", [Query="sp_get_residentsinfo "& home_name]),.....
instead of
let
Source = Sql.Database("NAMEOFDB", "CMUtility", [Query="sp_get_residentsinfo 'NAME OF HOME'"]),...
However, the parameter-included version just says
DataSource.Error: Microsoft SQL: Incorrect syntax near 'House'.
Details:
DataSourceKind=SQL
DataSourcePath=NAMEOFDB;CMUtility
Message=Incorrect syntax near 'House'.
Number=102
Class=15
"House" is the currently - assigned last word of the home_name variable. What have I done wrong?
PS - I have surmised that I shouldn't need the extra & at the end of the parameter, as I'm not adding anything else to the query, but even with both &s it still doesn't work.
The type of your parameters is text. In SQL, text literals must be quoted, i.e. sp_get_residentsinfo 'NAME OF HOME', but the statement build by you is sp_get_residentsinfo NAME OF HOME.
You should use Text.Replace to escape single quotes in the parameter's value and append a quote before and after it.
In a c++ project, I'm writing a parser to read from and write to .ics files. To do that, I test my parser against several files with a maximum of possible cases, from several sources (gmail, yahoo, ...). Recently I found in a test file a situation that leaves me a little confused, and for which I could not find a satisfactory answer.
One of my test file failed to be imported by my parser. The VEVENT that cause the issue contains the following start date:
DTSTART;TZID=GMT+04:00:20120103T120000
This event match with a VTIMEZONE, that declares his TZID parameter as follow:
TZID:GMT+04:00
AFAIK the ":" char should be instead used as separator, and I suspect that the VTIMEZONE itself is malformed in the sample described above, but I didn't find any document that explicitly specifies that this situation can never happen. I also noticed that several apps like Thunderbird also fail to import this file, apparently for the same reason.
So my question is: can a TZID parameter in a VTIMEZONE contain a ":" char?
Also, I don't know if I should use the TZID content as a key to extract the ISO date from the DTSTART parameter, or if I do simply reject a such event, tagging it as corrupted, and showing an error message after the importation?
The authority on this is RFC5545 and the relevant subsections:
RFC5545 3.2.19. Time Zone Identifier
tzidparam = "TZID" "=" [tzidprefix] paramtext
which is complemented by
RFC5545 3.1. Content Lines
param = param-name "=" param-value *("," param-value)
param-value = paramtext / quoted-string
paramtext = *SAFE-CHAR
[..]
SAFE-CHAR = WSP / %x21 / %x23-2B / %x2D-39 / %x3C-7E
/ NON-US-ASCII
; Any character except CONTROL, DQUOTE, ";", ":", ","
From which we can conclude that a Time Zone ID parameter cannot contain a ":" char.
On VAX/VMS (or OpenVMS Alpha and its other names) there was an editor called TPU. In TPU you could enable selection of text independently of holding a key down. You pressed SELECT and then any cursor movement you made selected text between the editing point and the new cursor location.
You could also record macros. So you could use this text selection feature to create macros like:
find "abc"
select
find "xyz"
cut
stop recording
So this macro would find any line with "abc" in it and then cut all text between "abc" and "xyz". Massive time saver.
Making sense? How can I do that in VS2015? I can't find a macro extension that provides the selection behaviour I need to do this.
Cheers,
.pd.
EDIT
It occurred to me this could be done with a regex but it seems like a pretty big ask.
#Html.DropDownListFor(m => m.Property, Model.SelectListProperty, htmlAttributes: new { #class="whatever" })
// the regex would replace this with
#Html.MyDropDownListFor(m => m.Property, Model.SelectListProperty, Model.Property, htmlAttributes: new { #class="whatever"})
So I would be looking for a regex to
- find #Html.DropDownList
- replace the token 1 of that line split by ',' with token 1 of token 0 split by '.' and prefixed with "Model."
Assuming Model.Property comes from m => m.Property.
Search for
#Html\.DropDownListFor\(((\w+)\s*=>\s*\2\.(\w+)),\s*(Model\.\w+)(,(?:[^(){}]|\{[^{}]*\})*)?\)
Replace with
#Html.MyDropDownListFor($1, $4, Model.$3$5)
Demo: http://regexr.com/3f3io
How to filter all names that consist of numbers and end with .jpg and/or _number.jpg?
Background info:
In SSIS 2008 I have a foreach loop that will store the filename into a variable for all jpg files. The enumorator configuration for Files is currently: *.jpg
This will handle all jpg files.
What is the code so it will only handle names likes?:
3417761506233.jpg
3417761506233_1.jpg
5414233177487.jpg
5414233177487_1.jpg
5414233177487_14.jpg
but not names like:
abc.jpg
abc123.jpg
def.png
456.png
The numbers represent EAN codes by the way.
I thought about this code:
\d|_|.jpg
but SSIS returns an error stating there are no files that meet the criteria eventhough the files(names) are in the folder.
You could use a Script Task within the loop to do the regex filtering:
http://microsoft-ssis.blogspot.com/2012/04/regex-filter-for-foreach-loop.html
Or you could use a (free) Third Party Enumerator:
http://microsoft-ssis.blogspot.com/2012/04/custom-ssis-component-foreach-file.html
For that, you can use the following regex:
^\d+(_\d+)?.jpg$
Demo: http://regex101.com/r/qC7oV3
^(\d+(?:_\d+)?\.jpg$)
DEMO --> http://regex101.com/r/dM9rJ7
Matches:
3417761506233.jpg
3417761506233_1.jpg
5414233177487.jpg
5414233177487_1.jpg
5414233177487_14.jpg
Excludes:
abc.jpg
abc123.jpg
def.png
456.png
Ive been following the tutorial on how to use mallet in R to create topic models. My text file has 1 sentence per line. It looks like this and has about 50 sentences.
Thank you again and have a good day :).
This is an apple.
This is awesome!
LOL!
i need 2.
.
.
.
This is my code:
Sys.setenv(NOAWT=TRUE)
#setup the workspace
# Set working directory
dir<-"/Users/jxn"
Dir <- "~/Desktop/Chat/malletR/text" # adjust to suit
require(mallet)
documents1 <- mallet.read.dir(Dir)
View(documents1)
stoplist1<-mallet.read.dir("~/Desktop/Chat/malletR/stoplists")
View(stoplist1)
**mallet.instances <- mallet.import(documents1$id, documents1$text, "~/Desktop/Chat/malletR/stoplists/en.txt", token.regexp ="\\p{L}[\\p{L}\\p{P}]+\\p{L}")**
Everything works except for the last line of the code
**`**mallet.instances <- mallet.import(documents1$id, documents1$text, "~/Desktop/Chat/malletR/stoplists/en.txt", token.regexp ="\\p{L}[\\p{L}\\p{P}]+\\p{L}")**`**
I keep getting this error :
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
java.lang.NoSuchMethodException: No suitable method for the given parameters
According to the package, this is how the function should be:
mallet.instances <- mallet.import(documents$id, documents$text, "en.txt",
token.regexp = "\\p{L}[\\p{L}\\p{P}]+\\p{L}")
I believe it has something to do with the token.regexp argument as
documents1 <- mallet.read.dir(Dir) works just fine which means that the first 3 arguments supplied to mallet.instances was correct.
This is a link to the git repo that i was following the tutorial from.
https://github.com/shawngraham/R/blob/master/topicmodel.R
Any help would be much appreciated.
Thanks,
J
I suspect the problem is with your text file. I have encountered the same error and resolved it by using the as.character() function as follows:
mallet.instances <- mallet.import(as.character(documents$id),
as.character(documents$text),
"en.txt",
FALSE,
token.regexp="\\p{L}[\\p{L}\\p{P}]+\\p{L}")
Are you sure you converted the id field also to character ? It is easy to overlook the advice and leave it as an integer.
Also there is a typo in the code sample: the backslashes have to be escaped:
token.regexp = "\\p{L}[\\p{L}\\p{P}]+\\p{L}"
This usually occurs because the html text editor eats up one backslash.