Sma*_*tti 6 syntax-highlighting notepad++ http-status-codes
我想在Notepad ++中为访问日志编写自定义语言.
问题是数字(这里:HTTP状态代码)不会像真正的关键字一样突出显示(即GET).Notepad ++通常只为数字提供高亮颜色.
我该如何处理文字等数字?
示例日志文件
192.23.0.9 - - [10/Sep/2012:13:46:42 +0200] "GET /js/jquery-ui.custom.min.js HTTP/1.1" 200 206731
192.23.0.9 - - [10/Sep/2012:13:46:43 +0200] "GET /js/onmediaquery.min.js HTTP/1.1" 200 1229
192.23.0.9 - - [10/Sep/2012:13:46:43 +0200] "GET /en/contact HTTP/1.1" 200 12836
192.23.0.9 - - [10/Sep/2012:13:46:44 +0200] "GET /en/imprint HTTP/1.1" 200 17380
192.23.0.9 - - [10/Sep/2012:13:46:46 +0200] "GET /en/nothere HTTP/1.1" 404 2785
Run Code Online (Sandbox Code Playgroud)
示例自定义语言
http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=User_Defined_Language_Files
我还尝试编辑和导入这样的预定义语言:http:
//notepad-plus.sourceforge.net/commun/userDefinedLang/Log4Net.xml
我认为自定义语言应如下所示:
<KeywordLists>
[...]
<Keywords name="Words1">404 501</Keywords>
<Keywords name="Words2">301 303</Keywords>
<Keywords name="Words3">200</Keywords>
</KeywordLists>
<Styles>
<WordsStyle name="DEFAULT" styleID="11" fgColor="000000" bgColor="FFFFFF" colorStyle="0" fontName="Courier New" fontStyle="0"/>
[...]
<WordsStyle name="KEYWORD1" styleID="5" fgColor="FF0000" bgColor="FFFFFF" colorStyle="1" fontName="" fontStyle="0"/>
<WordsStyle name="KEYWORD2" styleID="6" fgColor="0000FF" bgColor="FFFFFF" colorStyle="1" fontName="" fontStyle="1"/>
<WordsStyle name="KEYWORD3" styleID="7" fgColor="00FF00" bgColor="FFFFFF" colorStyle="1" fontName="" fontStyle="0"/>
[...]
// This line causes number highlighting. Deletion doesn't work either.
<WordsStyle name="NUMBER" styleID="4" fgColor="0F7F00" bgColor="FFFFFF" fontName="" fontStyle="0"/>
</Styles>
Run Code Online (Sandbox Code Playgroud)
不幸的是,数字将以相同的颜色着色.
我想像这样给它们着色:

等等
有什么建议?如何处理像关键字这样的数字?
不可能将数字突出显示为关键字,因为内置词法分析器(解析器/语言定义)使用数字作为标记,这意味着区分数字和关键字的唯一方法是解析整个数字块并然后与关键字列表进行比较,在这种情况下,还需要解析数字块周围的分隔符,以确保.200.不会突出显示为200。这就是为什么您的数字都以相同的颜色突出显示;即“数字”颜色。
虽然这可以使用自定义词法分析器使用固定位置标记或正则表达式匹配来完成,但您会发现用户定义的语言(我最后听说的)没有此功能。
因为您的要求实际上相当简单,据我了解,尽可能笼统(按照您评论中的要求)...
Highlight space delimited numeric values contained in a given set.
[[:space:]](200|301|404)[[:space:]]
Run Code Online (Sandbox Code Playgroud)
我们可以将“查找”对话框的“标记”功能与该正则表达式一起使用,但所有内容都会被标记为与失败的实验相同的颜色。
也许简单且适合您需求的方法是使用 npp pythonscript 和Mark Style中的设置来Style Configurator获得所需的结果?
像这种粗略的宏观风格:
from Npp import *
def found(line, m):
global first
pos = editor.positionFromLine(line)
if first:
editor.setSelection(pos + m.end(), pos + m.start())
first = False
else:
editor.addSelection(pos + m.end(), pos + m.start())
editor.setMultipleSelection(True)
lines = editor.getUserLineSelection()
# Use space padded search since MARKALLEXT2 will act just
# like the internal lexer if only the numeric is selected
# when it is called.
first = True
editor.pysearch( " 200 ", found, 0, lines[0], lines[1])
notepad.menuCommand(MENUCOMMAND.SEARCH_MARKALLEXT1)
first = True
editor.pysearch( " 301 ", found, 0, lines[0], lines[1])
notepad.menuCommand(MENUCOMMAND.SEARCH_MARKALLEXT2)
first = True
editor.pysearch( " 404 ", found, 0, lines[0], lines[1])
notepad.menuCommand(MENUCOMMAND.SEARCH_MARKALLEXT3)
Run Code Online (Sandbox Code Playgroud)
要使用它,只需使用插件管理器安装Python Script,转到插件菜单并选择New Script然后粘贴,保存,选择要解析的文档的选项卡,然后执行脚本(再次从插件菜单)。
显然,您可以将所有 5 种标记样式用于不同的术语,您可以指定一个快捷方式,并且您可以更多地了解 nppPython 的“脚本”-vs-“宏”样式,并制作一个完整的脚本来解析您想要的任何内容。 .. 每当您选择特定的词法分析器样式时,拍摄脚本触发器也是可行的。
| 归档时间: |
|
| 查看次数: |
5088 次 |
| 最近记录: |