2

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.

enter image description here

Here are additional help.

2 Answers 2

2

Try the Regex below:

(?i)(?<=^function)\s+\K\w+

Click for Regex Demo

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 enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you so much @Gurman. It works great. \K was awesome. I did not know such feature existed. I have one more small request. Is it possible to add another type of function, which actually start with pro. pro another_routine, type IF(!DEBUG) THEN PRINT, 'get_algorithm_type' print, type END
@Cricrazy For that case, you can use this regex (?i)(?:(?<=^function)|(?<=^pro))\s+\K\w+
@Cricrazy Also, If the answer helped you, please consider upvoting it or accepting the answer
works perfectly. Accepted as the answer most gladly. Thank you very much.
1

Try it like this

<parser displayName="mylang" id="mylang_syntax">
  <function mainExpr="(?<=function|Function|FUNCTION)[\t ]+[\w]+"/>
</parser>

and you get

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.