On Fri, Nov 8, 2013 at 11:33 AM, Edward K. Ream <[email protected]> wrote:

> 
When a regex matches, its components will be parsed, and the components
sent to the vim-like command given by the corresponding setting.  Example:

    
gg vim-goto-first-line

> 
One of the beauties of this scheme is that I can test it without changing
Leo's source code!  This accelerates the project. I plan to do this today.

Here is the first test script.  This is, by far, the most complex use of
regexes I've ever attempted::

    import re
    g.cls()
    n_c_tail = r'(?P<count>[0-9]*)(?P<command>.)(?P<tail>.*)'
    tables = (
        (n_c_tail,('35N','N','2d2','d2d',)),
    )
    for pat,aList in tables:
        fields = re.findall('P<([a-zA-Z]+)>',pat)
        print('pattern: %s\n fields: %s' % (pat,','.join(fields)))
        for s in aList:
            print('  %s' % s)
            m = re.search(pat,s)
            for field in fields:
                print('    %7s %s' % (field,m.group(field) or 'None'))

And here is the output::

    pattern: (?P<count>[0-9]*)(?P<command>.)(?P<tail>.*)
     fields: count,command,tail
      35N
          count 35
        command N
           tail None
      N
          count None
        command N
           tail None
      2d2
          count 2
        command d
           tail 2
      d2d
          count None
        command d
           tail 2d

This demonstrates that it's possible to use regex to parse vim-like
commands into patterns.

At present the command is always just a single character, but that can be
changed easily.

> k.getArg will accept characters until one of the actual regexs match.
This imposes constraints on the regexs!  The preprocessor might (or might
not) check those constraints.

In fact, the constraint is simple:  no (unescaped) * or + or $ (etc) at the
end of the pattern.  In practice, this will always be true, because only a
few kinds of "extensions" are possible after the one or two characters that
denote the actual "main" command letters.

This is just a ton of fun:

- The regexes, though tricky, are relatively easily debugged in the script
shown above.
- The regexes, in essence, replace all the hacks in vim's main line.

Being able to invoke commands with regexes is far more important than the
slight additional time required to handle keystrokes.

Still to do:

- Add more patterns covering all vim's main commands.
- Check patterns to ensure constraints are met.  This is a check on user
input.
- Create parsers for new @data nodes.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to