Skip to content

Commit

Permalink
Implemented 'StringFormat' (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown6656 committed Jul 13, 2020
1 parent b577bfd commit cbb42d3
Show file tree
Hide file tree
Showing 11 changed files with 356 additions and 121 deletions.
12 changes: 6 additions & 6 deletions new/AutoItInterpreter/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

//////////////////////////////////////////////////////////////////////////
// Autogenerated 2020-07-13 10:29:19.365 //
// Autogenerated 2020-07-13 15:26:52.055 //
// ANY CHANGES TO THIS DOCUMENT WILL BE LOST UPON RE-GENERATION //
//////////////////////////////////////////////////////////////////////////

using System.Reflection;
using System;

[assembly: AssemblyVersion("0.5.1045.20195")]
[assembly: AssemblyFileVersion("0.5.1045.20195")]
[assembly: AssemblyInformationalVersion("53153e693226163009d9ef9f010a66e9762ffbde")]
[assembly: AssemblyVersion("0.5.1055.20195")]
[assembly: AssemblyFileVersion("0.5.1055.20195")]
[assembly: AssemblyInformationalVersion("b577bfd8fb4d7256e4ed61801285a044356294bb")]
[assembly: AssemblyCompany("Unknown6656")]
[assembly: AssemblyCopyright("Copyright © 2018 - 2020, Unknown6656")]
[assembly: AssemblyProduct("AutoIt3 Interpreter by Unknown6656")]
Expand All @@ -20,6 +20,6 @@ public static class __module__
public static string Author { get; } = "Unknown6656";
public static string Year { get; } = "2018 - 2020";
public static string Copyright { get; } = "Copyright © 2018 - 2020, Unknown6656";
public static Version? InterpreterVersion { get; } = Version.Parse("0.5.1045.20195");
public static string GitHash { get; } = "53153e693226163009d9ef9f010a66e9762ffbde";
public static Version? InterpreterVersion { get; } = Version.Parse("0.5.1055.20195");
public static string GitHash { get; } = "b577bfd8fb4d7256e4ed61801285a044356294bb";
}
2 changes: 1 addition & 1 deletion new/AutoItInterpreter/AutoItInterpreter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>enable</Nullable>
<StartupObject>$Program.$Main</StartupObject>
<!--<StartupObject>$Program.$Main</StartupObject>-->
<OutDir>$(SolutionDir)bin</OutDir>
<LangVersion>preview</LangVersion>
<Deterministic>false</Deterministic>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,19 @@ public sealed class FrameworkFunctions
ProvidedNativeFunction.Create(nameof(ObjName), 1, 2, ObjName, 1),
ProvidedNativeFunction.Create(nameof(StringAddCR), 1, StringAddCR),
ProvidedNativeFunction.Create(nameof(StringCompare), 2, 3, StringCompare, Variant.Zero),
ProvidedNativeFunction.Create(nameof(StringFormat), , StringFormat),
ProvidedNativeFunction.Create(nameof(StringFromASCIIArray), , StringFromASCIIArray),
ProvidedNativeFunction.Create(nameof(StringInStr), , StringInStr),
ProvidedNativeFunction.Create(nameof(StringFormat), 1, 33, StringFormat),
// ProvidedNativeFunction.Create(nameof(StringFromASCIIArray), , StringFromASCIIArray),
// ProvidedNativeFunction.Create(nameof(StringInStr), , StringInStr),
ProvidedNativeFunction.Create(nameof(StringLeft), 2, StringLeft),
ProvidedNativeFunction.Create(nameof(StringLen), 1, StringLen),
ProvidedNativeFunction.Create(nameof(StringLower), 1, StringLower),
ProvidedNativeFunction.Create(nameof(StringMid), 2, 3, StringMid, -1),
ProvidedNativeFunction.Create(nameof(StringRegExp), , StringRegExp),
ProvidedNativeFunction.Create(nameof(StringRegExpReplace ), , StringRegExpReplace ),
ProvidedNativeFunction.Create(nameof(StringReplace), , StringReplace),
ProvidedNativeFunction.Create(nameof(StringReverse), , StringReverse),
// ProvidedNativeFunction.Create(nameof(StringRegExp), , StringRegExp),
// ProvidedNativeFunction.Create(nameof(StringRegExpReplace ), , StringRegExpReplace ),
// ProvidedNativeFunction.Create(nameof(StringReplace), , StringReplace),
// ProvidedNativeFunction.Create(nameof(StringReverse), , StringReverse),
ProvidedNativeFunction.Create(nameof(StringRight), 2, StringRight),
ProvidedNativeFunction.Create(nameof(StringSplit), , StringSplit),
// ProvidedNativeFunction.Create(nameof(StringSplit), , StringSplit),
ProvidedNativeFunction.Create(nameof(StringStripCR), 1, StringStripCR),
ProvidedNativeFunction.Create(nameof(StringStripWS), 2, StringStripWS),
ProvidedNativeFunction.Create(nameof(StringToASCIIArray), 1, 4, StringToASCIIArray, Variant.Zero, Variant.Default, Variant.Zero),
Expand Down Expand Up @@ -1477,6 +1477,7 @@ public static FunctionReturnValue ObjGet(CallFrame frame, Variant[] args)
string path = args[0].ToString();


throw new NotImplementedException();
}

public static FunctionReturnValue ObjName(CallFrame frame, Variant[] args)
Expand All @@ -1503,19 +1504,17 @@ public static FunctionReturnValue ObjName(CallFrame frame, Variant[] args)
_ => StringComparison.CurrentCultureIgnoreCase,
});

public static FunctionReturnValue StringFormat(CallFrame frame, Variant[] args)
{
}

public static FunctionReturnValue StringFromASCIIArray(CallFrame frame, Variant[] args)
{

}

public static FunctionReturnValue StringInStr(CallFrame frame, Variant[] args)
{
public static FunctionReturnValue StringFormat(CallFrame frame, Variant[] args) => (Variant)StringFormatter.FormatString(args[0].ToString(), args[1..]);

}
// public static FunctionReturnValue StringFromASCIIArray(CallFrame frame, Variant[] args)
// {
//
// }
//
// public static FunctionReturnValue StringInStr(CallFrame frame, Variant[] args)
// {
//
// }

public static FunctionReturnValue StringLeft(CallFrame frame, Variant[] args)
{
Expand Down Expand Up @@ -1543,25 +1542,25 @@ public static FunctionReturnValue StringMid(CallFrame frame, Variant[] args)
return (Variant)(len < 0 ? "" : str.Substring(start, len));
}

public static FunctionReturnValue StringRegExp(CallFrame frame, Variant[] args)
{

}

public static FunctionReturnValue StringRegExpReplace(CallFrame frame, Variant[] args)
{

}

public static FunctionReturnValue StringReplace(CallFrame frame, Variant[] args)
{

}

public static FunctionReturnValue StringReverse(CallFrame frame, Variant[] args)
{

}
// public static FunctionReturnValue StringRegExp(CallFrame frame, Variant[] args)
// {
//
// }
//
// public static FunctionReturnValue StringRegExpReplace(CallFrame frame, Variant[] args)
// {
//
// }
//
// public static FunctionReturnValue StringReplace(CallFrame frame, Variant[] args)
// {
//
// }
//
// public static FunctionReturnValue StringReverse(CallFrame frame, Variant[] args)
// {
//
// }

public static FunctionReturnValue StringRight(CallFrame frame, Variant[] args)
{
Expand All @@ -1575,10 +1574,10 @@ public static FunctionReturnValue StringRight(CallFrame frame, Variant[] args)
});
}

public static FunctionReturnValue StringSplit(CallFrame frame, Variant[] args)
{

}
// public static FunctionReturnValue StringSplit(CallFrame frame, Variant[] args)
// {
//
// }

public static FunctionReturnValue StringStripCR(CallFrame frame, Variant[] args) => (Variant)args[0].ToString().Replace("\r", "");

Expand Down
2 changes: 1 addition & 1 deletion new/AutoItInterpreter/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"AutoItInterpreter": {
"commandName": "Project",
"commandLineArgs": "-vv -t ../test/test"
"commandLineArgs": "-vq -t ../test/unittest-stringformat"
}
}
}
87 changes: 38 additions & 49 deletions new/AutoItInterpreter/Runtime/AU3Thread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,44 @@ protected override Union<InterpreterError, Variant> InternalExec(Variant[] args)
public sealed class AU3CallFrame
: CallFrame
{
private const RegexOptions _REGEX_OPTIONS = RegexOptions.IgnoreCase | RegexOptions.Compiled;
private static readonly Regex REGEX_INTERNAL_LABEL = new Regex(@"^§\w+$", _REGEX_OPTIONS);
private static readonly Regex REGEX_VARIABLE = new Regex(@"\$([^\W\d]|[^\W\d]\w*)\b", _REGEX_OPTIONS);
private static readonly Regex REGEX_GOTO = new Regex(@"^goto\s+(?<label>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_WHILE = new Regex(@"^while\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_WEND = new Regex(@"^wend$", _REGEX_OPTIONS);
private static readonly Regex REGEX_NEXT = new Regex(@"^next$", _REGEX_OPTIONS);
private static readonly Regex REGEX_EXIT = new Regex(@"^exit(\b\s*(?<code>.+))?$", _REGEX_OPTIONS);
private static readonly Regex REGEX_RETURN = new Regex(@"^return(\b\s*(?<value>.+))?$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FOR = new Regex(@"^for\s+.+$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FORTO = new Regex(@"^for\s+(?<start>.+)\s+to\s+(?<stop>.+?)(\s+step\s+(?<step>.+))?$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FORIN = new Regex(@"^for\s+(?<variable>.+)\s+in\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FORIN_VARIABLES = new Regex(@"^\$(?<key>[^\W\d]|[^\W\d]\w*)\s*,\s*\$(?<value>[^\W\d]|[^\W\d]\w*)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_WITH = new Regex(@"^with\s+(?<variable>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDWITH = new Regex(@"^endwith$", _REGEX_OPTIONS);
private static readonly Regex REGEX_REDIM = new Regex(@"^redim\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_DO = new Regex(@"^do$", _REGEX_OPTIONS);
private static readonly Regex REGEX_UNTIL = new Regex(@"^until\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_IF = new Regex(@"^(?<elif>else)?if\s+(?<condition>.+)\s+then$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ELSE = new Regex(@"^else$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDIF = new Regex(@"^endif$", _REGEX_OPTIONS);
private static readonly Regex REGEX_DECLARATION_MODIFIER = new Regex(@"^(local|static|global|const|dim|enum|step)\b", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENUM_STEP = new Regex(@"^(?<op>[+\-*]?)(?<step>\d+)\b", _REGEX_OPTIONS);
private static readonly Regex REGEX_INCLUDE = new Regex(@"^include?\s+(?<open>[""'<])(?<path>(?:(?!\k<close>).)+)(?<close>[""'>])$", _REGEX_OPTIONS);
private static readonly Regex REGEX_CONTINUELOOP_EXITLOOP = new Regex(@"^(?<mode>continue|exit)loop\s*(?<level>.+)?\s*$", _REGEX_OPTIONS);
private static readonly Regex REGEX_SELECT = new Regex(@"^select$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDSELECT = new Regex(@"^endselect$", _REGEX_OPTIONS);
private static readonly Regex REGEX_SWITCH = new Regex(@"^switch\b\s*(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDSWITCH = new Regex(@"^endswitch$", _REGEX_OPTIONS);
private static readonly Regex REGEX_CASE = new Regex(@"^case\b\s*(?<expression>.+)*$", _REGEX_OPTIONS);
private static readonly Regex REGEX_CONTINUECASE = new Regex(@"^continuecase$", _REGEX_OPTIONS);

private readonly ConcurrentDictionary<string, IEnumerator<(Variant key, Variant value)>> _iterators = new();
private readonly ConcurrentStack<Variable> _withcontext_stack = new ConcurrentStack<Variable>();
private readonly ConcurrentStack<bool> _if_stack = new ConcurrentStack<bool>();
private readonly ConcurrentStack<string> _while_stack = new();
private readonly ConcurrentStack<(Variant? switch_expression, bool case_handled)> _switchselect_stack = new();

private volatile int _instruction_pointer = 0;
private List<(SourceLocation LineLocation, string LineContent)> _line_cache;

Expand All @@ -289,7 +327,6 @@ public sealed class AU3CallFrame
public Dictionary<string, int> InternalJumpLabels => _line_cache.WithIndex().Where(l => REGEX_INTERNAL_LABEL.IsMatch(l.Item.LineContent)).ToDictionary(l => l.Item.LineContent, l => l.Index);



internal AU3CallFrame(AU3Thread thread, CallFrame? caller, AU3Function function, Variant[] args)
: base(thread, caller, function, args)
{
Expand Down Expand Up @@ -548,19 +585,6 @@ private void InsertReplaceSourceCode(int instruction_ptr, params string[] lines)
return InterpreterResult.OK;
}






// TODO
private readonly ConcurrentDictionary<string, IEnumerator<(Variant key, Variant value)>> _iterators = new();
private readonly ConcurrentStack<Variable> _withcontext_stack = new ConcurrentStack<Variable>();
private readonly ConcurrentStack<bool> _if_stack = new ConcurrentStack<bool>();
private readonly ConcurrentStack<string> _while_stack = new();

private readonly ConcurrentStack<(Variant? switch_expression, bool case_handled)> _switchselect_stack = new();

private InterpreterError? MoveToEndOf(BlockStatementType type)
{
SourceLocation init = CurrentLocation;
Expand Down Expand Up @@ -628,41 +652,6 @@ private void InsertReplaceSourceCode(int instruction_ptr, params string[] lines)
return depth == 0 ? null : WellKnownError("error.no_matching_close", type, init);
}



private const RegexOptions _REGEX_OPTIONS = RegexOptions.IgnoreCase | RegexOptions.Compiled;
private static readonly Regex REGEX_INTERNAL_LABEL = new Regex(@"^§\w+$", _REGEX_OPTIONS);
private static readonly Regex REGEX_VARIABLE = new Regex(@"\$([^\W\d]|[^\W\d]\w*)\b", _REGEX_OPTIONS);
private static readonly Regex REGEX_GOTO = new Regex(@"^goto\s+(?<label>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_WHILE = new Regex(@"^while\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_WEND = new Regex(@"^wend$", _REGEX_OPTIONS);
private static readonly Regex REGEX_NEXT = new Regex(@"^next$", _REGEX_OPTIONS);
private static readonly Regex REGEX_EXIT = new Regex(@"^exit(\b\s*(?<code>.+))?$", _REGEX_OPTIONS);
private static readonly Regex REGEX_RETURN = new Regex(@"^return(\b\s*(?<value>.+))?$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FOR = new Regex(@"^for\s+.+$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FORTO = new Regex(@"^for\s+(?<start>.+)\s+to\s+(?<stop>.+?)(\s+step\s+(?<step>.+))?$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FORIN = new Regex(@"^for\s+(?<variable>.+)\s+in\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FORIN_VARIABLES = new Regex(@"^\$(?<key>[^\W\d]|[^\W\d]\w*)\s*,\s*\$(?<value>[^\W\d]|[^\W\d]\w*)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_WITH = new Regex(@"^with\s+(?<variable>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDWITH = new Regex(@"^endwith$", _REGEX_OPTIONS);
private static readonly Regex REGEX_REDIM = new Regex(@"^redim\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_DO = new Regex(@"^do$", _REGEX_OPTIONS);
private static readonly Regex REGEX_UNTIL = new Regex(@"^until\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_IF = new Regex(@"^(?<elif>else)?if\s+(?<condition>.+)\s+then$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ELSE = new Regex(@"^else$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDIF = new Regex(@"^endif$", _REGEX_OPTIONS);
private static readonly Regex REGEX_DECLARATION_MODIFIER = new Regex(@"^(local|static|global|const|dim|enum|step)\b", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENUM_STEP = new Regex(@"^(?<op>[+\-*]?)(?<step>\d+)\b", _REGEX_OPTIONS);
private static readonly Regex REGEX_INCLUDE = new Regex(@"^include?\s+(?<open>[""'<])(?<path>(?:(?!\k<close>).)+)(?<close>[""'>])$", _REGEX_OPTIONS);
private static readonly Regex REGEX_CONTINUELOOP_EXITLOOP = new Regex(@"^(?<mode>continue|exit)loop\s*(?<level>.+)?\s*$", _REGEX_OPTIONS);
private static readonly Regex REGEX_SELECT = new Regex(@"^select$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDSELECT = new Regex(@"^endselect$", _REGEX_OPTIONS);
private static readonly Regex REGEX_SWITCH = new Regex(@"^switch\b\s*(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDSWITCH = new Regex(@"^endswitch$", _REGEX_OPTIONS);
private static readonly Regex REGEX_CASE = new Regex(@"^case\b\s*(?<expression>.+)*$", _REGEX_OPTIONS);
private static readonly Regex REGEX_CONTINUECASE = new Regex(@"^continuecase$", _REGEX_OPTIONS);


private InterpreterResult? ProcessStatement(string line) => Interpreter.Telemetry.Measure(TelemetryCategory.ProcessStatement, delegate
{
InterpreterResult? result = line.Match(null, new Dictionary<Regex, Func<Match, InterpreterResult?>>
Expand Down
Loading

0 comments on commit cbb42d3

Please sign in to comment.