Tapatalk

Papyrus (Creation Kit) comments

Papyrus (Creation Kit) comments

71
NewbieNewbie
71

    Aug 27, 2019#1

    Hello,

    I am struggling with comment highlighting for Papyrus (Creation Kit Scripting language for Skyrim and Fallout). This is a Lua like language.

    A line comment is defined by ; ...
    A block by ;/ ... /;

    This is what I have defined so far

    Code: Select all

    /L20"Papyrus" Nocase Block Comment On = ;/ Block Comment Off = /; Line Comment = ; Line Comment Preceding Chars = [~/]
    And this is the result:

    ; line comment
    float Function GetCurrentRealTime() native global

    ;/ Block comment
    line2
    /;

    Block comments are not working. What can I do?

    6,685587
    Grand MasterGrand Master
    6,685587

      Aug 27, 2019#2

      The order for searching for beginning of a block or line comment cannot be determined by the order of block/line comment definition in syntax highlighting wordfile. So it is important that a line comment is not just a substring of a block comment starting with same character(s).

      It is necessary to write line comments in files to syntax highlight with UltraEdit always with a semicolon and a space and use this definition in wordfile:

      Code: Select all

      /L20"Papyrus" Nocase Line Comment Num = 2;  Line Comment Preceding Chars = [~/] Block Comment On = ;/ Block Comment Off = /;
      Note: There are exactly two spaces after 2; in above line.

      A semicolon is interpreted as beginning of a line comment with this definition if a space follows and there is no slash left to the semicolon.
      Best regards from an UC/UE/UES for Windows user from Austria

      71
      NewbieNewbie
      71

        Aug 27, 2019#3

        Unfortunately the CK generates scripts like this:

        Code: Select all

        ;BEGIN FRAGMENT CODE - Do not edit anything between this and the end comment
        ;NEXT FRAGMENT INDEX 90
        Scriptname QF_DA10_00022F08 Extends Quest Hidden
        
        ;BEGIN ALIAS PROPERTY MainDoor
        ;ALIAS PROPERTY TYPE ReferenceAlias
        ReferenceAlias Property Alias_MainDoor Auto
        ;END ALIAS PROPERTY
        I can't modify these lines - another idea for a workaround?

          Aug 27, 2019#4

          And I found another issue with comments:

          In many functions I have added a comment to see in which quest stage a function is called:

          Code: Select all

          function MyQuestStageFunction() ; stage 20
          Therefore I defined a function list regex like this:

          /TGFindStr = "^\s*[\w\[\]]*\s*function\s+(\w+\([^\)]*\).*)"

          I want to see the stage in the function list.

          But UE seems to eat up the comment that shall be captured by the final .* sequence - only MyQuestStageFunction() is shown in function list.

          6,685587
          Grand MasterGrand Master
          6,685587

            Aug 27, 2019#5

            I suggest following:

            Code: Select all

            /L20"Papyrus" Nocase Line Comment Num = 2;  Line Comment Preceding Chars = [~/] Line Comment Alt = ; Line Comment Valid Columns Alt = [1] Block Comment On = ;/ Block Comment Off = /; File Extensions = PSC
            /Regexp Type = Perl
            /TGBegin "Functions"
            /TGFindStr = "^[\t ]*[0-9a-z_\[\]]*[\t ]*function[\t ]+([0-9a-z_]+\([^)]*\).*)$"
            /TGEnd
            /Strip Comments = No
            There is absolutely no possibility to force UltraEdit to evaluate the first character after a comment starting string to determine if that string really starts a comment and which type of comment as it would be required for LUA and Papyrus (and one more language on remembering correct from more than 650 supported languages). UltraEdit supports nearly all languages ever invented by someone, but not all languages and some not in all aspects.

            The definition above adds a second line comment definition for interpreting just ; as line comment starting string only in first column in a line. Of course a block comment starting with ;/ also at column 1 of a line results in getting just this line syntax highlighted as line comment and not as beginning of a line comment  and everything else up to /; because of UltraEdit does not evaluate / after line comment starting string ; to find out that this is not a line comment (but a block comment).

            It would be also possible to save into a macro file a macro with following macro code and configure this macro to be automatically executed on every file load:

            Code: Select all

            IfExtIs "psc"
            Top
            PerlReOn
            Find MatchCase RegExp "(?<!/);(?![ /])"
            Replace All "; "
            EndIf
            The file extension psc is interpreted case insensitive by UltraEdit. This macro executed on every load of a file results in inserting a space character after every semicolon if the file has the file extension psc and there is neither a slash character left to the semicolon nor a space or slash right to the semicolon.

            /Strip Comments = No disables stripping line and block comments from file content in memory before running the regular expression search(es) for the strings to display in function list since UltraEdit for Windows v24.20.0.35, see Function list ignores block comments ... could this be optional?

            I modified also the Perl regular expression. /s matches any whitespace according to Unicode which includes the newline and vertical whitespace characters carriage return and line feed and so every Perl regular expression starting with ^\s* matches also empty and blank lines. That is usually not wanted for functions to show in function list because the line number should be the line number containing the keyword function and not the line number of an empty or blank line above. And I suppose that Papyrus is like most programming and scripting languages and interpret only the ASCII whitespace characters normal space, horizontal tab, carriage return and line feed as horizontal and vertical whitespace characters and not all whitespace characters according to Unicode. See also Remove / delete blank and empty lines.

            I assume also that a function name cannot contain any word character according to Unicode for being valid for Papyrus. I think supported are only the ASCII characters 0.-9A-Za-z_ whereby a regular expression in a wordfile is always executed by UltraEdit case insensitive and therefore it is valid and more optimized to skip A-Z from this character class. Unicode defines thousands of characters as Unicode characters. So using a character class containing the word characters really supported by the programming or scripting language avoids false positives and decreases time required to complete the searches.

            And last .* at end (or beginning) of a search expression is not optimal. It is not clearly defined where to end (or begin) matching zero or more characters. In theory .* at end of a search expression can result in a positive match if no character is matched/selected at all. But Perl regular expression engine interprets .* greedy per definition and for that reason it matches as much characters as possible which means all characters except newline characters (or end of file depending on a flag controlling matching behavior of dot). For that reason I appended $ to specify clearly where to stop matching any character except newline characters zero or more times greedy.
            Best regards from an UC/UE/UES for Windows user from Austria

            71
            NewbieNewbie
            71

              Aug 28, 2019#6

              Okay, only the block comment issue cannot be solved - since the generated code from CK is used to synchronize the Object manager with the source code and the synchronization fails when the "anchor" comments are modified.

              But a workaround would be to add the anchors to the fold elements
              /Open Fold Strings = ... ";BEGIN"
              /Close Fold Strings =  ... ";END"

              And fold the first block on load via macro - this would be a very nice workaround because then I never have to see the generated code at all - but I cant find a fold block command in the list of macro commands... 

              Code: Select all

              IfExtIs "psc"
              Top
              Find ";BEGIN FRAGMENT CODE"
              StartSelect
              Find ";END FRAGMENT CODE"
              EndSelect
              HideShowSelection
              EndIf
              But auto-loaded macro is not called.
              p1.png (3.88KiB)
              p2.png (6.7KiB)

              Calling it manual will do what I expect.

              The macro jumps to the END FRAGMENT CODE line but does not fold during load. The macro only works manual - so my macro or UE has a bug.

              This simplified solution also works only manual.

              Code: Select all

              IfExtIs "psc"
              Top
              Find ";BEGIN FRAGMENT CODE"
              HideShowSelection
              EndIf
              Thanks for the support, now I bought a license...

              6,685587
              Grand MasterGrand Master
              6,685587

                Aug 28, 2019#7

                You do a quite good job as beginner on using UltraEdit. I am really impressed.

                Following macro code worked on my tests on opening a *.psc file:

                Code: Select all

                IfExtIs "psc"
                Top
                PerlReOn
                Find MatchCase ";BEGIN FRAGMENT CODE"
                IfFound
                Find MatchCase Select ";END FRAGMENT CODE"
                IfFound
                HideShowSelection
                EndIf
                EndIf
                EndIf
                The two IfFound are just for safety reasons to avoid further execution of macro commands on one of the two strings not found case sensitive in the just opened *.psc file.

                The optimized version using just following code does not work on file load while working on manual execution after file load.

                Code: Select all

                IfExtIs "psc"
                Top
                PerlReOn
                Find MatchCase ";BEGIN FRAGMENT CODE"
                IfFound
                HideShowSelection
                EndIf
                EndIf
                I think, the reason is that the macro is executed on file content before syntax highlighting is applied at all and therefore the open/close fold string definitions are not available on execution of the macro. Parsing a file for code folding is done in background after file open finished already being important on opening a very large file with millions of lines.

                For that reason it is necessary to really select the block to fold which is done with the two Find commands. The second Find command is with option Select resulting in extending the selection done by first find to end of found string of second find. That's like holding key SHIFT while clicking in Find and Replace window on tab Find on button Next.
                Best regards from an UC/UE/UES for Windows user from Austria

                71
                NewbieNewbie
                71

                  Sep 16, 2019#8

                  Does still not auto-start for me :-(

                  BTW: Is a native plug-in interface planned? The JavaScript integration does not allow file-system access and that reduces the usefulness a lot.
                  And not just to complain or talking about problems - UE is really an impressive tool and worth the money. I wish the Mac version also would someday reach this level.

                  6,685587
                  Grand MasterGrand Master
                  6,685587

                    Sep 16, 2019#9

                    I am not an employee of IDM Computer Solutions, Inc. I am just an UltraEdit user. So I don't know anything about planned extensions. But I doubt that a native plug-in interface (DLL interface) is planned by IDM Computer Solutions, Inc. The UltraEdit macro and script environments are designed for automatic editing tasks on files opened in UltraEdit or UEStudio. There are lots of scripting languages available to do other things with files and folders. All those script interpreters supporting direct access to files and folders or other resources of operating system are potentially dangerous as scripts can be written by everyone using those script interpreters to do something harmful.

                    It is possible to configure a user tool to run a script interpreter with a customized script file for a specific task which cannot be done in UltraEdit or UEStudio. Such user configured user tools can be executed from within UltraEdit macros and scripts. It is even possible to configure a batch file or another script file or an interpreter executable as user tool which executes one or more scripting commands created dynamically in an UltraEdit script or macro.

                    The posted code for the macro executed on every file load works in my configuration.
                    Please verify in dialog window Set Macro to Run on File Load/Save:
                    1. The macro file name configured for Macro filename;
                    2. the macro name entered for Macro name to run on load;
                    3. 1 is set for # of times.
                    If the fold is still not working on file load, please write one more post with following information and files packed into a 7-Zip, RAR or ZIP file attached to the post:
                    1. The lines as stored in INI file of UltraEdit in section [MacroLoadOS];
                    2. how all code folding settings are configured by you in configuration;
                    3. how a *.psc file is usually opened by you,
                    4. the version of UltraEdit used by you;
                    5. the *.uew wordfile used by you for syntax highlighting *.psc files;
                    6. the *.mac macro file containing the macro executed once on every file load;
                    7. a small example *.psc file.
                    Best regards from an UC/UE/UES for Windows user from Austria