相关疑难解决方法(0)

词法分析者与解析者

词法分析器和解析器在理论上真的有那么不同吗?

讨厌正则表达式似乎很时髦:编码恐怖,另一篇博客文章.

然而,流行的基于乐兴的工具:pygments,geshi或者美化,都使用正则表达式.他们好像有什么东西......

什么时候足够兴奋,什么时候需要EBNF?

有没有人使用这些词法分析器生成的令牌与野牛或antlr解析器生成器?

parsing antlr lexer pygments

299
推荐指数
6
解决办法
10万
查看次数

正则表达式在VB.Net源代码中获取注释

我在vb.net中有一个语法高亮功能.我使用正则表达式匹配"!IF",然后将其着色为蓝色.这很有效,直到我试图弄清楚如何做评论.

我正在写这篇评论的语言可以是如果该行以单引号开头'或者如果该行中的任何地方有两个单引号

'this line is a comment
!if StackOverflow = "AWESOME" ''this is also a comment
Run Code Online (Sandbox Code Playgroud)

现在我知道如何查看它是否以单行开头^'但我需要将字符串一直返回到行尾,这样我就可以将整个注释的颜色设置为绿色,而不仅仅是单引号.

您不应该需要代码,但这里是一个片段,以防它有所帮助.

    For Each pass In frmColors.lbRegExps.Items
        RegExp = System.Text.RegularExpressions.Regex.Matches(LCase(rtbMain.Text), LCase(pass))
        For Each RegExpMatch In RegExp
            rtbMain.Select(RegExpMatch.Index, RegExpMatch.Length)
            rtbMain.SelectionColor = ColorTranslator.FromHtml(frmColors.lbHexColors.Items(PassNumber))
        Next
        PassNumber += 1
    Next
Run Code Online (Sandbox Code Playgroud)

regex vb.net

3
推荐指数
1
解决办法
3020
查看次数

使用RegEx查找VBA注释

我试图使用正则表达式查找所有VBA注释.我有一些主要有用的东西,但有一些我无法弄清楚的例外.

我正在使用的表达式:

'(?!.*").*
Run Code Online (Sandbox Code Playgroud)

拿我们的测试代码:

Working - This is a test 'This should be captured
Working - "this is a test" 'This should be captured
Not Working - "this is a test" 'This should be "captured"
Not Working - This is a test 'This should be "captured"
Working - "this is a test 'this should not capture'" 'this should capture
Working - "this isn't a test" 'this should capture
Run Code Online (Sandbox Code Playgroud)

以下是RegExr中此示例的链接:http: //regexr.com/3f24h

由于某种原因,第三和第四个例子没有捕获.问题似乎是在评论中有一个字符串值,我无法弄清楚如何解决它.

有什么建议?

regex vba comments

1
推荐指数
1
解决办法
144
查看次数

标签 统计

regex ×2

antlr ×1

comments ×1

lexer ×1

parsing ×1

pygments ×1

vb.net ×1

vba ×1