File tree 7 files changed +28
-14
lines changed 7 files changed +28
-14
lines changed Original file line number Diff line number Diff line change @@ -432,21 +432,21 @@ struct Function : public AST {
432
432
}
433
433
};
434
434
435
- struct LiteralString ;
436
-
437
435
/* * Represents import "file". */
438
436
struct Import : public AST {
439
- LiteralString *file;
440
- Import (const LocationRange &lr, const Fodder &open_fodder, LiteralString *file)
437
+ // Must be a LiteralString.
438
+ AST *file;
439
+ Import (const LocationRange &lr, const Fodder &open_fodder, AST *file)
441
440
: AST(lr, AST_IMPORT, open_fodder), file(file)
442
441
{
443
442
}
444
443
};
445
444
446
445
/* * Represents importstr "file". */
447
446
struct Importstr : public AST {
448
- LiteralString *file;
449
- Importstr (const LocationRange &lr, const Fodder &open_fodder, LiteralString *file)
447
+ // Must be a LiteralString.
448
+ AST *file;
449
+ Importstr (const LocationRange &lr, const Fodder &open_fodder, AST *file)
450
450
: AST(lr, AST_IMPORTSTR, open_fodder), file(file)
451
451
{
452
452
}
Original file line number Diff line number Diff line change @@ -643,11 +643,11 @@ class Desugarer {
643
643
desugar (ast->body , obj_level);
644
644
desugarParams (ast->params , obj_level);
645
645
646
- } else if (dynamic_cast <const Import *>(ast_)) {
647
- // Nothing to do.
646
+ } else if (auto *ast = dynamic_cast <Import *>(ast_)) {
647
+ desugar (ast-> file , obj_level);
648
648
649
- } else if (dynamic_cast <const Importstr *>(ast_)) {
650
- // Nothing to do.
649
+ } else if (auto *ast = dynamic_cast <Importstr *>(ast_)) {
650
+ desugar (ast-> file , obj_level);
651
651
652
652
} else if (auto *ast = dynamic_cast <InSuper *>(ast_)) {
653
653
desugar (ast->element , obj_level);
Original file line number Diff line number Diff line change @@ -2031,7 +2031,7 @@ class SortImports {
2031
2031
// / Get the value by which the imports should be sorted.
2032
2032
UString sortingKey (Import *import)
2033
2033
{
2034
- return import->file ->value ;
2034
+ return dynamic_cast < const LiteralString*>( import->file ) ->value ;
2035
2035
}
2036
2036
2037
2037
// / Check if `local` expression is used for importing,
Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ limitations under the License.
22
22
/** Unparse the string. */
23
23
UString jsonnet_string_unparse (const UString & str , bool single );
24
24
25
+
26
+ // Note that the following two functions do not handle the quoting of ' and "
27
+ // inside verbatim strings because that quoting is reversible. Thus, that
28
+ // quoting is done at lexing time and undone again at pretty-printing time.
29
+
25
30
/** Escape special characters. */
26
31
UString jsonnet_string_escape (const UString & str , bool single );
27
32
Original file line number Diff line number Diff line change @@ -1509,7 +1509,8 @@ class Interpreter {
1509
1509
1510
1510
case AST_IMPORT: {
1511
1511
const auto &ast = *static_cast <const Import *>(ast_);
1512
- HeapThunk *thunk = import (ast.location , ast.file );
1512
+ const auto *file = static_cast <const LiteralString *>(ast.file );
1513
+ HeapThunk *thunk = import (ast.location , file);
1513
1514
if (thunk->filled ) {
1514
1515
scratch = thunk->content ;
1515
1516
} else {
@@ -1521,7 +1522,8 @@ class Interpreter {
1521
1522
1522
1523
case AST_IMPORTSTR: {
1523
1524
const auto &ast = *static_cast <const Importstr *>(ast_);
1524
- const ImportCacheValue *value = importString (ast.location , ast.file );
1525
+ const auto *file = static_cast <const LiteralString *>(ast.file );
1526
+ const ImportCacheValue *value = importString (ast.location , file);
1525
1527
scratch = makeString (decode_utf8 (value->content ));
1526
1528
} break ;
1527
1529
Original file line number Diff line number Diff line change @@ -138,7 +138,8 @@ <h2 id="lexing">Lexing</h2>
138
138
first subsequent line that does not begin with < i > W</ i > , and it is an error if this line does not
139
139
contain some optional whitespace followed by < code > |||</ code > . The content of the string is the
140
140
concatenation of all the lines that began with < i > W</ i > but with that prefix stripped. The line
141
- ending style in the file is preserved in the string.</ li >
141
+ ending style in the file is preserved in the string. This form cannot be used in
142
+ < code > import</ code > statements.</ li >
142
143
</ ul >
143
144
144
145
< p > Double- and single-quoted strings are allowed to span multiple lines, in which case whatever
Original file line number Diff line number Diff line change @@ -17,14 +17,20 @@ limitations under the License.
17
17
// Can capture variables from another file.
18
18
std.assertEqual ((import "lib/A_20_func.libsonnet" )(), 20 ) &&
19
19
20
+ // Ensure string is quoted.
21
+ std.assertEqual ((import "lib/\u0041 _20_func.libsonnet" )(), 20 ) &&
22
+
20
23
# Test single quoted string.
21
24
std.assertEqual ((import 'lib/A_20_func.libsonnet' )(), 20 ) &&
22
25
# The block string is hard to test because the filename would include a terminating \n
23
26
24
27
// Each import has its own environment, can't be overidden.
25
28
std.assertEqual (local A = 7 ; local lib = import "lib/A_20.libsonnet" ; lib, 20 ) &&
26
29
std.assertEqual (local A = 7 , lib = import "lib/A_20.libsonnet" ; lib, 20 ) &&
30
+
27
31
std.assertEqual (importstr "lib/some_file.txt" , "Hello World!\n " ) &&
32
+ std.assertEqual (importstr "lib/\u0073 ome_file.txt" , "Hello World!\n " ) &&
33
+
28
34
std.assertEqual (import "lib/rel_path.libsonnet" , "rel_path" ) &&
29
35
std.assertEqual (import "lib/rel_path4.libsonnet" , "rel_path" ) &&
30
36
You can’t perform that action at this time.
0 commit comments