Re: python imports

Andrey Torba <[email protected]>
Newsgroups gmane.emacs.cedet
Message-ID <CAFMdeWAdvxmK5gymUqcunpoF-PRSYPckStVhL8zFj6uuo0PUZg@mail.gmail.com>
Hi all,

In order to parse this python code:

from a.b.c import (
    x as xmodule,
    y as ymodule,
    z as zmodule,
    )

I created grammar:

import_stmt
....
  | FROM dotted_name_module IMPORT import_block
    (identity $4)
                    <- lisp code here which prepend "a.b.c" for each found
module?
  ;

import_block
  : PAREN_BLOCK
    (let ((wisent-python-EXPANDING-block t))
      (EXPANDFULL $1 import_block_as_name_list))
  ;

import_block_as_name_list
  : LPAREN
  | RPAREN
  | import_as_name COMMA
  | import_as_name RPAREN
  ;

As a result I get 3 modules: "x", "y", "z". How can i prepend "a.b.c" for
each module?
Also i think parser should create 3 global variables of type 'module':
xmodule, ymodule, zmodule

Thanks,
-Andrey


On 27 September 2014 16:14, Andrey Torba <[email protected]> wrote:

> Hello CEDET developers,
>
> I'm investigating how to parse python's imports for the cases:
>
> 1. from ... import <classes> (works well in current implementation)
>   Example:
>   from a.b.c import Class1, Class2
>
> 2. from ... import <modules> (doesn't work)
>   Example:
>   from a.b.c import module1, module2
>
>   In this case parser must create:
>     - two INCLUDE-TAGs: 'a.b.c.module1' and 'a.b.c.module2'.
>
> When we import something we don't know if it is module or class or
> function... So include-tag should be 'a.b.c.something', 'a.b.c.class1',
> 'a.b.c.module1'. And then in the functions
> 'semantic-dependency-find-file-on-path' and 'semantic-tag-include-filename'
> we can guess which file to open:
>   - a/b/c/something.py
>   - a/b/c.py   class:something
>   - a/b/c/__init__.py    class:something
>
> My question is: how can i build the grammar which makes 2 include tags
> from the string: 'from a.b.c import module1, module2'. I need to remember
> context ('a.b.c') and then build a full module path (format "%s.%s" "a.b.c"
> "module1") ?
>
> Thanks,
> -Andrey
>



-- 
Regards, Andrey

------------------------------------------------------------------------------
Slashdot TV.  Videos for Nerds.  Stuff that Matters.
http://pubads.g.doubleclick.net/gampad/clk?id=160591471&iu=/4140/ostg.clktrk

_______________________________________________
Cedet-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cedet-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.