Skip to content

Commit a0179ed

Browse files
axellewmarijnh
authored andcommitted
Add support for import expressions.
Committer: Axel Lewenhaupt <[email protected]>
1 parent 09943f9 commit a0179ed

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

mode/soy/soy.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,26 @@
402402
}
403403
return expression(stream, state);
404404

405+
case "import":
406+
if (stream.eat(";")) {
407+
state.soyState.pop();
408+
state.indent -= 2 * config.indentUnit;
409+
return null;
410+
}
411+
if (stream.match(/\w+(?=\s+as)/)) {
412+
return "variable";
413+
}
414+
if (match = stream.match(/\w+/)) {
415+
return /(from|as)/.test(match[0]) ? "keyword" : "def";
416+
}
417+
if (match = stream.match(/^["']/)) {
418+
state.soyState.push("string");
419+
state.quoteKind = match[0];
420+
return "string";
421+
}
422+
stream.next();
423+
return null;
424+
405425
case "tag":
406426
var endTag = state.tag[0] == "/";
407427
var tagName = endTag ? state.tag.substring(1) : state.tag;
@@ -499,6 +519,10 @@
499519
state.indent += 2 * config.indentUnit;
500520
state.soyState.push("tag");
501521
return "keyword";
522+
} else if (!state.context && stream.match(/\bimport\b/)) {
523+
state.soyState.push("import");
524+
state.indent += 2 * config.indentUnit;
525+
return "keyword";
502526
}
503527

504528
return tokenUntil(stream, state, /\{|\s+\/\/|\/\*/);

mode/soy/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,7 @@
252252
'[keyword {let] [def $myList]: [[[[[string \'a\'] ] ] [keyword /}] ' +
253253
'[keyword {let] [def $test]: [[[variable $a] [operator +] [atom 1] [keyword for] ' +
254254
'[def $a] [keyword in] [variable-2 $myList] [keyword if] [variable-2 $a] [operator >=] [atom 3] ] [keyword /}]');
255+
256+
MT('import',
257+
'[keyword import] {[def Name], [variable Person] [keyword as] [def P]} [keyword from] [string \'examples/proto/example.proto\'];');
255258
})();

0 commit comments

Comments
 (0)