Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse quotes and candidates for expansion/substitution as a tree #2

Closed
emersion opened this issue Jun 20, 2018 · 1 comment
Closed
Labels
enhancement New feature or request

Comments

@emersion
Copy link
Owner

That means, don't unquote when parsing. That probably means: keep a list of {unquoted, quoted} fragments when parsing.

@emersion emersion added the enhancement New feature or request label Jun 20, 2018
@emersion
Copy link
Owner Author

emersion commented Aug 1, 2018

Err, it's probably more a tree than a flat list. A token can contain:

  • Unquoted strings
  • Quoted strings (" or ')
  • Candidates for parameter expansion (${expression} or $variable)
  • Candidates for command substitution ($(command) or `command`)
  • Candidates for arithmetic expansion ($((expression)))

Examples:

echo "hey 'there'" # hey 'there'
echo 'hey "there"' # hey "there"
echo "hey $(echo "there")" # hey there
echo `echo \`echo hey\`` # hey
echo $(echo $(echo hey `echo there $(echo how are you)`)) # hey there how are you
echo $(($x-1))
echo ${x:-$(ls)} # ls is executed only if x is null or unset

WIP proposal:

enum mrsh_token_type {
    TOKEN_STRING,
    TOKEN_PARAMETER,
    TOKEN_COMMAND,
    TOKEN_ARITHMETIC,
    TOKEN_LIST,
};

struct mrsh_token {
    enum mrsh_token_type type;
};

struct mrsh_token_string {
    struct mrsh_token token;
    char *str;
    bool single_quoted;
};

struct mrsh_token_parameter {
    struct mrsh_token token;
    char *name;
    char *op;
    struct mrsh_token *arg;
};

struct mrsh_token_command {
    struct mrsh_token token;
    char *command;
    bool back_quoted;
};

struct mrsh_token_arithmetic {
    struct mrsh_token token;
    struct mrsh_token *expression;
};

struct mrsh_token_list {
    struct mrsh_token token;
    struct mrsh_array children; // struct mrsh_token *
    bool double_quoted;
};

@emersion emersion changed the title Correctly handle quoting Parse quotes and candidates for expansion/substitution Aug 1, 2018
@emersion emersion changed the title Parse quotes and candidates for expansion/substitution Parse quotes and candidates for expansion/substitution as a tree Aug 1, 2018
emersion added a commit that referenced this issue Aug 2, 2018
This patch adds some groundwork for future full token support (with
candidates for expansion and substitution).

See #2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant