User Defined language multiple questions
-
Thanks, i’ll use those then.
-
Just for info, I’m waiting for the example code. Preferable the one used in the gif.
-
So, the XML file.
<UserLang name="GP" ext="" udlVersion="2.1"> <Settings> <Global caseIgnored="no" allowFoldOfComments="no" foldCompact="no" forcePureLC="0" decimalSeparator="0" /> <Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" /> </Settings> <KeywordLists> <Keywords name="Comments">00// 01 02 03 04</Keywords> <Keywords name="Numbers, prefix1"></Keywords> <Keywords name="Numbers, prefix2"></Keywords> <Keywords name="Numbers, extras1"></Keywords> <Keywords name="Numbers, extras2"></Keywords> <Keywords name="Numbers, suffix1"></Keywords> <Keywords name="Numbers, suffix2"></Keywords> <Keywords name="Numbers, range"></Keywords> <Keywords name="Operators1"></Keywords> <Keywords name="Operators2">== === + - / * < > <= >= != % isNil notNil compareFloats</Keywords> <Keywords name="Folders in code1, open">{</Keywords> <Keywords name="Folders in code1, middle"></Keywords> <Keywords name="Folders in code1, close">}</Keywords> <Keywords name="Folders in code2, open"></Keywords> <Keywords name="Folders in code2, middle"></Keywords> <Keywords name="Folders in code2, close"></Keywords> <Keywords name="Folders in comment, open"></Keywords> <Keywords name="Folders in comment, middle"></Keywords> <Keywords name="Folders in comment, close"></Keywords> <Keywords name="Keywords1">if else while animate for repeat waitUntil</Keywords> <Keywords name="Keywords2">to
method
return
argCount
arg
defineClass
lastReceiver
call
callWith
function
parse
primitives
comment
globalFuncs</Keywords> <Keywords name="Keywords3">true false not and or</Keywords> <Keywords name="Keywords4">this</Keywords> <Keywords name="Keywords5"></Keywords> <Keywords name="Keywords6"></Keywords> <Keywords name="Keywords7"></Keywords> <Keywords name="Keywords8"></Keywords> <Keywords name="Delimiters">00' 01 02' 03( 04 05) 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords> </KeywordLists> <Styles> <WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="COMMENTS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="LINE COMMENTS" fgColor="5E86BD" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="NUMBERS" fgColor="FF00FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS1" fgColor="C10000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="KEYWORDS2" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="KEYWORDS3" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="KEYWORDS4" fgColor="129300" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="KEYWORDS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="OPERATORS" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="FOLDER IN CODE1" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="FOLDER IN CODE2" fgColor="FF0000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" /> <WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS1" fgColor="FF00FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="100924419" /> <WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> <WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" /> </Styles> </UserLang> </NotepadPlus>
-
Here is the code !
method justToShowYouThingsAreStrange { b1 = 2 b2 = 3 var = (b1 + b2) } method project ProjectEditor { return project } method stage ProjectEditor { return stage } method library ProjectEditor { return library } method scripter ProjectEditor { return scripter } to recover baseFilename { // Save any projects in memory (usually only one) to files. if (isNil baseFilename) { baseFilename = 'recovered' } baseFilename = (withoutExtension (filePart baseFilename)) gc // dispose of unreachable projects for editor (allInstances 'ProjectEditor') { fileName = (uniqueNameNotIn (listFiles (userHomePath)) baseFilename 'gpp') saveProject (project editor) (join (userHomePath) '/' fileName) } } to startProjectEditorFromMorphic { // Start the project editor from the morphic background menu. page = (global 'page') if (not (confirm (global 'page') nil 'Enter project editor (current morphs will be lost)?')) { return } removeAllParts (morph page) editor = (initialize (new 'ProjectEditor') (emptyProject)) addPart page editor pageResized editor developerModeChanged editor }
-
The functions can be defined by ‘method’ (for class) or ‘to’ for global functions.
-
which npp version do you use? Can be found as debug-info from ? menu (last menu item). With 7.7.1 it seems that folding is correct, regardless whether I open a gp file or if using a new file. Btw. I have add the gp to the extensions in udl.
-
Yes, I’m using 7.4.2. I’m going to update now.
-
don’t update. Download a zipped version and see if this changes what you want.
There are a lot of changes since 7.4, so you might run into other troubles. -
When variable contains numbers in it’s name and is inside parenthesis, the nuber are highlighted.
Is caused by the delimiter2 setting to allow nesting with numbers. What do you try to achieve with this delimiter?
-
I tried v7.7.1 and sadly it didn’t resolve my folding problem. And about the delimiter 2, I used it because if don’t numbers are not highlighted at all inside parenthesis.
-
But in the folding problem is not my main question with the workaround of opening a new file. I’m more intrusted in the variables/functions highlighting. If you could help would be awesome anyway.
-
I tried v7.7.1 and sadly it didn’t resolve my folding problem
With the same code you sent? What exactly do you do to see this behavior.
about the delimiter 2, I used it because if don’t numbers are not highlighted at all inside parenthesis
What do you try to achieve with this delimiter? Why is it needed at all?
-
I used delimiter 2 with parenthesis because when I’m not using it, numbers and strings are not highlighted at all, wich is kind of worse. But this is really not an issue. Just like the folding problem.
-
for function list you need to edit functionList.xml
I added to the end of associationMap tag
<association id= "gp_function" userDefinedLangName="GP" /> <association id= "gp_function" ext=".gp" />
and a new parser tag
<parser displayName="GP" id ="gp_function" > <!-- <classRange --> <!-- mainExpr ="(?<=^class\x20).*?(?=\n\S|\Z)" --> <!-- > --> <!-- <className> --> <!-- <nameExpr expr="\w+(?=[\(|:])" /> --> <!-- </className> --> <!-- <function --> <!-- mainExpr="(?<=def\x20).+?(?=:)" --> <!-- > --> <!-- <functionName> --> <!-- <funcNameExpr expr=".*" /> --> <!-- </functionName> --> <!-- </function> --> <!-- </classRange> --> <function mainExpr="(?m-s)(?<=to\x20).+?(?={.*$)" > <functionName> <nameExpr expr=".*" /> </functionName> </function> </parser>
The open part is how a class and its methods are defined. Is not part of your sample code.
Note, once you edit functionlist.xml you need to restart npp in order to make it work.
-
Midnight here - unless someone else takes over I will follow up on this tomorrow.
-
Thnks a lot for now.
I tried what you said but I still have problems.-
Only functions defined by ‘to’ are recognized.
-
The function are listed with the arguments in their name. For example :
to playABC s instr beatsPerMinute transposition { if (isNil instr) { instr = 'piano' } if (isNil beatsPerMinute) { beatsPerMinute = 120 } if (isClass instr 'String') { instrument = (newSampledInstrument instr) } (isClass instr 'Array') { instrument = (sampledInstrumentFromSamples instr) } else { return nil } scorePlayer = (newScorePlayer instrument beatsPerMinute) voice = (parse (new 'ABCParser') s) if (notNil transposition) { transpose (new 'ABCParser') voice transposition } addVoice scorePlayer voice playScore scorePlayer return scorePlayer }
Here, the name of the function is just ‘playABC’. Without ‘instr’, ‘beatsPerMinute’ and ‘transposition’.
Thanks a lot for all of this. But don’t hurry to help I won’t be able to answer for two weeks.
-
-
Only functions defined by ‘to’ are recognized.
:-) That’s no wonder as it isn’t included yet. Therefore my statement
The open part is how a class and its methods are defined. Is not part of your sample code. :-)The function are listed with the arguments in their name. For example :
Yes, as I don’t know this language and don’t know how you wanted it to be reported
I used<nameExpr expr=".*" />
which returns the whole line. For example, a change to
<nameExpr expr="\w+" />
would return the first word after to.But don’t hurry to help I won’t be able to answer for two weeks.
No problem. Just respond when you are back to this thread and we can go on.
As said, I need the class and its method definitions as an example.