Error in trying to use an inout(char)[] with a regex
Shriramana Sharma via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Oct 16 19:06:36 PDT 2015
Hello. Please see the following code:
import std.range;
string textAttr(T)(T spec) if (is(ElementType!(T): const(char)[]))
{
return "";
// made dummy for illustration; actually this runs a foreach loop on the
// individual items in spec, analyses them and passes them to
// appropriate subroutines for processing and returns their output to
// the caller
//
// made into a separate function taking either a range or array so that
// it can be passed either the output of splitter or args[1 .. $]
}
string textAttr(const(char)[] spec)
{
import std.algorithm: splitter;
return textAttr(splitter(spec));
}
inout(char)[] applyTextAttr(inout(char)[] text)
{
import std.regex;
static auto inlineRE = ctRegex!`\$\(ta (.*?)\)`;
return text.replaceAll!(m => textAttr(m[1]))(inlineRE);
}
void main(string [] args)
{
import std.stdio;
if (args.length == 1) return;
alias ta = textAttr;
writeln(ta(args[1 .. $]), "text1", ta("u g /w"), "text2", ta("off"));
}
Now upon trying to compile this I'm getting the errors:
$ dmd inout_test.d
/usr/include/dmd/phobos/std/regex/package.d(557): Error: variable
std.regex.RegexMatch!(inout(char)[], BacktrackingMatcher).RegexMatch._input
only parameters or stack based variables can be inout
/usr/include/dmd/phobos/std/regex/package.d(374): Error: variable
std.regex.Captures!(inout(char)[], ulong).Captures._input only parameters or
stack based variables can be inout
/usr/include/dmd/phobos/std/regex/package.d(419): Error: inout on return
means inout must be on a parameter as well for @property R()
/usr/include/dmd/phobos/std/regex/package.d(425): Error: inout on return
means inout must be on a parameter as well for @property R()
/usr/include/dmd/phobos/std/regex/package.d(431): Error: inout on return
means inout must be on a parameter as well for @property R()
/usr/include/dmd/phobos/std/regex/package.d(438): Error: inout on return
means inout must be on a parameter as well for @property R()
/usr/include/dmd/phobos/std/regex/package.d(445): Error: inout on return
means inout must be on a parameter as well for @property R()
/usr/include/dmd/phobos/std/regex/package.d(558): Error: template instance
std.regex.Captures!(inout(char)[], ulong) error instantiating
/usr/include/dmd/phobos/std/regex/package.d(684): instantiated from
here: RegexMatch!(inout(char)[], BacktrackingMatcher)
/usr/include/dmd/phobos/std/regex/package.d(878): instantiated from
here: matchMany!(BacktrackingMatcher, StaticRegex!char, inout(char)[])
/usr/include/dmd/phobos/std/regex/package.d(751): instantiated from
here: matchAll!(inout(char)[], StaticRegex!char)
/usr/include/dmd/phobos/std/regex/package.d(1210): instantiated from
here: replaceAllWith!((m, sink) => sink.put(fun(m)), matchAll, inout(char)
[], StaticRegex!char)
inout_test.d(22): instantiated from here: replaceAll!((m) =>
textAttr(m[1]), inout(char)[], StaticRegex!char)
/usr/include/dmd/phobos/std/regex/package.d(599): Error: inout on return
means inout must be on a parameter as well for @property R()
/usr/include/dmd/phobos/std/regex/package.d(605): Error: inout on return
means inout must be on a parameter as well for @property R()
/usr/include/dmd/phobos/std/regex/package.d(611): Error: inout on return
means inout must be on a parameter as well for @property R()
I'm totally not clear as to what the error about inout means, and how I can
fix this. Please advise. Thanks!
--
Shriramana Sharma, Penguin #395953
More information about the Digitalmars-d-learn
mailing list