简体   繁体   English

编写编译模式正则表达式

[英]Writing compilation mode regexps

The final working solution that takes into account line and column ranges: 考虑行和列范围的最终工作解决方案:

(csharp
 "^ *\\(?:[0-9]+>\\)*\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\),\\([0-9]+\\)) *\: \\(error\\|warning\\) *CS[0-9]+:)"
 1 (2 . 4) (3 . 5) )

Both answers below were incredibly helpful; 以下两个答案都非常有用。 I understand the system a lot better now. 我现在对系统有了更好的了解。


Summary: my regexps work to match the output strings, but don't work in the compilation-error-regexp-alist-alist to match errors in my compilation output. 简介:我的正则表达式可以匹配输出字符串,但是不能在compile-error-regexp-alist-alist中匹配我的编译输出中的错误。

I'm finding the compilation mode regexps a bit confusing. 我发现编译模式regexp有点混乱。 I've written a regex that I know works on my error string using rebuilder and the original regexes that are in compile.el. 我编写了一个正则表达式,我知道它可以使用rebuilder和compile.el中的原始正则表达式处理我的错误字符串。

40>f:\\Projects\\dev\\source\\Helper.cs(37,22,37,45): error CS1061: 'foo.bar' does not contain a definition for 'function' and no extension method 'method' accepting a first argument of type 'foo.bar' could be found (are you missing a using directive or an assembly reference?) 40> f:\\ Projects \\ dev \\ source \\ Helper.cs(37,22,37,45):错误CS1061:'foo.bar'不包含'function'的定义并且没有扩展方法'method'接受可以找到类型为'foo.bar'的第一个参数(是否缺少using指令或程序集引用?)

And here's my regexp: 这是我的正则表达式:

(pushnew '(csharp
 "^ *\\(?:[0-9]+>\\)*\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\),\\([0-9]+\\),[0-9]+,[0-9]+) *\: \\(?:error *CS[0-9]+:\\)"
 2 3)
     compilation-error-regexp-alist-alist)

Obviously, I'm just trying to get to the first line/column pair that's output. 显然,我只是试图到达输出的第一行/列对。 (I'm surprised that the compiler is outputting 4 numbers instead of two, but whatever.) (我很惊讶编译器输出的是4个数字而不是2个,但无论如何。)

If we look at the edg-1 regexp in compile.el: 如果我们在compile.el中查看edg-1 regexp:

    (edg-1
 "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
 1 2 nil (3 . 4))

So I guess where I'm confused is to how the arguments are passed. 所以我想我困惑的是如何传递参数。 In edg-1, where are 3 and 4 coming from? 在edg-1中,3和4来自哪里? I guess they don't correspond to the capture groups? 我想它们与捕获组不对应吗? If I run the edg-1 regexp through re-builder on a well-formed error message and enter subexpression mode, 0 matches the whole matching string, 1 matches the file name and path, and 2 matches the line number. 如果我在格式正确的错误消息上通过re-builder运行edg-1 regexp并进入子表达式模式,则0匹配整个匹配字符串,1匹配文件名和路径,2匹配行号。 From looking at the documentation (when I do Mx describe-variable), it appears as though it just cares about what place the subexpressions are in the main expression. 通过查看文档(当我做Mx describe-variable时),看起来好像它只是在乎子表达式在主表达式中的位置。 Either way, I'm clearly misunderstanding something. 无论哪种方式,我显然都误会了一些东西。

I've also tried modifying the official csharp.el regexp to handle the extra two numbers, but with no luck. 我也尝试过修改官方的csharp.el regexp以处理额外的两个数字,但是没有运气。

(Edit, fixed the example slightly, updated the csharp regexp) (编辑,稍微修正示例,更新了csharp regexp)

Found some info on this. 找到了一些有关此的信息。

This page has a simplified explanation: 此页面具有简化的说明:
http://praveen.kumar.in/2011/03/09/making-gnu-emacs-detect-custom-error-messages-a-maven-example/ http://praveen.kumar.in/2011/03/09/making-gnu-emacs-detect-custom-error-messages-a-maven-example/

Quote from page - 页面引用-

"Each elt has the form (REGEXP FILE [LINE COLUMN TYPE HYPERLINK
HIGHLIGHT...]).  If REGEXP matches, the FILE'th subexpression
gives the file name, and the LINE'th subexpression gives the line
number.  The COLUMN'th subexpression gives the column number on
that line"

So it looks like the format is something like this: 所以看起来格式是这样的:

(REGEXP FILE [LINE COLUMN TYPE HYPERLINK HIGHLIGHT...])

Looking at the regex again, it looks like a modified BRE. 再次查看正则表达式,它看起来像是经过修改的BRE。

 ^                   # BOS
 \( [^ \n]+ \)       # Group 1

 (                   # Literal '('
 \( [0-9]+ \)        # Group 2
 )                   # Literal ')'

 : [ ] 

 \(?:
      error
   \|
      warnin\(g\)    # Group 3
   \|
      remar\(k\)     # Group 4
 \)

Here is the edg-1 这是EDG-1

(edg-1
 "^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
 1 2 nil (3 . 4))

Where 哪里

"^\\([^ \n]+\\)(\\([0-9]+\\)): \\(?:error\\|warnin\\(g\\)\\|remar\\(k\\)\\)"
REGEXP ^^^^^^^^

 1     2    nil    (3 . 4)
 ^     ^     ^      ^^^^^
FILE LINE  COLUMN   TYPE

"TYPE is 2 or nil for a real error or 1 for warning or 0 for info.
TYPE can also be of the form (WARNING . INFO).  In that case this
will be equivalent to 1 if the WARNING'th subexpression matched
or else equivalent to 0 if the INFO'th subexpression matched."

So, TYPE is of this form (WARNING . INFO) 因此,TYPE是这种形式(WARNING。INFO)

In the regex,
if capture group 3 matched (ie. warnin\(g\) ) it is equivalent to a warning.
If capture group 4 matched (ie. remar\(k\) ) it is equivalent to info.  
One of these will match.  

csharp element info csharp元素信息

Looking at your csharp element 看着你的csharp元素

"^ *\\(?:[0-9]+>\\)?\\(\\(?:[a-zA-Z]:\\)?[^:(\t\n]+\\)(\\([0-9]+\\),\\([0-9]+\\),[0-9]+,[0-9]+) *\: \\(?:error *CS[0-9]+:\\)"
2 3 4

And your regex (below) actually doesn't have capture group 4 in it. 而且您的正则表达式(如下)实际上没有捕获组4。
So, your FILE LINE COLUMN of 2 3 4 因此,您的FILE LINE COLUMN为2 3 4
probably should be 1 2 3 大概应该是1 2 3

Here is your regex as its engine see's it - 这是您的正则表达式,因为它的引擎可以看到它-

 ^ 
 [ ]* 
 \(?:
      [0-9]+ > 
 \)?
 \(                            # Group 1
      \(?:
            [a-zA-Z] : 
      \)?
      [^:(\t\n]+ 
 \)
 (                             # Literal '('
      \( [0-9]+ \)                # Group 2
      ,
      \( [0-9]+ \)                # Group 3
      ,
      [0-9]+
      ,
      [0-9]+ 
 )                             # Literal ')'
 [ ]* \: [ ] 
 \(?:
      error [ ]* CS [0-9]+ :
 \)

My crystal ball came up with a weird explanation: compilation-error-regexp-alist-alist is just a collection of matching rules, but it doesn't say which rules to use. 我的水晶球提出了一个怪异的解释: compilation-error-regexp-alist-alist只是一组匹配规则,但没有说明要使用哪些规则。 So you need to add csharp to compilation-error-regexp-alist if you want to use your new rule. 因此,如果要使用新规则,则需要将csharp添加到compilation-error-regexp-alist

As for the meaning of (3 . 4) , see Ch v compilation-error-regexp-alist . 至于(3 . 4) Ch v compilation-error-regexp-alist (3 . 4)的含义,请参见Ch v compilation-error-regexp-alist

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM