Using Sublime Text 2 Build System with SQL*Plus and Oracle - regex

I'm trying to setup Sublime Text 2 so that I can code my Oracle packages, triggers, functions, etc. I have the build system compiling my code just fine. Now I'm working on trying to get Sublime Text to take me to the exact line/column position when an error happens. To do this you have to use the file_regex option documented here.
The file_regex option uses a Perl-style regular expression to capture
up to four fields of error information from the build program’s
output, namely: filename, line number, column number and error
message. Use groups in the pattern to capture this information. The
filename field and the line number field are required.
My problem seems to be filename, which is the first required thing. My question is at the very bottom but let me show you how everything is setup because others may find this useful.
Here is my build system (compileSql.sublime-build)...
{
"cmd": ["c:\\projectX\\compileSql.bat", "$file"],
"file_regex": "^([0-9]+)/([0-9]+)"
}
Here is compileSql.bat. All this does is it makes a new file called runFile.txt which contains the file I'm currently working on in Sublime text, except it starts the file off with set defined off;, then my code, then ends with show errors; It then logs in and compiles the package (trigger, function, whatever)...
#echo set define off; > c:\projectX\runFile.txt
type %1 >> c:\projectX\runFile.txt
#echo show errors; >> c:\projectX\runFile.txt
sqlplus -s {user}/{pwd}#{database} #c:\projectX\runFile.txt
So all I have to do is press F7 and it compiles for me...
But when I get an error, this is the result...
When I click on the error is doesn't take me to that line number. Instead it opens a file called 8. So back up to my build system, I know the problem is with this: "file_regex": "^([0-9]+)/([0-9]+)". Sublime Text 2 requires the first matched pattern to be the file. That's the part I'm not grasping, why does it need to know that? It's the file I'm working on, the one I just pressed F7 for. So something needs to come before the ([0-9]+)/([0-9]+) in the regular expression, I don't know what to put in there.

Related

Build system regex captures

I am trying to filter the output of my build system in SublimeText3.
First of all, can someone explain the difference between:
"file_regex": "",
"line_regex": "",
I want to catch the following line from this example output:
Compile success 0 Errors 0 Warnings Analysis time : 15.0 [ms]
.
VHDL/Verilog/EDIF/SystemC Simulator build 10.3.3558.6081
(c) 1997-2016 Aldec, Inc. All rights reserved.
License Number 0
Welcome to VSIMSA!
This message was printed from `startup.do' macro file.
# creating library
alib work
ALIB: Library `work' attached.
Compile success 0 Errors 0 Warnings Analysis time : 31.0 [ms]
Compile Package "BT601_cfg"
Compile success 0 Errors 0 Warnings Analysis time : 15.0 [ms]
# starting simulation with tb_top as the top level module
# asim fpc_tb
# running the simulation
# run 1000us
echo hi
hi
quit
First of all, can someone explain the difference between:
"file_regex": "",
"line_regex": "",
The file_regex is used in sublime-build systems to capture the locations of warnings, errors or things of that type to allow you to directly navigate to the associated location in the file that generated the message.
The regex should match on such lines by including anywhere from one to four regex captures which capture the following information:
file name
line number
column number
message text
The captures have to appear in this order, so if for example there is no column number but there is message text, you need to include an empty regex capture so that the capture on the message text is the fourth one.
The file and line/column information are used to allow Sublime to directly open the file and position the cursor at the appropriate location. The file name can be a relative path, in which case the folder set as the working_dir in your build file is used to determine where the file can actually be found.
The text of the message would be used for things such as inline error messages attached to the file window with phantoms, if you happen to have the appropriate feature turned on.
The line_regex is only needed in cases where the tool that you're running displays the name of the file on a line different than the line that contains the error.
In that case, you should provide a line_regex that has the following captures:
line number
column number
message text
If there is a line_regex set and it matches on a line, Sublime will look backwards through the results to find the first line that matches the file_regex you provided, allowing it to pick up the name of the file as well.
While you're working on setting up a build system, it can sometimes be helpful to open the Sublime console by selecting View > Show Console from the menu or pressing the associated key.
From there you can enter the following command and press enter:
sublime.log_result_regex(True)
This will get Sublime to log to the console what it's finding, so you can see if things are working as expected.
For example, given this example:
int main(int argc, char const *argv[])
{
printf("Hello, World!\n");
}
Building with the shipped C++ Single File build system generates the following output in the console:
Running g++ "/home/tmartin/test.c" -o "/home/tmartin/test"
found result file, line, col of [/home/tmartin/test.c], [3], [29] full path: /home/tmartin/test.c
More information on this topic can be found in the Official documentation as well as in the Unofficial documentation (linked here are the build system sections of both documentation sets).
I want to catch the following line from this example output:
Compile success 0 Errors 0 Warnings Analysis time : 15.0 [ms]
Since these regex values are for capturing the actual errors and warnings, it doesn't make sense to capture this particular line since it's not allowing you to navigate anywhere.
For your regex, you have to escape the \[ms\] or else this would mean a character set which would match m or s.
You also have 2 consecutive white spaces at 2 places (After Warnings and after time :) in your string instead of 1. These can be matched with just 2 white spaces.
You could update your regex to:
^Compile success [0-9]+ Errors [0-9]+ Warnings Analysis time : [0-9]+\.[0-9]+ \[ms\]

Search for multiple strings in several files with Sublime 3 using AND

This previous (similar) question of mine Search for multiple strings in several files with Sublime 3 was answered with a way to search for multiple strings in multiple files in SublimeText, using the regex OR operator:
Find: (string1|string2)
Where: <open folders>
This works perfectly for searching files where either string1 OR string2 is present. What I need now is to search in lots of files for both strings present. I.e., I need to use the AND operator.
I looked around this question Regular Expressions: Is there an AND operator? and also this one Regex AND operator and came up with the following recipes:
(?=string1)(?=string2)
(?=.*string1)(?=.*string2)
(string1 string2)
(string1\&string2)
but none of them work.
So the question is: how can I search multiple strings in several files at once with SublimeText?
(I'm using SublimeText 3103)
Add: the strings are not necessarily in the same line. They can be located anywhere within each file. For example, this file:
string1 dfgdfg d dfgdf
sadasd
asdasd
dfgdfg string2 dfgdfg
should trigger a match.
Open sublime Text and press
Shift+Ctrl+F
or click on the Find in Files options under Files tab. The above is keyboard shortcut for this option. When you press above key, these are following options
When you select ... button from above, you get 6 options which are Add Folder or Add Open Files or Add Open Folders
To search strings that occur in the same line
Use the following regex for your and operation
(?=.*string1)(?=.*string2)
I am using the following regex
(?=.*def)(?=.*s)\w+ <-- \w+ will help in understanding which line is matched(will see later)
and I am searching within current open files
Make sure the Use Buffer option is enabled (one just before Find). It will display the matches in a new file. Also make sure the Show Context (one just before Use Buffer) option is enabled. This will display the exact line that matches. Now Click on Find on the right side.
Here is the output I am getting
See the difference in background color of line 1315 and 1316(appearing in left side). 1316 is matched line in designation file
This is the image of last part
There were total 6 files that were opened while I used this regex
For finding strings anywhere in file
Use
(?=[\s\S]*string1)(?=[\s\S]*string2)[\s\S]+
but it will kill sublime if number of lines increases.
If there are only two words that you need to find, the following will work super fast in comparison to above
(\bstring1\b[\S\s]*\bstring2\b)|(\bstring2\b[\S\s]*\bstring1\b)

Notepad ++ Regular Expression on finding missing {/}

I have one big file filled with custom text and scripts, that are used by one software, it crashes because of one problem
The software display whole text throught
{#HEXCOLOR}TEXT TEXT TEXT{/}
for example
{#FF00FF}Hello{/}
as we can see the whole text is inside custom script that starts from {#HEXCOLOR} and ends with {/} but in some lines the "{/}" is missing, that make program crash.
for example
{#FF00FF}Hello
It is possible some how to search for missing {/} in the file via Regular Expression ?
I tried by myself but failed:
{#[^{}]}.?{/[^{}]*}
you could use this pattern
({#[^}]+}[^{\r\n]+)(?={#|$)
and replace with \1{/}
Demo

Writing an interpreter in C++

I'm working on a C++ project which should do following operations:
Open a .txt file which contains list of strings
(for example String1: "Hi,name_1_is,;Ondrej,age24;year,,88;") with optional values determined by empty commas ",,".
After this check each string using regular expressions for valid input
(like "Hi" shouldn't be a number or "1" must be a number and everything with ",," is optional and can be skipped or user can enter this value as well).
Then evaluate the result and save it to variable or new .txt generated file.
This result shows if whole string is correct with an "ok" message attached to it or it will attach "not ok" message right to the parameter with wrong input.
I have already finished the part with opening a .txt file, checking the whole string and saving the right strings to the new file (using Qt and Visual Studio 2010 Express).
I need to do the part where each parameter will be checked but somehow I don't know how exactly, as I should not build Parser but the whole programm must be build like Interpreter.
Actually I'm stucked at this point because I have no idea how to start to build this like an Interpreter.
All my attempts resulted always with structure similar to Parser
(that means: I used split string, then checked each token or char using regex, then built the string together again, ect.)
Could you provide me with some usefull links or tips of how to achieve that or at least where to start at all please?

Can Notepad++ save out search results to a text file?

I need to do quite a few regular expression search/replaces throughout hundreds and hundreds of static files. I'm looking to build an audit trail so I at least know what files were touched by what searches/replaces.
I can do my regular expression searches in Notepad++ and it gives me file names/paths and number of hits in each file. It also gives me the line #s which I don't really care that much about.
What I really want is a separate text file of the file names/paths. The # of hits in each file would be a nice addition, but really it's just a list of file names/paths that I'm after.
In Notepad++'s search results pane, I can do a right click and copy, but that includes all the line #s and code which is just too much noise, especially when you're getting hundreds of matches.
Anyone know how I can get these results to just the file name/paths? I'm after something like:
/about/foo.html
/about/bar.html
/faq/2012/awesome.html
/faq/2013/awesomer.html
/foo/bar/baz/wee.html
etc.
Then I can name that file regex_whatever_search.txt and at the top of it include the regex used for the search and replace. Below that, I've got my list of files it touched.
UPDATE What looks like the easiest thing to do (at least that I've found) is to just copy all the search results into a new text file and run the following regex:
^\tLine.+$
And replace that with an empty string. That'll give you just the file path and hit counts with a lot of empty space between each entry. Then run the following regex:
\s+\n
And replace with:
\n
That'll strip out all the unwanted empty space and you'll be left with a nice list.
maybe you need power of unix tools
assume you have GNUWin32 installed in c:\tools\gnuwin32
than if you have replace.bat file with that content:
#echo off
set BIN=c:\tools\gnuwin32\bin
set WHAT=%1
set TOWHAT=%2
set MASK=%3
rem Removing quotes
SET WHAT=###%WHAT%###
SET WHAT=%WHAT:"###=%
SET WHAT=%WHAT:###"=%
SET WHAT=%WHAT:###=%
SET TOWHAT=###%TOWHAT%###
SET TOWHAT=%TOWHAT:"###=%
SET TOWHAT=%TOWHAT:###"=%
SET TOWHAT=%TOWHAT:###=%
SET MASK=###%MASK%###
SET MASK=%MASK:"###=%
SET MASK=%MASK:###"=%
SET MASK=%MASK:###=%
echo %WHAT% replaces to %TOWHAT%
rem printing matching files
%BIN%\grep -r -c "%WHAT%" %MASK%
rem actual replace
%BIN%\find %MASK% -type f -exec %BIN%\sed -i "s/%WHAT%/%TOWHAT%/g" {} +
you can do regex replace in masked files recursively with output you required
replace "using System.Windows" "using Nothing" *.cs
The regulat expression I use for this kind of problem is
^\tLine.[0-9]*:.
And it works for me
This works well if you have Excel available and want to avoid using regular expressions:
Ctrl+A to select all the results
drag & drop the selected results to Excel
Create a Filter on the 1st row
Filter out the lines that have "(Blank)" on the 1st column
Select the remaining lines (i.e. the lines with the filenames) and copy/paste them to another sheet or any wanted destination
You could also Ctrl+A, Ctrl+C the search results, then use the Paste Option "Use Text Import Wizard" in Excel, say that the data is "Fixed width" and put one single break line after the 2nd character (to remove the two leading spaces in the filename during import), and use a filter to filter out the unwanted rows.