Rev 9ed5fa1: the spectacular new importer;; abbreviation

33 views
Skip to first unread message

Edward K. Ream

unread,
Nov 21, 2016, 3:52:37 PM11/21/16
to leo-editor
Leo now supports the importer;; abbreviation.  It creates an @@file node containing an almost complete line-oriented importer for a new language.  I'll be adding to it soon, but it's more than good enough as it is.

The checkin log discusses hacks to Leo's abbreviation code needed to support importer;; These changes should not affect existing abbreviations in any way.  They merely add the ability to make script substitutions in headlines. Nevertheless, these changes might have changed Leo's abbreviation handling in unexpected ways.  Please report any problems immediately.

Importance

The importer;; abbreviation is a huge step forward, for several reasons:

1. The abbreviation almost completely eliminates the need for endless soporific instructions about how to create a new importer.  Instead of reading blah-blah-blah about cassettes and such, devs will just run the abbreviation.  Everything will be created for them.

Note: Below are full instructions for running importer;; That's almost all that is needed in the way of docs!

2. importer;; will be of great practical use to me as I go about converting the remaining 14 importers.  I have spent about 8 hours already on the importer;; abbreviation and needed tweaks to Leo's abbreviation code. Nevertheless, it will likely soon pay off handsomely. And even if it doesn't, using the abbreviation will be a whole lot more fun than doing the same thing over and over again.

3. Perhaps most importantly, importer;; should remove much of the sheer terror that might otherwise confront devs in the future ;-)

Enabling the abbreviation

As mentioned in the checkin log, to make importer;; functional you must:

1. Copy it from leoSettings (@settings-->Abbreviations-->@outline-data tree-abbreviations) to the corresponding location in myLeoSettings.leo.

2. Make sure @bool scripting-abbreviations is True in myLeoSettings.leo.

Using the abbreviation

1. Just type importer;; in the body pane of an empty node.

A dialog will prompt you for the name of the language.  Suppose you type x.

2. Now you will be prompted for to fill in the first field:

    'extensions': [comma-separated lists of extensions, with leading periods],

The italicized field will be highlighted.  Type '.x' (including quotes) followed by two commas.

3. You will then be prompted to fill in the second field:

    strict = True leading whitespace is significant. Otherwise False,

Again, the italicized field will be highlighted.

Type False, followed by two commas.

4. You will then be prompted for the last field:

        return level
            ### Examples:
            # self.indent # for python, coffeescript.
            # self.curlies
            # (self, curlies, self.parens)
   
Only "level" is highlighted. The comments provide some hints about what to type.

Let's type "self.curlies" followed by two commas.

5. Nothing more is highlighted, so that's it! No more substitutions remain. The outline is ready to use!

Take a look at the result. The new tree is an almost complete @@file node for the importer. Subtrees contain an X_Importer class and an X_ScanState class. Docstrings, ctors and __repr__ methods are complete.

Note: The generated tree contain ### comments showing where more work may be needed.  I might remove the need for some of them, but there is no great need to do so.

None of this would have been possible without Terry Brown's initial implementation of script substitutions in abbreviations.  Thanks again, Terry.

Edward

P.S: importer;; will soon generate x.get_new_table, and perhaps a one or two other nodes.  It's very easy to make such changes!

EKR

Edward K. Ream

unread,
Nov 21, 2016, 7:14:26 PM11/21/16
to leo-editor
​​
​​
On Mon, Nov 21, 2016 at 2:52 PM, Edward K. Ream <edre...@gmail.com> wrote:
Leo now supports the importer;; abbreviation. 
 
​[big snip]​
 

P.S: importer;; will soon generate x.get_new_table, and perhaps a one or two other nodes.
 
Imo, importer;; is good as it stands.  i.get_new_table is already generalized. It should work for the majority of languages as is. I see no strong reason to put a disabled version of i.get_new_table in the file.

I did make one real improvement. Rev f10fa02 uses the new get_language helper to set "name" and "cap_name" in the various namespaces.

The templates uses {|{x=get_language()}|} first. Thereafter the template uses {|{name}|} and {|{cap_name}|}.

It's a great simplification.

Tomorrow I'll use importer;; to create real importers.  That will reveal any lingering problems.

EKR

Edward K. Ream

unread,
Nov 22, 2016, 7:55:45 AM11/22/16
to leo-editor
On Monday, November 21, 2016 at 6:14:26 PM UTC-6, Edward K. Ream wrote:

Tomorrow I'll use importer;; to create real importers.  That will reveal any lingering problems.

I have retired the importer;; abbreviation.  The @button make-importer script is significantly better.

The c# importer was made with importer;; There were no big problems.

The xml importer was made with the @button script. Even fewer problems ;-)

I've got to fix the xml importer asap.  That's next.

EKR

Edward K. Ream

unread,
Dec 3, 2016, 6:24:53 PM12/3/16
to leo-editor
On Mon, Nov 21, 2016 at 2:52 PM, Edward K. Ream <edre...@gmail.com> wrote:
Leo now supports the importer;; abbreviation.  It creates an @@file node containing an almost complete line-oriented importer for a new language.  I'll be adding to it soon, but it's more than good enough as it is.

​This post is obsolete.  The new @button make-importer script does a better job, more naturally and conveniently, than any abbreviation could hope to do.

EKR
Reply all
Reply to author
Forward
0 new messages