Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Missing QUALIFIED role #95

Closed
Closed

Description

@zurk

if you get UAST for

import lib1
lib1.lib2.lib3.var = None

You will have next list of Identifiers with roles:

<lib1>:         ['IMPORT', 'PATHNAME', 'IDENTIFIER']
<var>:          ['IDENTIFIER', 'EXPRESSION', 'LEFT']
<lib3>:         ['IDENTIFIER', 'EXPRESSION']
<lib2>:         ['IDENTIFIER', 'EXPRESSION']
<lib1>:         ['IDENTIFIER', 'QUALIFIED', 'IDENTIFIER', 'EXPRESSION']

QUALIFIED role is missing in lib2 and lib3 identifiers.
you can use code from issue #94 to reproduse result.
this gist: https://gist.github.com/zurk/8f7dd974347925ae62c31d9441491613

Activity

  1. juanjux commented on Sep 21, 2017

    @juanjux
    Contributor

    Santi once clarified that only the parent element had the qualified(identifier) role which with the AST that Python produces would be lib. Once we've a renormalization process to modify the three we could add a common parent with the Qualified role.

    #51 (comment)

    We could rethink it, anyway.

    cc @abeaumont

  2. zurk commented on Sep 22, 2017

    @zurk
    Author

    @juanjux Yes, I would be great to have something like Santi suggest in the comment you provided.
    But then this parent identifier shouldn't have the token or full name lib1.lib2.lib3.var. Otherwise, it is confusing.

    Also about LEFT role. In this case, parent qualified identifier should have it and not the last simple identifier.

    So, as I think good to have something like:

    <lib1>:         ['IMPORT', 'PATHNAME', 'IDENTIFIER']
    <>:             ['QUALIFIED', 'IDENTIFIER', 'EXPRESSION', 'LEFT']    // or <lib1.lib2.lib3.var> as token
    <var>:          ['IDENTIFIER', 'EXPRESSION']     // `QUALIFIED` child
    <lib3>:         ['IDENTIFIER', 'EXPRESSION']     // `QUALIFIED` child
    <lib2>:         ['IDENTIFIER', 'EXPRESSION']     // `QUALIFIED` child
    <lib1>:         ['IDENTIFIER', 'EXPRESSION']     // `QUALIFIED` child
    
  3. abeaumont commented on Sep 22, 2017

    @abeaumont
    Contributor

    I guess what to do depens on what Qualified means. Currently it's being used as a module identifier, but instead it probably should be used as currently defined: Qualified is a kind of property identifiers may have, when it's composed of multiple simple identifiers, that is, all but the last one should be qualified. If the AST doesn't provide a separate Qualified node, we shouldn't need it.

    So what should be considered, I think, is whether it's possible to annotate it as commented with current AST. I think it should, but maybe I'm missing something. The same applies to the left role, I think.

  4. juanjux commented on Sep 22, 2017

    @juanjux
    Contributor

    Previously it was just as @abeaumont said, I changed it when Santi told me about the first element if there wasn't a parent element (and there isn't: in the AST, the parent is "Assignment" directly as you can see here: https://github.com/bblfsh/python-driver/blob/master/tests/qualified.py.native).

    I can change it so in a.b.c a and b has the Qualified role again and c doesn't have it if we agree (it's actually easier that way because in the native AST those nodes will have the Attribute internal type).

  5. self-assigned this
    on Oct 25, 2017
  6. juanjux commented on Nov 14, 2017

    @juanjux
    Contributor

    Reopening because I found that while now it works for qualified variable accesses, for method calls the Qualified is not applied to the first elements.

  7. juanjux commented on Nov 14, 2017

    @juanjux
    Contributor

    I've fixed the calls. There is another case that I think is impossible to solve with the current SDK, qualified expressions that are not part of assignments, function calls or arguments, like just:

    a.b.c

    In this case all three nodes will have the Qualified role, but as we've discussed in this thread c shouldn't.

    The problem is that Python's AST generates exactly the same nodes for the three (same internalType and same internalRole) so there isn't really a way to tell the annotation to make c unqualified other than checking than the parent doesn't have the Attribute role, but we don't have a function that can check the parent of the node right now in the ann.go module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions