creating a new importer for parse-body use

20 views
Skip to first unread message

jkn

unread,
Apr 11, 2021, 5:16:41 PM4/11/21
to leo-editor

Hi (Edward, probably)

I am interested in writing an importer to allow me to use the parse-body command on a simple format I use for making notes (it's similar to the format used by the old Origami editor used for Transputer occam files in the TDS; Transputer development system)

I'm starting with a stripped-down file

    leo/plugins/importers/tds.py

based on others in that directory.

I'm a little unclear as to whether just that file will be enough; I intend to select this parser by means of '@language tds', but with just 'noddy' contents of the tds importer I am seeing an error like:

{{{

Traceback (most recent call last):
  File "/home/jkn/leo-editor/leo/core/leoKeys.py", line 2466, in callAltXFunction
    func(event)
  File "/home/jkn/leo-editor/leo/core/leoImport.py", line 2738, in parse_body_command
    c.importCommands.parse_body(c.p)
  File "/home/jkn/leo-editor/leo/core/leoImport.py", line 1137, in parse_body
    ext = '.' + g.app.language_extension_dict.get(language)
TypeError: can only concatenate str (not "NoneType") to str

}}}

I have tried creating a matching file colorizor leo/modes/tds.py, without success

Any thoughts? In any case, that error message might be improved IMO

Thanks, Jon N


Edward K. Ream

unread,
Apr 11, 2021, 8:21:41 PM4/11/21
to leo-editor
On Sun, Apr 11, 2021 at 4:16 PM jkn <jkn...@nicorp.f9.co.uk> wrote:
Hi (Edward, probably)

Yes. I wrote this mess :-)
I am interested in writing an importer to allow me to use the parse-body command...
...
I'm starting with a stripped-down file...leo/plugins/importers/tds.py

Yes, that sounds reasonable.
I'm a little unclear as to whether just that file will be enough;

Yes, it should be enough, provided that '@language tds' is supported.

I intend to select this parser by means of '@language tds', but with just 'noddy' contents of the tds importer I am seeing an error like:

{{{

Traceback (most recent call last):
  File "/home/jkn/leo-editor/leo/core/leoKeys.py", line 2466, in callAltXFunction
    func(event)
  File "/home/jkn/leo-editor/leo/core/leoImport.py", line 2738, in parse_body_command
    c.importCommands.parse_body(c.p)
  File "/home/jkn/leo-editor/leo/core/leoImport.py", line 1137, in parse_body
    ext = '.' + g.app.language_extension_dict.get(language)
TypeError: can only concatenate str (not "NoneType") to str

}}}

I have tried creating a matching file colorizor leo/modes/tds.py, without success

Creating modes/tds.py only affects colorizing. It should have no effect on importers.

Any thoughts? In any case, that error message might be improved IMO

Hehe. I agree the message leaves a bit to be desired.

However, the traceback is actually pretty informative. As usual, the last two lines are the most informative. Clearly, g.app.language_extension_dict.get( language) is returning None.

The "language" var comes from the line:

language = g.scanForAtLanguage(c, p), so yes, you must support your new language by creating entries in three language dictionaries.  See the node "app.__init__ (helpers contain language dicts)" in leoApp.py.

Summary

You have to make @language tds work by creating entries for tds in three dictionaries in leoApp.py.
You have to create an importer for .tds files.
parse_body shouldn't crash if g.app.language_extension_dict.get( language) is None.

Edward

jkn

unread,
Apr 12, 2021, 4:09:44 AM4/12/21
to leo-editor
Thanks Edward. It looks like addressing the first of these:

> You have to make @language tds work by creating entries for tds in three dictionaries in leoApp.py.

Is what I need to look at first.

Regards, Jon N
Reply all
Reply to author
Forward
0 new messages