feat(charka): STRING y UNSTRING — manejo de cadenas
Dos verbos comunes de COBOL para construir y partir cadenas.
- IR: Stmt::StringConcat { sources, into } y
Stmt::Unstring { source, delimiter, into }.
- Parser: STRING a b DELIMITED BY SIZE INTO t END-STRING y
UNSTRING s DELIMITED BY d INTO a b c END-UNSTRING.
- Codegen: STRING -> format! concatenado; UNSTRING -> un bloque que
parte con str::split y reparte los trozos a los destinos.
- Shadow: el intérprete concatena / parte el texto y lo reparte.
- Corpus: programa nuevo 12-cadenas. Verificado: el intérprete sombra
y el crate compilado por scaffold dan la misma salida.
Alcance v1: STRING con DELIMITED BY SIZE (otros delimitadores se
ignoran); sin WITH POINTER ni ON OVERFLOW.
Tests: charka-ir 25, charka-codegen 19, charka-shadow 17. fmt +
clippy limpios.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -367,6 +367,23 @@ mod tests {
|
||||
assert!(out.contains(".saturating_sub(1)]"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn string_concatenates_and_unstring_splits() {
|
||||
let out = gen("DATA DIVISION.\n\
|
||||
WORKING-STORAGE SECTION.\n\
|
||||
01 WS-A PIC X(4).\n\
|
||||
01 WS-B PIC X(4).\n\
|
||||
01 WS-OUT PIC X(10).\n\
|
||||
01 WS-SRC PIC X(10).\n\
|
||||
PROCEDURE DIVISION.\n\
|
||||
MAIN.\n\
|
||||
STRING WS-A WS-B DELIMITED BY SIZE INTO WS-OUT END-STRING.\n\
|
||||
UNSTRING WS-SRC DELIMITED BY ',' INTO WS-A WS-B END-UNSTRING.\n");
|
||||
assert!(out.contains("self.ws_out.store(&format!("));
|
||||
assert!(out.contains("__src.split(__delim.as_str())"));
|
||||
assert!(out.contains("__it.next().unwrap_or(\"\")"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_program_still_compiles_shape() {
|
||||
let out = gen("");
|
||||
|
||||
Reference in New Issue
Block a user