diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4e5f761 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/CSTNet.Tests/bin/Debug/netcoreapp3.1/CSTNet.Tests.dll", + "args": [], + "cwd": "${workspaceFolder}/CSTNet.Tests", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..4b8e54d --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/CSTNet.Tests/CSTNet.Tests.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/CSTNet.Tests/CSTNet.Tests.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/CSTNet.Tests/CSTNet.Tests.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/notebooks/cst.ipynb b/notebooks/cst.ipynb index c69d644..db164e1 100644 --- a/notebooks/cst.ipynb +++ b/notebooks/cst.ipynb @@ -6,11 +6,11 @@ "source": [ "# Caret-Separated Text\n", "\n", - "Caret-Separated Text (or CST) is a key-value pair format represented by numbers or words as keys and the value is the string enclosed between carets (^) that contains the translation. Any text which is not enclosed with carets is considered a comment and ignored.\n", + "Caret-Separated Text (or CST) is a key-value pair format represented by numbers as keys and the value is the string enclosed between carets (^) that contains the translation. Any text which is not enclosed with carets is considered a comment and ignored.\n", "\n", "## CST.NET\n", "\n", - "My parser, CST.NET, uses .NET's built-in indexing extension function to accomplish locating of each respective key. Originally, CST keys were only numbered-based but the indexing naturally elimates this restriction. There is no consequence for using something other numbers now. An additional normalizion process of line endings from the document's to the system's, if needed, happens before it reads the file. This was done in order to prevent avoid crashes." + "CST.NET uses .NET's built-in indexing extension function to accomplish locating of each respective key. As a consequence, it does not matter what you use for keys. I added an additional normalizion to the pipeline that converts the document's line endings to the system's, in order to prevent crashes." ] }, { @@ -29,16 +29,16 @@ "source": [ "public static class CST\n", "{\n", - " public static string GetValue(string cst, int key, params string[] args)\n", + " public static string Parse(string cst, int key, params string[] args)\n", " {\n", " var entries = NormalizeEntries(cst);\n", - " return ReadEntries(entries, $\"{key}\", args);\n", + " return GetEntry(entries, $\"{key}\", args);\n", " }\n", "\n", - " public static string GetValue(string cst, string key, params string[] args)\n", + " public static string Parse(string cst, string key, params string[] args)\n", " {\n", " var entries = NormalizeEntries(cst);\n", - " return ReadEntries(entries, key, args);\n", + " return GetEntry(entries, key, args);\n", " }\n", "\n", " static IEnumerable NormalizeEntries(string cst)\n", @@ -61,7 +61,7 @@ " }\n", "\n", " // TODO: support argument parameters\n", - " static string ReadEntries(IEnumerable entries, string key, params string[] args)\n", + " static string GetEntry(IEnumerable entries, string key, params string[] args)\n", " {\n", " var translation = \"[ENTRY NOT FOUND]\";\n", "\n", @@ -99,12 +99,29 @@ "source": [ "var v1Path = Path.Combine(Environment.CurrentDirectory, \"data\", \"v1.cst\");\n", "var v1File = File.ReadAllText(v1Path);\n", - "var multiLine = CST.GetValue(v1File, 1);\n", - "var singleLine = CST.GetValue(v1File, 2);\n", - "Console.WriteLine(singleLine);\n", - "Console.WriteLine(singleLine);" + "var multiLine = CST.Parse(v1File, 1);\n", + "var singleLine = CST.Parse(v1File, 2);\n", + "Console.WriteLine($\"Single line:{Environment.NewLine}{singleLine}\");\n", + "Console.WriteLine($\"Multiline:{Environment.NewLine}{multiLine}\");" ], - "outputs": [] + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "Single line:\r\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc pharetra nunc nec erat finibus efficitur. Duis non ullamcorper purus. Donec sit amet ultricies sapien. Sed lacinia sem eu nunc gravida, vitae tincidunt eros tempus. Quisque nibh est, tempus sit amet purus at, facilisis cursus ante. Nam nisi purus, vehicula sed magna ac, lobortis aliquam urna. Sed condimentum, felis a placerat tincidunt, est augue pulvinar turpis, eu dictum leo diam quis mi. Nulla non efficitur neque, sed efficitur orci. Aliquam quis libero consequat, convallis tortor sit amet, varius orci.\n\nOrci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nunc vel dictum eros, vitae mattis risus. Curabitur eget nisi interdum, euismod nisl in, fermentum turpis. Morbi a feugiat lacus. Duis ligula felis, commodo quis sodales ac, congue sit amet tortor. Sed vulputate, velit id interdum convallis, purus nisl interdum lorem, sit amet aliquam lacus sapien ac neque. Proin sit amet ultricies mi.\r\n" + }, + "execution_count": 1, + "metadata": {} + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "Multiline:\r\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ac dictum orci, at tincidunt nulla. Donec aliquet, eros non interdum posuere, ipsum sapien molestie nunc, nec facilisis libero ipsum et risus. In sed lorem vel ipsum placerat viverra.\r\n" + }, + "execution_count": 1, + "metadata": {} + } + ] }, { "cell_type": "code", @@ -113,12 +130,29 @@ "source": [ "var v2Path = Path.Combine(Environment.CurrentDirectory, \"data\", \"v2.cst\");\n", "var v2File = File.ReadAllText(v2Path);\n", - "var multiLineV2 = CST.GetValue(v2File, \"Multiline\");\n", - "var singleLineV2 = CST.GetValue(v2File, \"Singleline\");\n", - "Console.WriteLine(singleLineV2);\n", - "Console.WriteLine(multiLineV2);" + "var multiLineV2 = CST.Parse(v2File, \"Multiline\");\n", + "var singleLineV2 = CST.Parse(v2File, \"Singleline\");\n", + "Console.WriteLine($\"Single line v2:{Environment.NewLine}{singleLineV2}\");\n", + "Console.WriteLine($\"Multiline v2:{Environment.NewLine}{multiLineV2}\");" ], - "outputs": [] + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": "Single line v2:\r\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ultricies nulla eu tortor mattis, dictum posuere lacus ornare. Maecenas a massa in ligula finibus luctus eu vitae nibh. Proin imperdiet dapibus mauris quis placerat.\r\n" + }, + "execution_count": 1, + "metadata": {} + }, + { + "output_type": "execute_result", + "data": { + "text/plain": "Multiline v2:\r\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc gravida nunc non justo pretium consectetur. Sed tempus libero ac ligula aliquam elementum. Duis vitae interdum leo. Sed semper nulla %1 a lectus dictum dictum. Ut mattis eu tortor in bibendum. Integer mattis tincidunt aliquet. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce quis orci nisl.\n\nQuisque vehicula, nisi ut scelerisque sodales, nisi ipsum sodales ipsum, in rutrum tellus lacus sed nibh. Etiam mauris velit, elementum sed placerat et, elementum et tellus. Duis vitae elit fermentum, viverra lorem in, lobortis elit. Maecenas eget nibh et lectus auctor dignissim.\r\n" + }, + "execution_count": 1, + "metadata": {} + } + ] } ], "metadata": {