Skip to content

Commit

Permalink
break :: into :, : anywhere in a slice
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedanese committed Mar 1, 2016
1 parent 34e85ae commit 54bb3a3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,13 +854,23 @@ namespace {
if (peek().kind == Token::BRACKET_R)
throw unexpected(pop(), "parsing index");

// break up "::" into ":", ":" before we start parsing.
if (peek().kind == Token::OPERATOR && peek().data == "::") {
Token joined = pop();
push(Token(Token::OPERATOR, joined.fodder, ":", "", "",
joined.location));
push(Token(Token::OPERATOR, Fodder{}, ":", "", "", joined.location));
}

Token first_token = pop();
if (peek().kind == Token::OPERATOR && peek().data == "::") {
Token joined = pop();
push(Token(Token::OPERATOR, joined.fodder, ":", "", "",
joined.location));
push(Token(Token::OPERATOR, Fodder{}, ":", "", "", joined.location));
}
push(first_token);

if (peek().data != ":")
first = parse(MAX_PRECEDENCE);

Expand Down
16 changes: 16 additions & 0 deletions test_suite/slice.sugar.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ local arrCases = [
input: arr[::],
output: arr,
},
{
input: arr[1::],
output: [1, 2, 3, 4, 5],
},
{
input: arr[1::2],
output: [1, 3, 5],
},
{
input: arr[::2],
output: [0, 2, 4],
Expand Down Expand Up @@ -100,6 +108,14 @@ local strCases = [
input: str[::],
output: str,
},
{
input: str[1::],
output: "12345",
},
{
input: str[1::2],
output: "135",
},
{
input: str[::2],
output: "024",
Expand Down

0 comments on commit 54bb3a3

Please sign in to comment.