繁体   English   中英

编写编译模式正则表达式

[英]Writing compilation mode regexps

考虑行和列范围的最终工作解决方案:

(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) )

以下两个答案都非常有用。 我现在对系统有了更好的了解。


简介:我的正则表达式可以匹配输出字符串,但是不能在compile-error-regexp-alist-alist中匹配我的编译输出中的错误。

我发现编译模式regexp有点混乱。 我编写了一个正则表达式,我知道它可以使用rebuilder和compile.el中的原始正则表达式处理我的错误字符串。

40> f:\\ Projects \\ dev \\ source \\ Helper.cs(37,22,37,45):错误CS1061:'foo.bar'不包含'function'的定义并且没有扩展方法'method'接受可以找到类型为'foo.bar'的第一个参数(是否缺少using指令或程序集引用?)

这是我的正则表达式:

(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)

显然,我只是试图到达输出的第一行/列对。 (我很惊讶编译器输出的是4个数字而不是2个,但无论如何。)

如果我们在compile.el中查看edg-1 regexp:

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

所以我想我困惑的是如何传递参数。 在edg-1中,3和4来自哪里? 我想它们与捕获组不对应吗? 如果我在格式正确的错误消息上通过re-builder运行edg-1 regexp并进入子表达式模式,则0匹配整个匹配字符串,1匹配文件名和路径,2匹配行号。 通过查看文档(当我做Mx describe-variable时),看起来好像它只是在乎子表达式在主表达式中的位置。 无论哪种方式,我显然都误会了一些东西。

我也尝试过修改官方的csharp.el regexp以处理额外的两个数字,但是没有运气。

(编辑,稍微修正示例,更新了csharp regexp)

找到了一些有关此的信息。

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

页面引用-

"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"

所以看起来格式是这样的:

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

再次查看正则表达式,它看起来像是经过修改的BRE。

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

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

 : [ ] 

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

这是EDG-1

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

哪里

"^\\([^ \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."

因此,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元素信息

看着你的csharp元素

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

而且您的正则表达式(如下)实际上没有捕获组4。
因此,您的FILE LINE COLUMN为2 3 4
大概应该是1 2 3

这是您的正则表达式,因为它的引擎可以看到它-

 ^ 
 [ ]* 
 \(?:
      [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]+ :
 \)

我的水晶球提出了一个怪异的解释: compilation-error-regexp-alist-alist只是一组匹配规则,但没有说明要使用哪些规则。 因此,如果要使用新规则,则需要将csharp添加到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