tokenLevelRange

tokenLevelRange
(
T
)
()

Examples

It should return all tokens if there is one level

enum tpl = "1{{a}}2{{b}}3";

auto range = TokenRange(tpl);
auto levelRange = tokenLevelRange(range);

levelRange.array.should.equal([
  [ Token(Token.Type.plain, "1", Properties("")) ],
  [ Token(Token.Type.value, "a", Properties("")) ],
  [ Token(Token.Type.plain, "2", Properties("")) ],
  [ Token(Token.Type.value, "b", Properties("")) ],
  [ Token(Token.Type.plain, "3", Properties("")) ]
]);

It should group the tokens by levels

enum tpl = "1{{value1}}{{#value2}}3{{/value2}}";

auto range = TokenRange(tpl);
auto levelRange = tokenLevelRange(range);

levelRange.array.should.equal([
  [ Token(Token.Type.plain, "1", Properties("")) ],
  [ Token(Token.Type.value, "value1", Properties("")) ],
  [ Token(Token.Type.openBlock, "value2", Properties("")),
      Token(Token.Type.plain, "3", Properties("")),
      Token(Token.Type.closeBlock, "value2", Properties("")) ]
]);

It should group the tokens by levels when the same component is used in the block

enum tpl = "{{#a}}{{#a}}{{#a}}3{{/a}}{{/a}}{{/a}}";

auto range = TokenRange(tpl);
auto levelRange = tokenLevelRange(range);

levelRange.array.should.equal([
  [ Token(Token.Type.openBlock, "a", Properties("")),
      Token(Token.Type.openBlock, "a", Properties("")),
        Token(Token.Type.openBlock, "a", Properties("")),
          Token(Token.Type.plain, "3", Properties("")),
        Token(Token.Type.closeBlock, "a", Properties("")),
      Token(Token.Type.closeBlock, "a", Properties("")),
    Token(Token.Type.closeBlock, "a", Properties("")) ]
]);

It should strip ws from plain tokens

enum tpl = "{{a}}\ntest\n{{a}}";
auto range = TokenRange(tpl);
auto levelRange = tokenLevelRange(range);

levelRange.array.should.equal([
  [ Token(Token.Type.value, "a", Properties("")) ],
  [ Token(Token.Type.plain, "test", Properties("")) ],
  [ Token(Token.Type.value, "a", Properties("")) ]]);

Meta