Sublime Forum

file_regex parse error

#1

I am currently trying to create a build system however I am now a little stumped, when my build system fails to compile the code I get an error not unlike …

Compile Error: Missing Type specifier
[C:/Users/user account/Desktop/Test/TestMessage2.bmx;3;16]
Build Error: failed To compile C:/Users/user account/Desktop/Test/TestMessage2.bmx

Now I have managed to whip up a snippet of regex that can pick out the file like so;

“file_regex”: “(?<=)(.*?)(?=;)”

This selects the file from (but not including) upto the ; (not including as well)

If I drop that in the file_regex of the build system I am working on it fails to work, report ‘Error trying to parse, invalid escape’ when I try and build the file that causes an issue.

Any idea what I am doing wrong?

0 Likes

#2

Keep in mind that strings require escaping and regex requires escaping.

“” will never make it to the regex and it means nothing to the string?.

You need to escape your string escapes to have them make it to the regex parsing.

(?<=\\)(.*?)(?=\\;)

That should get you heading in the right direction.

0 Likes

#3

Sweet, thats what it was, just needed to escape it!. Many Thanks.

Now once a error occurs I tap F4 and the correct file opens with the above snippet. However its not putting the cursor at the right point

using

((?<=\)(.?)(?=\;))|((?<=\;)(.?)(?=\;))|((?<=\;)(.*?)(?=\]))

will let me select the file, line then column however I can not seem to get it to work as expected

0 Likes

#4

I thought (maybe very wrongly!) that in order to have the goto error working you needed to specify line and column in the same file_regex ?

0 Likes

#5

Ahaa!

got it to work with!

“file_regex”: “((?<=\).*?(?=\;))\;([0-9]+)\;([0-9]+)\]”

0 Likes

#6

Right after much more playing around I have get this to work

“file_regex”: “((?<=\).*?(?=\;))\;([0-9]+)\;([0-9]+)”,

All good and dandy, as I expect group 1 = filename, group 2 = line number, group 3 = column
Now trying to get the error message is proving beyond my current ability.

An example of the error message is;

Compile Error: Missing Type specifier
[C:/Users/user account/Desktop/Test/TestMessage2.bmx;3;16]
Build Error: failed To compile C:/Users/user account/Desktop/Test/TestMessage2.bmx

I tried to make group 4 yank the error message by doing … ((?<=\).?(?=\;))\;([0-9]+)\;([0-9]+)|(compile error: .) but that does not work

any pointers on how to get the error to group 4?

0 Likes

#7

Well, first off, regex is case sensitive by default…so

compile error: != Compile Error:

0 Likes

#8

((?<=\).?(?=\;))\;([0-9]+)\;([0-9]+)|(Compile Error: .)

Yep your right, correcting the case of the compile error still does not do what I want it too.

0 Likes

#9

Can you post an example of the entire thing you are trying to target with regex? I kind of would need to see the error in context with everything else you are targeting to be any real help.

0 Likes

#10

The build system I am trting to make is for BlitzMax (blitzmax.com)

the build file is as;

{
	"cmd": "bmk.bat", "release", "single", "fast", "console", "$file"],
  	"file_regex": "((?<=\\).*?(?=\\;))\\;([0-9]+)\\;([0-9]+)",
  	"selector": "source.BlitzMax"
}	

The above calls a .bat file to compile (and run) the application, should an error occur when its compiled the output in the console looks like;

Compiling:TestProg2.bmx

Compile Error: Missing type specifier
[C:/Users/user account/My Projects/Sandbox/Sublime Text 2 blitzmax plugin/Example bmx Source/CompileTest/TestProg2.bmx;3;16]
Build Error: failed to compile C:/Users/user account/My Projects/Sandbox/Sublime Text 2 blitzmax plugin/Example bmx Source/CompileTest/TestProg2.bmx[Finished]

The regex I provided above does work a treat. When the error occurs after I build I can press F4 and the edit cursor is moved to the error in question.

As I understand it;
Group 1 of the file_regex shows the filename of the error
Group 2 of the file_regex shows the line number in that file
Group 3 of the file_regex shows the column in that file
Group 4 is the error message

Providing group 4 on the end like so;

  	"file_regex": "((?<=\\).*?(?=\\;))\\;([0-9]+)\\;([0-9]+)|(Compile Error: .*)",

Does not work as I expected it too.

Break down of the groups…

Group 1 = ((?<=\\).*?(?=\\;))
Group 2 = ([0-9]+)
Group 3 = ([0-9]+)
Group 4 = (Compile Error: .*)

Any idea how I can get the error message working.

As I understand it, when Group 4 is working as expected I should see the error message in the Status Bar of Sublime Text 2 when I press F4

0 Likes

#11

Try something more like this:

(Compile Error:\\w\\W]+)((?<=\\).*?(?=\\;))\\;([0-9]+)\\;([0-9]+)

Group 1 = (Compile Error:\\w\\W]+) Group 2 = ((?<=\\).*?(?=\\;)) Group 3 = ([0-9]+) Group 4 = ([0-9]+)

**Edit: ** Don’t forget to escape stuff; I didn’t in my example here.
**Edit2: ** Added escapes

0 Likes

#12

Tried it and it does not work

As I understand these groups they are;

Group 1 needs to be the file name of the file with the error
Group 2 needs to be the line number
Group 3 needs to be the char on that line
Group 4 needs to be the error message

Swapping them around does not work, as a matter of fact it causes the already working group 1 to 3 to not work any more. :mrgreen:

0 Likes

#13

Here I simplified the regex and fixed some issues related to brackets:

(Compile Error:\\w\\W]+)(?:\\n|\\r\\n)\\(.*?)\\;([0-9]+)\\;([0-9]+)\\]

This is what it targeted:


This is my replacement output

group1: Compile Error: Missing type specifier group2: C:/Users/user account/My Projects/Sandbox/Sublime Text 2 blitzmax plugin/Example bmx Source/CompileTest/TestProg2.bmx group3: 3 group4: 16

0 Likes

#14

I think you’ll be out of luck with this error message. I think it’s a shortcoming of the build system.

The build system expects you to provide a regex that matches the file name, line number, column number, and error message, in that order. But your compiler emits the error message first.

IWBNI either named groups (parentheses) were used (does this feature exist?) or the build system spec allowed you to specify which group matches the file name and so on. Since you have a real need for this, you might be successful if you submit a feature request at sublimetext.userecho.com/.

0 Likes

#15

[quote=“hibbelig”]I think you’ll be out of luck with this error message. I think it’s a shortcoming of the build system.

The build system expects you to provide a regex that matches the file name, line number, column number, and error message, in that order. But your compiler emits the error message first.

IWBNI either named groups (parentheses) were used (does this feature exist?) or the build system spec allowed you to specify which group matches the file name and so on. Since you have a real need for this, you might be successful if you submit a feature request at sublimetext.userecho.com/.[/quote]

Ahh. The missing puzzle piece. From looking at his regex, I assumed he was having a regex issue. But it appears that even with regex that can match what he wants, he is still out of luck. Thanks for the info; I haven’t really used the this particular feature much.

0 Likes

#16

Aha, so that be the issue.

I guess a seperate ‘file_regex’, ‘line_regex’, ‘column_regex’ and ‘error_regex’ would do it as well.

0 Likes