Notepad++ Function list for SQL

匿名 (未验证) 提交于 2019-12-03 10:10:24

问题:

quick question .. I'm trying to get the function list option in Notepad++ going ...

Now, I found this thread: Notepad++ Function List for PL/SQL

which helped get me started, however, I'm still struggling with something, and I can't seem to wrap my monkey-brain around it.

It'll be this section I need to focus:

        <function             mainExpr="^[\t ]*(FUNCTION|PROCEDURE)[\s]*[\w]*[\s]*(\(|IS|AS)*"             displayMode="$functionName">             <functionName>                 <nameExpr expr="[\w]+[\s]*(\(|IS|AS)"/>             </functionName>         </function> 

That works perfectly fine .. so far. However, I would like to also see PACKAGE header and PACKAGE BODY names in there as well .. just to help tidy things up.

I figured it'd be easy to tweak the RegExp, however, nothing I've tried is working

So I'm trying to pick out these kinds of scenarios:

 CREATE PACKAGE aaa  CREATE OR REPLACE PACKAGE bbb  CREATE PACKAGE BODY ccc  CREATE OR REPLACE PACKAGE BODY ddd 

all 4: aaa, bbb, ccc, and ddd. I can't even get it to pull back one yet.. :(

Hoping I could get some help/hints/something ..

I know this is the main "logic":

mainExpr="^[\t ]*(FUNCTION|PROCEDURE)[\s]*[\w]*[\s]*(\(|IS|AS)*" 

that finds the line(s) ..

And trying to matchup the logic with what it finds for .. say, FUNCTIONs, and what I want for PACKAGE ... I tried this:

mainExpr="^[\t ]*(FUNCTION|PROCEDURE|CREATE OR REPLACE PACKAGE)[\s]*[\w]*[\s]*(\(|IS|AS)*" 

but even that doesn't pick out the header! O.o

I'm sure there's something I need to do with the part .. but again, not really understanding how it works ??

I've read this : https://notepad-plus-plus.org/features/function-list.html

but there's obviously something about the syntax/usage of this thing I'm not fully understanding ..

hoping somebody can help me out?

回答1:

I think your problem is coming from the Regex rather than anything you're doing incorrectly. I've made a new parser based on the one I found here: http://www.hermanmol.nl/?p=240

<parser id="plsql_func" displayName="PL/SQL" commentExpr="((/\*.*?\*)/|(--.*?$))">     <function         mainExpr="^[\w\s]{0,}(PACKAGE BODY|PACKAGE|FUNCTION|PROCEDURE)[\s]{1,}[\w_]{1,}">         <functionName>             <nameExpr expr="^[\w\s]{0,}(PACKAGE BODY|PACKAGE|FUNCTION|PROCEDURE)[\s]{1,}\K[\w_]{1,}"/>         </functionName>     </function> </parser> 

For me this seems to correctly pull out the Package, Procedures and Functions.

One thing to note however, I could not get this to work using a file extension assocation, and used the following instead to test on a text file: <association langID= "0" id="plsql_func" />

I also placed the updated functionList.xml file in both the Program Files (x86)\Notepad++ and the Users\xxxxx\AppData\Roaming\Notepad++ directories.

Edit - a short explanation of the Regex, I'm not great at Regex but it was requested in the comments

^[\w\s]{0,} - From the beginning of the line, find 0 or more letters or white space characters

(PACKAGE BODY|PACKAGE|FUNCTION|PROCEDURE) - followed by any of these

[\s]{1,}[\w_]{1,} - followed by one or more spaces, followed by one or more words



回答2:

Thanks Chrisrs2292,

I was helped by the location of the functionList.xml file in Users\xxxxx\AppData\Roaming\Notepad++ directories.

RegEX for T-SQL:

<association id= "T-SQL_func" langID="17"/>  <!-- T-SQL--> <parser displayName="T-SQL" id="T-SQL_func" commentExpr="(?s:/\*.*?\*/)|(?m-s:--.*?$)"> <function mainExpr='(?im)^\h*(create|alter)\s+(function|procedure)\s+((\[|")?[\w_]+(\]|")?\.?)?((\[|")?[\w_]+(\]|")?)?'           displayMode="$functionName">     <functionName>         <nameExpr expr='(?im)(function|procedure)\s+((\[|")?[\w_]+(\]|")?\.?)?((\[|")?[\w_]+(\]|")?)?' />     </functionName> </function> 



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!