token_type: assign token_type to worddesc during wordsplit

Also added some tests for that part.
This commit is contained in:
Khaïs COLIN 2025-04-09 13:25:58 +02:00
parent 4d6a64bf6a
commit 3ec90f7770
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
6 changed files with 254 additions and 11 deletions

177
test.sh
View file

@ -607,4 +607,181 @@ expecting <<EOF
╰─ redirections = (empty redir list)
EOF
when_run <<EOF "token type attribution is correct"
.debug
.exec
()|||&&>>><<<
EOF
expecting <<EOF
[dbg: 1]
[exec: 0]
╰─ t_simple_cmd
├─ line = 0
├─ t_wordlist
│ ├─ t_worddesc
│ │ ├─ word = [(]
│ │ ├─ marker = [ ]
│ │ ├─ flags = 0
│ │ ╰─ t_token_type = OPEN_PARENTH_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = [)]
│ │ ├─ marker = [ ]
│ │ ├─ flags = 0
│ │ ╰─ t_token_type = CLOSE_PARENTH_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = [||]
│ │ ├─ marker = [ ]
│ │ ├─ flags = 0
│ │ ╰─ t_token_type = OR_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = [|]
│ │ ├─ marker = [ ]
│ │ ├─ flags = 0
│ │ ╰─ t_token_type = PIPE_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = [&&]
│ │ ├─ marker = [ ]
│ │ ├─ flags = 0
│ │ ╰─ t_token_type = AND_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = [>>]
│ │ ├─ marker = [ ]
│ │ ├─ flags = 0
│ │ ╰─ t_token_type = OUT_APPEND_REDIR_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = [>]
│ │ ├─ marker = [ ]
│ │ ├─ flags = 0
│ │ ╰─ t_token_type = OUT_TRUNC_REDIR_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = [<<]
│ │ ├─ marker = [ ]
│ │ ├─ flags = 0
│ │ ╰─ t_token_type = HERE_DOC_REDIR_TOKEN
│ ╰─ t_worddesc
│ ├─ word = [<]
│ ├─ marker = [ ]
│ ├─ flags = 0
│ ╰─ t_token_type = IN_REDIR_TOKEN
╰─ redirections = (empty redir list)
EOF
when_run <<EOF "token type attribution is correct when tokens are double-quoted"
.debug
.exec
"(" ")" "|" "||" "&&" ">" ">>" "<" "<<"
EOF
expecting <<EOF
[dbg: 1]
[exec: 0]
╰─ t_simple_cmd
├─ line = 0
├─ t_wordlist
│ ├─ t_worddesc
│ │ ├─ word = ["("]
│ │ ├─ marker = [ " ]
│ │ ├─ flags = 34
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = [")"]
│ │ ├─ marker = [ " ]
│ │ ├─ flags = 34
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = ["|"]
│ │ ├─ marker = [ " ]
│ │ ├─ flags = 34
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = ["||"]
│ │ ├─ marker = [ "" ]
│ │ ├─ flags = 34
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = ["&&"]
│ │ ├─ marker = [ "" ]
│ │ ├─ flags = 34
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = [">"]
│ │ ├─ marker = [ " ]
│ │ ├─ flags = 34
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = [">>"]
│ │ ├─ marker = [ "" ]
│ │ ├─ flags = 34
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = ["<"]
│ │ ├─ marker = [ " ]
│ │ ├─ flags = 34
│ │ ╰─ t_token_type = WORD_TOKEN
│ ╰─ t_worddesc
│ ├─ word = ["<<"]
│ ├─ marker = [ "" ]
│ ├─ flags = 34
│ ╰─ t_token_type = WORD_TOKEN
╰─ redirections = (empty redir list)
EOF
when_run <<EOF "token type attribution is correct when tokens are single-quoted"
.debug
.exec
'(' ')' '|' '||' '&&' '>' '>>' '<' '<<'
EOF
expecting <<EOF
[dbg: 1]
[exec: 0]
╰─ t_simple_cmd
├─ line = 0
├─ t_wordlist
│ ├─ t_worddesc
│ │ ├─ word = ['(']
│ │ ├─ marker = [ ' ]
│ │ ├─ flags = 2
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = [')']
│ │ ├─ marker = [ ' ]
│ │ ├─ flags = 2
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = ['|']
│ │ ├─ marker = [ ' ]
│ │ ├─ flags = 2
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = ['||']
│ │ ├─ marker = [ '' ]
│ │ ├─ flags = 2
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = ['&&']
│ │ ├─ marker = [ '' ]
│ │ ├─ flags = 2
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = ['>']
│ │ ├─ marker = [ ' ]
│ │ ├─ flags = 2
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = ['>>']
│ │ ├─ marker = [ '' ]
│ │ ├─ flags = 2
│ │ ╰─ t_token_type = WORD_TOKEN
│ ├─ t_worddesc
│ │ ├─ word = ['<']
│ │ ├─ marker = [ ' ]
│ │ ├─ flags = 2
│ │ ╰─ t_token_type = WORD_TOKEN
│ ╰─ t_worddesc
│ ├─ word = ['<<']
│ ├─ marker = [ '' ]
│ ├─ flags = 2
│ ╰─ t_token_type = WORD_TOKEN
╰─ redirections = (empty redir list)
EOF
finalize