getScope

Undocumented in source. Be warned that the author may not have intended to support it.
@safe nothrow
getScope
(
const(Token)[] tokens
,
size_t line
)

Examples

Get the spec function and scope that contains a lambda

const(Token)[] tokens = [];
splitMultilinetokens(fileToDTokens("test/values.d"), tokens);

auto result = getScope(tokens, 101);
auto identifierStart = getPreviousIdentifier(tokens, result.begin);

tokens[identifierStart .. result.end].toString.strip.should.equal("it(\"should throw an exception if we request 2 android devices\", {
    ({
      auto result = [ device1.idup, device2.idup ].filterBy(RunOptions(\"\", \"android\", 2)).array;
    }).should.throwException!DeviceException.withMessage.equal(\"You requested 2 `androdid` devices, but there is only 1 healthy.\");
  }");

Get the a method scope and signature

const(Token)[] tokens = [];
splitMultilinetokens(fileToDTokens("test/class.d"), tokens);

auto result = getScope(tokens, 10);
auto identifierStart = getPreviousIdentifier(tokens, result.begin);

tokens[identifierStart .. result.end].toString.strip.should.equal("void bar() {
      assert(false);
  }");

Get the a method scope without assert

const(Token)[] tokens = [];
splitMultilinetokens(fileToDTokens("test/class.d"), tokens);

auto result = getScope(tokens, 14);
auto identifierStart = getPreviousIdentifier(tokens, result.begin);

tokens[identifierStart .. result.end].toString.strip.should.equal("void bar2() {
      enforce(false);
  }");

Meta