public void EmbeddedStringsTest() { Pattern.IsFriendly = false; var source = "find -P\"^ 'A'\" -F '.'"; var delimitedText = DelimitedText.BothQuotes(); foreach (var(text, _, status) in delimitedText.Enumerable(source)) { switch (status) { case DelimitedTextStatus.Outside: Console.WriteLine($"outside: {text.Guillemetify()}"); break; case DelimitedTextStatus.Inside: Console.WriteLine($"inside: {text.Guillemetify()}"); break; case DelimitedTextStatus.BeginDelimiter: Console.WriteLine($"begin delimiter: {text.Guillemetify()}"); break; case DelimitedTextStatus.EndDelimiter: Console.WriteLine($"end delimiter: {text.Guillemetify()}"); break; } } }
protected static string[] splitArguments(string arguments) { var delimitedText = DelimitedText.BothQuotes(); var destringified = delimitedText.Destringify(arguments.Replace(@"\", @"\\")); return(destringified.Split("/s+; f").Select(s => delimitedText.Restringify(s, RestringifyQuotes.None)).ToArray()); }
public Replacer(string source) { this.source = source; delimitedText = DelimitedText.BothQuotes(); formatter = new Formatter(); macros = new List <Macro>(); }
public override Verb CreateVerb(string[] tokens) { Color(position, length, Arrays); var index = position + length; var matcher = new Matcher(); if (matcher.IsMatch(source.Substring(index), "-/{)} ')'", false, true)) { var values = matcher[0, 1]; Color(index, matcher[0].Length, Arrays); values = values.Trim(); Array array; if (values.IsEmpty()) { array = new Array(); } else { var destringifier = DelimitedText.BothQuotes(); var items = destringifier.Destringify(values).Split("/s+"); for (var i = 0; i < items.Length; i++) { items[i] = destringifier.Restringify(items[i], RestringifyQuotes.None); } array = new Array(items); } result.Value = array; overridePosition = index + matcher[0].Length; return(new PushArrayLiteral(array)); } return(null); }
public static ObjectGraph FromSingleLine(string singleLine) { var delimitedText = DelimitedText.BothQuotes(); var parsed = delimitedText.Destringify(singleLine); var matcher = new Matcher(); using (var writer = new ObjectGraphWriter()) { foreach (var token in parsed.Split("/s* /(['{};']) /s*")) { switch (token) { case "{": writer.Begin(); break; case "}": writer.End(); break; default: if (matcher.IsMatch(token, REGEX_LINE)) { var name = matcher[0, 1]; var type = matcher[0, 2]; var value = matcher[0, 3]; value = delimitedText.Restringify(value, RestringifyQuotes.None); writer.Write(name, value, type); } else if (matcher.IsMatch(token, REGEX_GROUP)) { var name = matcher[0, 1]; var type = matcher[0, 2]; writer.Write(name, type: type); } break; } } return(writer.ToObjectGraph()); } }
public string Invoke(string sourceText) { var matcher = new Matcher(); var delimitedText = DelimitedText.BothQuotes(); var source = delimitedText.Destringify(sourceText, true); if (matcher.IsMatch(source, pattern)) { for (var i = 0; i < matcher.MatchCount; i++) { var arguments = matcher[i, 1].Split("/s* ',' /s*"); for (var j = 0; j < arguments.Length; j++) { arguments[j] = delimitedText.Restringify(arguments[j], RestringifyQuotes.None); } matcher[i] = Invoke(arguments); } return(delimitedText.Restringify(matcher.ToString(), RestringifyQuotes.None)); } return(sourceText); }