From 0a4406d21f2799011d52d78517dda5646f9eb92c Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 24 Mar 2022 21:16:32 +0100 Subject: [PATCH] New features and bug fixes - Fix import (`imp`) bug- - Add is in parameter available (`isi`) statement - Add is out parameter available (`iso`) statement --- .editorconfig | 113 ++++++++++++++++++ YesNt-Interpreter.sln | 5 + YesNt.CodeEditor/GlobalSuppressions.cs | 8 ++ YesNt.CodeEditor/YesNt.CodeEditor.csproj | 4 + .../Statements/FunctionStatements.cs | 24 ++++ .../PredifinedVariableStatements.cs | 2 - .../Statements/ProcessingStatements.cs | 6 +- YesNt.Interpreter/Utilities/Evaluator.cs | 9 ++ 8 files changed, 166 insertions(+), 5 deletions(-) create mode 100644 .editorconfig create mode 100644 YesNt.CodeEditor/GlobalSuppressions.cs diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..051cab7 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,113 @@ +[*.cs] + +# Default severity for analyzer diagnostics with category 'Critical Code Smell' +dotnet_analyzer_diagnostic.category-Critical Code Smell.severity = none +csharp_indent_labels = one_less_than_current +csharp_using_directive_placement = outside_namespace:silent +csharp_prefer_simple_using_statement = true:suggestion +csharp_prefer_braces = true:silent +csharp_style_namespace_declarations = file_scoped:silent +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +csharp_style_expression_bodied_lambdas = true:silent +csharp_style_expression_bodied_local_functions = false:silent +csharp_style_throw_expression = true:suggestion +csharp_style_prefer_null_check_over_type_check = true:suggestion +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_prefer_local_over_anonymous_function = true:silent +csharp_style_prefer_index_operator = true:suggestion +csharp_style_prefer_range_operator = true:suggestion + +[*.{cs,vb}] +dotnet_style_operator_placement_when_wrapping = beginning_of_line +tab_width = 4 +indent_size = 4 +end_of_line = crlf +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:silent +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_compound_assignment = true:suggestion +dotnet_style_prefer_simplified_interpolation = true:suggestion +dotnet_style_namespace_match_folder = true:suggestion +[*.cs] +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.const_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.const_should_be_pascal_case.symbols = const +dotnet_naming_rule.const_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.const.applicable_kinds = +dotnet_naming_symbols.const.applicable_accessibilities = * +dotnet_naming_symbols.const.required_modifiers = const + +# Naming styles + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +[*.{cs,vb}] +#### Naming styles #### + +# Naming rules + +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i + +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case + +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case + +# Symbol specifications + +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.interface.required_modifiers = + +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.types.required_modifiers = + +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected +dotnet_naming_symbols.non_field_members.required_modifiers = + +# Naming styles + +dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_suffix = +dotnet_naming_style.begins_with_i.word_separator = +dotnet_naming_style.begins_with_i.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case + +dotnet_naming_style.pascal_case.required_prefix = +dotnet_naming_style.pascal_case.required_suffix = +dotnet_naming_style.pascal_case.word_separator = +dotnet_naming_style.pascal_case.capitalization = pascal_case diff --git a/YesNt-Interpreter.sln b/YesNt-Interpreter.sln index 29d6502..a7ba697 100644 --- a/YesNt-Interpreter.sln +++ b/YesNt-Interpreter.sln @@ -7,6 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesNt.CodeEditor", "YesNt.C EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YesNt.Interpreter", "YesNt.Interpreter\YesNt.Interpreter.csproj", "{E40573DB-912A-4871-BB65-3EE6E7D72E79}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{52024699-4F8E-40F6-AF03-71DDB4A1DC06}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/YesNt.CodeEditor/GlobalSuppressions.cs b/YesNt.CodeEditor/GlobalSuppressions.cs new file mode 100644 index 0000000..3e5f094 --- /dev/null +++ b/YesNt.CodeEditor/GlobalSuppressions.cs @@ -0,0 +1,8 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Critical Code Smell", "S3998:Threads should not lock on objects with weak identity", Justification = "", Scope = "member", Target = "~M:YesNt.CodeEditor.TextEditor.YesNtInterpreter_OnLineExecuted(YesNt.Interpreter.Runtime.DebugEventArgs)")] diff --git a/YesNt.CodeEditor/YesNt.CodeEditor.csproj b/YesNt.CodeEditor/YesNt.CodeEditor.csproj index 33a02c7..68e1220 100644 --- a/YesNt.CodeEditor/YesNt.CodeEditor.csproj +++ b/YesNt.CodeEditor/YesNt.CodeEditor.csproj @@ -5,6 +5,10 @@ net5.0 + + + + diff --git a/YesNt.Interpreter/Statements/FunctionStatements.cs b/YesNt.Interpreter/Statements/FunctionStatements.cs index 8402458..2ce9edc 100644 --- a/YesNt.Interpreter/Statements/FunctionStatements.cs +++ b/YesNt.Interpreter/Statements/FunctionStatements.cs @@ -62,6 +62,15 @@ namespace YesNt.Interpreter.Statements } } + [Statement("%iso", SearchMode.Contains, SpaceAround.End, ConsoleColor.Yellow, KeepStatementInArgs = true, Priority = Priority.Highest)] + public void CheckIfOutParameterAvalible(string args) + { + args += " "; + args = args.Replace("%iso ", $"{RuntimeInfo.OutParametersStack.Count > 0} "); + + RuntimeInfo.CurrentLine = args.TrimEnd(); + } + [Statement("cal", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.DarkYellow, Priority = Priority.Low, Seperator = "|")] public void Call(string args) { @@ -119,6 +128,21 @@ namespace YesNt.Interpreter.Statements } } + [Statement("%isi", SearchMode.Contains, SpaceAround.End, ConsoleColor.Yellow, KeepStatementInArgs = true, Priority = Priority.Highest)] + public void CheckIfInParameterAvalible(string args) + { + if (!RuntimeInfo.IsInFunction) + { + RuntimeInfo.Exit("Statement not allowed outside of function", true); + return; + } + + args += " "; + args = args.Replace("%isi ", $"{RuntimeInfo.FunctionCallStack.Peek().Arguemtns.Count > 0} "); + + RuntimeInfo.CurrentLine = args.TrimEnd(); + } + [Statement("put", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Yellow)] public void AddOutParameter(string args) { diff --git a/YesNt.Interpreter/Statements/PredifinedVariableStatements.cs b/YesNt.Interpreter/Statements/PredifinedVariableStatements.cs index 5c66b5d..92a78a0 100644 --- a/YesNt.Interpreter/Statements/PredifinedVariableStatements.cs +++ b/YesNt.Interpreter/Statements/PredifinedVariableStatements.cs @@ -27,8 +27,6 @@ namespace YesNt.Interpreter.Statements public void GetPi(string args) { args += " "; - - args = args.Replace("%pi ", $"{Math.PI} "); RuntimeInfo.CurrentLine = args.TrimEnd(); diff --git a/YesNt.Interpreter/Statements/ProcessingStatements.cs b/YesNt.Interpreter/Statements/ProcessingStatements.cs index e4a73b8..a1cdb7e 100644 --- a/YesNt.Interpreter/Statements/ProcessingStatements.cs +++ b/YesNt.Interpreter/Statements/ProcessingStatements.cs @@ -74,7 +74,7 @@ namespace YesNt.Interpreter.Statements { try { - RuntimeInfo.Lines.RemoveAt(0); + RuntimeInfo.Lines.RemoveAt(RuntimeInfo.LineNumber); string[] lines = File.ReadAllLines(path); for (int i = 0; i < lines.Length; i++) @@ -85,12 +85,12 @@ namespace YesNt.Interpreter.Statements } catch { - RuntimeInfo.Exit($"Could not load file {path}", true); + RuntimeInfo.Exit($"Could not load file \"{path}\"", true); } } else { - RuntimeInfo.Exit($"Could not find file {path}", true); + RuntimeInfo.Exit($"Could not find file \"{path}\"", true); } } diff --git a/YesNt.Interpreter/Utilities/Evaluator.cs b/YesNt.Interpreter/Utilities/Evaluator.cs index 2c6c8e1..8e27d07 100644 --- a/YesNt.Interpreter/Utilities/Evaluator.cs +++ b/YesNt.Interpreter/Utilities/Evaluator.cs @@ -6,6 +6,15 @@ namespace YesNt.Interpreter.Utilities { public static bool? EvaluateCondition(string input) { + if (input.ToLower().FromSaveString().Trim() == "true") + { + return true; + } + else if (input.ToLower().FromSaveString().Trim() == "false") + { + return false; + } + string[] parts = input.Split("=="); if (parts.Length == 2) {