Need help adding function pattern to a custom language module

27 views
Skip to first unread message

Joe Strout

unread,
Jan 1, 2021, 11:39:17 AM1/1/21
to BBEdit Talk
I have a codeless language module (https://github.com/JoeStrout/miniscript-bbedit-lang-mod) which does a fine job of syntax coloring.  Now I want to add a function pattern, so it can identify functions and support the function pop-up.  Following the example in the docs, I've developed a RegEx which correctly selects functions when I run it on its own.  However, when I add it to the language module, my language no longer appears in BBEdit as a language option at all.  I have searched the Console for errors, but can't find any there.

The Function Pattern block in my plist looks like this:

        <string><![CDATA[
            (?x:
                ^(?P<function>
                    (?P<function_name>[a-zA-Z0-9_\.]+)
                    (?: *)=(?: *)function
                    (?s:.+?)
                    ^end function
                )
            )
          ]]></string>

Any idea what I'm doing wrong here?  Or how to get BBEdit to provide more information about what's wrong?

Rich Siegel

unread,
Jan 1, 2021, 11:42:16 AM1/1/21
to BBEdit Talk
On 1 Jan 2021, at 11:19, Joe Strout wrote:

> I have a codeless language module
> (https://github.com/JoeStrout/miniscript-bbedit-lang-mod) which does a
> fine
> job of syntax coloring. Now I want to add a function pattern, so it
> can
> identify functions and support the function pop-up. Following the
> example
> in the docs, I've developed a RegEx which correctly selects functions
> when
> I run it on its own. However, when I add it to the language module,
> my
> language no longer appears in BBEdit as a language option at all. I
> have
> searched the Console for errors, but can't find any there.

Choose "Logs" from the "Folder" submenu of the main application menu.
There may be a "Language Module Errors.log" in the folder that opens in
the Finder. If so it should describe what prevented the module from
loading.

R.

--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <https://www.barebones.com/>

Someday I'll look back on all this and laugh... until they sedate me.

Joe Strout

unread,
Jan 1, 2021, 12:20:11 PM1/1/21
to BBEdit Talk
Thank you!  That was what I needed.  To close the loop for future searchers, the error ("quantifier does not follow a repeatable item (error 112109)") was because I had the (?x: quantifier around the whole expression (telling PCRE to ignore inline comments and "most whitespace"), but was attempting to match an arbitrary amount of spaces with (?: *).  The fix was to backslash-escape any spaces in my pattern that I really meant to be there.

Thank you, Rich!  You (and BBEdit) rock.

Neil Faiman

unread,
Jan 1, 2021, 2:37:31 PM1/1/21
to BBEdit Talk Mailing List
A possibly useful tip (for those who hate back-slashes): Instead of backslash-escaping a space in a ?:x regex, you can also use "[ ]" (i.e., a single-character character class containing just a space. Personally, I find it easier to read.

Also, when I find myself putting a space character in a pattern, I usually stop and ask myself, "Would a \s make more sense (or just as much sense) here?

Regards,

Neil Faiman
Reply all
Reply to author
Forward
0 new messages