Sublime Forum

Build system regex improvement

#4

Wow… if only that were documented somewhere, or at least somewhere I would find it. Thanks for that!

If it really was that hard to lex the output it would be pretty easy to write a pre-processor. I already have a grep on the output of Apple’s amazingly verbose Swift compiler.

Edit: It’s documented here: http://sublimetext.info/docs/en/reference/build_systems.html

0 Likes

#6

It’s mentioned in this page of the Unofficial Documentation which, if you haven’t read it, is definitely worth a look-see. It fills the gaps in the official documentation pretty well, I find. I think it’s my most used bookmark. :slightly_smiling:

0 Likes

#7

You just beat me to it.

I actually did read it when I wrote my build system fields, many moons ago, but I only needed the first two fields since column isn’t output and I don’t know if error message was added more recently or if I just ignored it becuase it wasn’t used anywhere at the time.

0 Likes

#8

I think error messages were shown on the status bar when traversing the build results with F4 (and shift+f4), but yeah, they were effectively a non-factor before inline error display.

0 Likes

#9

They do get shown on the status line! But then disappear after a few seconds.

0 Likes

#10

So, I just saw on the blog page (https://sublimetext.com/blog/) that inline error support got enabled in build 3124. I have build 3126, so technically it should be working for me except that its not. I ran my regex through a regex checker. It says in the blog that this new Phantom API functionality is accessible through a plugin, so maybe I need the right plugin. If you got it to work for C, did you use a plugin and if so which one?

0 Likes

#11

The result I posted above is from a build system that ships with Sublime itself, so it just works, no extra plugin needed.

Not all of the build systems that ship with Sublime support this particular option, though. For example, the default Python build system doesn’t support it, likely due to the way that the error message appears a couple of lines away from the line where the error file is reported.

The show_errors_inline setting needs to be turned on for this to work, although it’s enabled by default so that is probably not the issue.

0 Likes

#12

I got this to work on a single line without any additional plugins using the following regex:

"^[ ]*\"(.*?)\", line ([0-9]*)():(.*):"

This puts the error number inline error #20.

My ultimate goal however is to have the actual error text. This is complicated by the fact that its a multi-line error message. Below is an example of this error message and the regex I tried with it but unsuccessfully. It puts a single space instead of the error message, but seems to work fine in regexpal.

"file_regex": "^[ ]*\"(.*?)\", line ([0-9]*)():.*:[ \r\n]+(.*)"
----------------------- start ------------------------------
"C:\Users\myself\my_view_my_code\MY_CODE\My_Libs\libraries\sub_libs\source\SomeSource.c", line 241: error #20: 


          identifier "bytes_written" is undefined


          bytes_written = fwrite(pData, 1U, fsize, pFileWrite);


          ^





---------------------------------- end --------------------------------
0 Likes

#13

Yes. I never had to tweak the show_errors_inline setting – it was enabled.

0 Likes

#14

You might try experimenting with a (?s) prefix which causes regex to match newlines with the dot operator.

So

"file_regex": "(?s)^[ ]*\"(.*?)\", line ([0-9]*)():.*:[ \r\n]+(.*)\^"

should return a multiline error message. Note that I added the trailing caret to terminate the matching according to your example.

0 Likes

#15

Remember to double-escape your backslashes because the regular expression is inside a JSON string.

1 Like

#16

Is there a simple way to make the inline error appear at the end of the line of the error instead of below? IN my case I have no column information.

I’m guessing I’m going to have to hack my theme file.

0 Likes

#17

For those interested in how to do this, you can do a quick and dirty hack to your exec.py file:

  • change line 438 to sublime.Region(view.line(pt).end(), view.line(pt).end()),
  • change line 444 to sublime.LAYOUT_INLINE,

I also changed the phantomCss key in my theme file so that the inline errors looked the way I wanted them to, in particular I added display: inline; to div.error so that the inline fit within the source line.

0 Likes

#18

This seems to rely on the error string containing the information in a certain order. How do you handle error messages that contain the information in a different order? Or that have a different format depending on whether it’s a warning or an error?

0 Likes

#19

The obvious solution would be using named groups, but is anyone actually having this problem?

0 Likes

#20

You either translate the error messages to something that build results regexps can work with, or you don’t.
What I’m saying is that you need a custom build system and modify the output from your executable. I’m doing this in CSScheme.

Related:

1 Like

#21

Yes, I am having this problem with a particular hardware simulation tool. A related problem is that the tool in question has at least 3 different formats for error messages, but I’ve managed to work around that one with some regex sophistry.

0 Likes

#22

Yeah, as FichteFoll says, piping error output through some utility that makes it sane seems to be a fact of life since tool writers seem to find so many novel ways to screw up error reporting. I do that with a hyper-verbose compiler which seems to think 10+ lines of output for each error or warning is a good idea.

1 Like

#23

Yes, that seems like a reasonable workaround, but I think the more elegant solution would be to add some flexibility to Sublime on this. Since Sublime is script-able, why not provide a way to script this rather than the simplistic regex? Even supporting named groups in the regex would help a lot.

1 Like

#24

The entire build system is scripted in Python from what I can tell. If you go into the “Default” package and look at exec.py you’ll find code for the build system. I’ve already hacked that to change the inline errors as per my above comment, I’m sure you could replace the regexes too, but I haven’t looked into it.

0 Likes