← 输入框|github.com|刷新
Skip to content

Check the type of element inside the list for str.join() #2366

Open

Description

@ubaidsk
          Actually, I am still not checking the type of element inside the list which should be str, I checked grammar for asr but didn't get anything on how to iterate over list expression as it must be a list of str expressions. ast is getting generated perfectly but, I don't know how can I map ast nodes to asr nodes.

Originally posted by @Agent-Hellboy in #2364 (comment)

Activity

  1. ubaidsk commented on Oct 6, 2023

    @ubaidsk
    CollaboratorAuthor

    You can refer the following approach to get the List type:

    if (ASR::is_a<ASR::List_t>(*param_type)) {
    if (ASR::is_a<ASR::List_t>(*arg_type)) {
    ASR::ttype_t *param_elem = ASR::down_cast<ASR::List_t>(param_type)->m_type;

  2. Agent-Hellboy commented on Oct 6, 2023

    @Agent-Hellboy
    Contributor

    You can refer the following approach to get the List type:

    if (ASR::is_a<ASR::List_t>(*param_type)) {
    if (ASR::is_a<ASR::List_t>(*arg_type)) {
    ASR::ttype_t *param_elem = ASR::down_cast<ASR::List_t>(param_type)->m_type;

    sure

  3. Agent-Hellboy commented on Oct 9, 2023

    @Agent-Hellboy
    Contributor

    Hi @Shaikh-Ubaid, I am still not able to iterate over the List_t ASR node, I am not able to get any info ASR.asdl

    How can I iterate over expr_t to get the list element?

    here is expr_t

    struct expr_t // Sum
    {
        const static asrType class_type = asrType::expr;
        asr_t base;
        exprType type;
    };
    

    I guess expr can be expr = expr | list_of_expr right?

    I am kinda confused, the example you shared is to check if the expression is list type or not.

  4. ubaidsk commented on Oct 9, 2023

    @ubaidsk
    CollaboratorAuthor

    I am still not able to iterate over the List_t ASR node

    You need not iterate over the List_t. You can simply get the element type of the list (using the above shared approach) and check if the element type is a string or not.

    The List already contains elements of the same type.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions