Sublime Forum

How to replace dots (.) with slashes (/) when using `file_regex`?

#1

I am implementing a goto file/function with file_regex on my Python Projects build systems. For example, when I am using the following build system:

{
	"folders":
	[
		{
			"path": ".",
		}
	],
    "build_systems":
    [
        {
            "name": "Run Project",
            "file_regex": "^\\d\\d:\\d\\d:\\d\\d:\\d\\d\\d.\\d\\d\\d\\d\\d\\d \\d.\\d\\de-\\d\\d - (\\w+(?:\\.\\w+(?!\\.\\w+:))*)[^:]+:(\\d+) - (.*)$",
            "shell": true,
            "env": {"PYTHONIOENCODING": "utf8"},
            "syntax": "Packages/Text/Plain text.tmLanguage",
            "working_dir": "$project_path/source",
            "shell_cmd": "python unit_tests.py -v TestChomskyGrammar.test_grammarInvalidNonTerminalException -f",
        },
    ],
}

And some python log mine on the output.exec build panel has:

23:32:13:530.091047 1.22e-04 - grammar.grammar.<module>:58 - Importing grammar.grammar
23:32:13:657.607079 1.54e-04 - source.<module>:60 - Importing __main__

And I double click on the first line, I got this on the Sublime Text console:

found result file, line, col of [grammar.grammar], [58], [Importing grammar.grammar] full path: /D/grammar.grammar
Unable to open /D/grammar.grammar

It is not interpreting the dot (.) as a file path separator. How can I intercept the file_regex results before Sublime Text tries to open the file and replace the dots (.) with slashes (/)? So /D/grammar.grammar becomes /D/grammar/grammar?

One way I can think of, is to implement my own system of file_regex, like my_file_regex and when I double click on the output build panel, I perform my custom go to file and open the file by myself, without relying on Sublime Text internals result_file_regex voodoo. (by creating a mouse bind I can detect a double click by timing the differences between the clicks, get the current line, apply my my_file_regex, extract the capturing groups and finally open the file replacing dots (.) with slashes (/))

Related threads:


0 Likes

#2

Here is a solution: sublime_text_full_regex_build.md

For more related threads on this topic:

0 Likes

#3

Try this,
Replace /'/'/g with /[/]/g

  • / - start of the regex
  • [/] match characters inside square brackets
  • /g end of the regex
0 Likes