summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorÁkos Kőrösi <korakos99@gmail.com>2026-05-21 20:15:58 +0200
committerÁkos Kőrösi <korakos99@gmail.com>2026-05-21 20:15:58 +0200
commit4b73bf960895a139330bf4c0d0317e5d2f48e06b (patch)
treea7c50744a2835327d5c4cd974015a6c897328e4e /src
parent4f0df837a5d97007d490d17d1180dacb5e195875 (diff)
fix var expansion in double quotes
Diffstat (limited to 'src')
-rw-r--r--src/lexparse.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/lexparse.c b/src/lexparse.c
index de14c0a..14566f5 100644
--- a/src/lexparse.c
+++ b/src/lexparse.c
@@ -1,5 +1,6 @@
#include <ctype.h>
#include <stddef.h>
+#include <stdio.h>
#include "syntax.h"
#include "../src/utils.h"
@@ -47,6 +48,7 @@ static MaybeChunk handle_dollar_expansion(char* line, size_t* pos, QuotationMode
} else if (line[*pos] == '_' || isalnum(line[*pos])){
String buf = make_String(256);
while (line[*pos] == '_' || isalnum(line[*pos])) {
+ printf("%c\n", line[*pos]);
push_to_String(&buf, line[(*pos)++]);
}
return (MaybeChunk){
@@ -95,22 +97,34 @@ static Chunk collect_single_q_section(char* line, size_t* pos) {
};
}
-static Chunk collect_double_q_section(char* line, size_t* pos) {
+static void collect_double_q_section(char* line, Word* result_buf, size_t* pos) {
// TODO: add the extra double-q expansions
(*pos)++;
- String buf = make_String(256);
- size_t i;
- for (i = *pos; line[i] != '\"' && line[i] != '\0'; i++) {
- push_to_String(&buf, line[i]);
+ printf("%c\n", line[*pos]);
+ String lit_buf = make_String(256);
+
+ while (line[*pos] != '\"' && line[*pos] != '\0') {
+ // TODO: handle escapes
+ if (line[*pos] == '$') {
+ MaybeChunk m_dollar = handle_dollar_expansion(line, pos, DOUBLE_Q);
+ if (m_dollar.some) {
+ if (lit_buf.count>0) {
+ push_to_Word(result_buf, (Chunk){.qmode = DOUBLE_Q, .kind = CHUNK_LIT, .as.lit_str = inner(&lit_buf)});
+ lit_buf = make_String(256);
+ }
+ push_to_Word(result_buf, m_dollar.value);
+ } else {
+ push_to_String(&lit_buf, '$');
+ }
+ } else {
+ push_to_String(&lit_buf, line[*pos]);
+ }
}
- if (line[i] == '\0') exit(44);
+ if (line[(*pos)++] == '\0') exit(46);
- *pos = ++i;
- return (Chunk){
- .qmode = DOUBLE_Q,
- .kind = CHUNK_LIT,
- .as.lit_str = inner(&buf)
- };
+ if (lit_buf.count > 0) {
+ push_to_Word(result_buf, (Chunk){.qmode = DOUBLE_Q, .kind = CHUNK_LIT, .as.lit_str = inner(&lit_buf)});
+ }
}
DECLARE_MAYBE(SpecialToken, MaybeSpecialToken)
@@ -199,8 +213,7 @@ TokenVec* lex_level(char* line, size_t* pos, char until, TokenVecVec* tok_seq_po
Chunk chunk = collect_single_q_section(line, pos);
push_to_Word(&buf.word_germ, chunk);
} else if (line[*pos] == '\"') {
- Chunk chunk = collect_double_q_section(line, pos);
- push_to_Word(&buf.word_germ, chunk);
+ collect_double_q_section(line, &buf.word_germ,pos);
} else if (line[*pos] == '$') {
MaybeChunk dollar_chunk = handle_dollar_expansion(line, pos, UN_Q);
if (dollar_chunk.some) {