Reputation: 1031
I am trying to set up a Function List for a new language in Notepad++. To do so, it requires me to add a parser in functionlist.xml
. I added the parser, and it works, but it also adds the actual word function
in the function list. How can I remove word function from it? I have looked into the Regular Expression's lookbehind feature. But I could not make it work.
Here is the parser.
<parser displayName="mylang" id="mylang_syntax">
<function mainExpr="^\s*(function|Function|FUNCTION)[\t ]+[\w]+">
<functionName>
<NameExpr expr="/(?<=^function /)[\w]+" />
<NameExpr expr="/(?<=^Function /)[\w]+" />
<nameexpr expr="/(?<=^FUNCTION /)[\w]+" />
</functionName>
</function>
</parser>
Here is an example text to try on.
FUNCTION uniqn, input_array
IF(!DEBUG) THEN PRINT, 'uniqn_no_sort'
counter = 0L
length = n_elements(input_array(*, 0))
duplicate_array = STRARR(length)
END
function get_algorithm_type, type
IF(!DEBUG) THEN PRINT, 'get_algorithm_type'
print, type
END
This is how it looks in the functionlist sidebar. I would like to remove the word 'function'. Please note that it needs to work in Notepad++. (I cannot use any other Text editors). Thank you in advance for your help.
Here are additional help.
Upvotes: 2
Views: 1963
Reputation: 18980
Try it like this
<parser displayName="mylang" id="mylang_syntax">
<function mainExpr="(?<=function|Function|FUNCTION)[\t ]+[\w]+"/>
</parser>
and you get
Upvotes: 1
Reputation: 10360
Try the Regex below:
(?i)(?<=^function)\s+\K\w+
Regex Explanation:
(?i)
- modifier to make the search case-insensitive(?<=^function)
- positive lookbehind to find the position immediately preceded by the sub-string function
at the start of the line\s+
- matches 1+ occurrences of a white-space character\K
- forget everything matched so far\w+
- matches 1+ occurrences of all the characters which fall within the character class [a-zA-Z0-9_]
Add the following parser
tag to the file functionList.xml
<parser id="mylang" displayName="mylang_syntax">
<function mainExpr="(?i)(?<=^function)\s+\K\w+" />
</parser>
OUTPUT
As you can see below, extra spaces between the function
and the functionName
have also been ignored
Upvotes: 2