├── .github ├── dependabot.yml └── workflows │ ├── AutoMerge.yml │ └── csharp.yml ├── python ├── cs2cpp │ ├── __init__.py │ └── cs2cpp.py ├── README.md ├── setup.py └── test.py ├── csharp ├── Platform.RegularExpressions.Transformer.CSharpToCpp.Tests │ ├── Platform.RegularExpressions.Transformer.CSharpToCpp.Tests.csproj │ └── CSharpToCppTransformerTests.cs ├── Platform.RegularExpressions.Transformer.CSharpToCpp.sln └── Platform.RegularExpressions.Transformer.CSharpToCpp │ ├── Platform.RegularExpressions.Transformer.CSharpToCpp.csproj │ └── CSharpToCppTransformer.cs ├── LICENSE ├── README.md └── .gitignore /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: nuget 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | -------------------------------------------------------------------------------- /python/cs2cpp/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from .cs2cpp import CSharpToCpp 4 | 5 | __version__ = "0.2.0" 6 | __copyright__ = "2022" 7 | __authors__ = ["Ethosa", "Konard"] 8 | -------------------------------------------------------------------------------- /.github/workflows/AutoMerge.yml: -------------------------------------------------------------------------------- 1 | name: auto-merge 2 | 3 | on: 4 | pull_request_target: 5 | 6 | jobs: 7 | auto-merge: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: ahmadnassri/action-dependabot-auto-merge@v2 12 | with: 13 | target: minor 14 | github-token: ${{ secrets.DEPENDABOT_AUTO_MERGE_TOKEN }} 15 | -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # CSharpToCpp 4 | ### Simple C# to C++ translator written in Python 5 | 6 |
7 | 8 | 9 | ## Get Started 10 | ### Install 11 | ```pip install --upgrade cs2cpp``` 12 | 13 | ### Usage 14 | ```python 15 | from cs2cpp import CSharpToCpp 16 | 17 | cscpp = CSharpToCpp() 18 | sourceCode = """using System; 19 | // This is hello world program. 20 | class Program 21 | { 22 | public static void Main(string[] args) 23 | { 24 | var myFirstString = "ban"; 25 | char*[] args = {"1", "2"}; 26 | Console.WriteLine("Hello, world!"); 27 | } 28 | }""" 29 | print(cscpp.translate(sourceCode)) # translate code from C# to C++! 30 | ``` 31 | -------------------------------------------------------------------------------- /csharp/Platform.RegularExpressions.Transformer.CSharpToCpp.Tests/Platform.RegularExpressions.Transformer.CSharpToCpp.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8 5 | false 6 | latest 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to -------------------------------------------------------------------------------- /csharp/Platform.RegularExpressions.Transformer.CSharpToCpp.Tests/CSharpToCppTransformerTests.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | 3 | namespace Platform.RegularExpressions.Transformer.CSharpToCpp.Tests 4 | { 5 | public class CSharpToCppTransformerTests 6 | { 7 | [Fact] 8 | public void EmptyLineTest() 9 | { 10 | // This test can help to test basic problems with regular expressions like incorrect syntax 11 | var transformer = new CSharpToCppTransformer(); 12 | var actualResult = transformer.Transform(""); 13 | Assert.Equal("", actualResult); 14 | } 15 | 16 | [Fact] 17 | public void HelloWorldTest() 18 | { 19 | const string helloWorldCode = @"using System; 20 | class Program 21 | { 22 | public static void Main(string[] args) 23 | { 24 | Console.WriteLine(""Hello, world!""); 25 | } 26 | }"; 27 | const string expectedResult = @"class Program 28 | { 29 | public: static void Main(std::string args[]) 30 | { 31 | printf(""Hello, world!\n""); 32 | } 33 | };"; 34 | var transformer = new CSharpToCppTransformer(); 35 | var actualResult = transformer.Transform(helloWorldCode); 36 | Assert.Equal(expectedResult, actualResult); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /python/setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | with open("README.md", "r") as fh: 4 | long_description = fh.read() 5 | 6 | setuptools.setup( 7 | name="cs2cpp", 8 | version="0.2.0", 9 | author="Ethosa", 10 | author_email="social.ethosa@gmail.com", 11 | description="Csharp to Cpp code translator", 12 | long_description=long_description, 13 | long_description_content_type="text/markdown", 14 | url="https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/tree/master/python", 15 | packages=setuptools.find_packages(), 16 | license="LGPLv3", 17 | keywords="csharp cpp cs2cpp links platform ethosa konard", 18 | classifiers=[ 19 | "Development Status :: 4 - Beta", 20 | "Programming Language :: Python :: 3", 21 | "Programming Language :: Python :: 3.4", 22 | "Programming Language :: Python :: 3.5", 23 | "Programming Language :: Python :: 3.6", 24 | "Programming Language :: Python :: 3.7", 25 | "Programming Language :: Python :: 3.8", 26 | "Programming Language :: Python :: 3.9", 27 | "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", 28 | "Operating System :: OS Independent", 29 | ], 30 | project_urls={ 31 | "Github": "https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/tree/master/python", 32 | "Documentation": "https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/tree/master/python", 33 | }, 34 | python_requires=">=3", 35 | install_requires=["retranslator >= 0.2.0"] 36 | ) 37 | -------------------------------------------------------------------------------- /csharp/Platform.RegularExpressions.Transformer.CSharpToCpp.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29326.143 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Platform.RegularExpressions.Transformer.CSharpToCpp", "Platform.RegularExpressions.Transformer.CSharpToCpp\Platform.RegularExpressions.Transformer.CSharpToCpp.csproj", "{4CC673F5-B97D-441D-8D74-6F40A93F1454}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Platform.RegularExpressions.Transformer.CSharpToCpp.Tests", "Platform.RegularExpressions.Transformer.CSharpToCpp.Tests\Platform.RegularExpressions.Transformer.CSharpToCpp.Tests.csproj", "{03D93E29-4D6F-44DD-AFCC-F220154C1CF0}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {4CC673F5-B97D-441D-8D74-6F40A93F1454}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {4CC673F5-B97D-441D-8D74-6F40A93F1454}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {4CC673F5-B97D-441D-8D74-6F40A93F1454}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {4CC673F5-B97D-441D-8D74-6F40A93F1454}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {03D93E29-4D6F-44DD-AFCC-F220154C1CF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {03D93E29-4D6F-44DD-AFCC-F220154C1CF0}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {03D93E29-4D6F-44DD-AFCC-F220154C1CF0}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {03D93E29-4D6F-44DD-AFCC-F220154C1CF0}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {70937F8A-7518-405A-9A61-6C116D17481D} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /python/test.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from unittest import main, TestCase 3 | 4 | from cs2cpp import CSharpToCpp 5 | 6 | 7 | class CSharpToCppTest(TestCase): 8 | translator = CSharpToCpp() 9 | 10 | def test_translate_hello_world(self): 11 | print( 12 | self.translator.translate( 13 | (''' 14 | using System; 15 | // This is hello world program. 16 | class Program 17 | { 18 | public static void Main(string[] args) 19 | { 20 | var myFirstString = "ban"; 21 | char*[] args = {"1", "2"}; 22 | Console.WriteLine("Hello, world!"); 23 | } 24 | }'''))) 25 | 26 | def test_some(self): 27 | print( 28 | self.translator.translate( 29 | (''' 30 | namespace Platform.Interfaces 31 | { 32 | /// 33 | /// Defines a factory that produces instances of a specific type. 34 | /// Определяет фабрику, которая производит экземпляры определенного типа. 35 | /// 36 | /// Type of produced instances.Тип производимых экземпляров. 37 | public interface IFactory 38 | { 39 | /// 40 | /// Creates an instance of TProduct type. 41 | /// Создает экземпляр типа TProduct. 42 | /// 43 | /// The instance of TProduct type.Экземпляр типа TProduct. 44 | TProduct Create(); 45 | } 46 | }'''))) 47 | 48 | if __name__ == '__main__': 49 | main(verbosity=2) 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Actions Status](https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/workflows/CD/badge.svg)](https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/actions?workflow=CD) 2 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/7bcd272efb834b7993f0cf3ea1e9bb69)](https://www.codacy.com/manual/drakonard/RegularExpressions.Transformer.CSharpToCpp?utm_source=github.com&utm_medium=referral&utm_content=linksplatform/RegularExpressions.Transformer.CSharpToCpp&utm_campaign=Badge_Grade) 3 | [![CodeFactor](https://www.codefactor.io/repository/github/linksplatform/regularexpressions.transformer.csharptocpp/badge)](https://www.codefactor.io/repository/github/linksplatform/regularexpressions.transformer.csharptocpp) 4 | 5 | | [![NuGet Version and Downloads count](https://img.shields.io/nuget/v/Platform.RegularExpressions.Transformer.CSharpToCpp?label=nuget&style=flat)](https://www.nuget.org/packages/Platform.RegularExpressions.Transformer.CSharpToCpp) | C# | 6 | |-|-| 7 | | [![PyPI version](https://badge.fury.io/py/cs2cpp.svg)](https://badge.fury.io/py/cs2cpp) | __Python__ | 8 | 9 | # [RegularExpressions.Transformer.CSharpToCpp](https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp) 10 | 11 | LinksPlatform's Platform.RegularExpressions.Transformer.CSharpToCpp Class Library. 12 | 13 | Namespace: [Platform.RegularExpressions.Transformer.CSharpToCpp](https://linksplatform.github.io/RegularExpressions.Transformer.CSharpToCpp/csharp/api/Platform.RegularExpressions.Transformer.CSharpToCpp.html) 14 | 15 | Forked from: [LinksPlatform/Collections.Methods/CSharpToCppTranslator](https://github.com/linksplatform/Collections.Methods/tree/93bdb700f81cae341164da6a78e1b770814d0eba/CSharpToCppTranslator) 16 | 17 | NuGet package: [Platform.RegularExpressions.Transformer.CSharpToCpp](https://www.nuget.org/packages/Platform.RegularExpressions.Transformer.CSharpToCpp) 18 | 19 | Python version: [cs2cpp](https://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp/tree/master/python) 20 | 21 | ## [Documentation](https://linksplatform.github.io/RegularExpressions.Transformer.CSharpToCpp) 22 | [PDF file](https://linksplatform.github.io/RegularExpressions.Transformer.CSharpToCpp/csharp/Platform.RegularExpressions.Transformer.CSharpToCpp.pdf) with code for e-readers. 23 | 24 | ## Depend on 25 | * [Platform.RegularExpressions.Transformer](https://github.com/linksplatform/RegularExpressions.Transformer) 26 | -------------------------------------------------------------------------------- /csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/Platform.RegularExpressions.Transformer.CSharpToCpp.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | LinksPlatform's Platform.RegularExpressions.Transformer.CSharpToCpp Class Library 5 | Konstantin Diachenko 6 | Platform.RegularExpressions.Transformer.CSharpToCpp 7 | 0.3.0 8 | Konstantin Diachenko 9 | net8 10 | Platform.RegularExpressions.Transformer.CSharpToCpp 11 | Platform.RegularExpressions.Transformer.CSharpToCpp 12 | LinksPlatform;RegularExpressions.Transformer.CSharpToCpp;CSharpToCppTransformer 13 | https://raw.githubusercontent.com/linksplatform/Documentation/18469f4d033ee9a5b7b84caab9c585acab2ac519/doc/Avatar-rainbow-icon-64x64.png 14 | https://linksplatform.github.io/RegularExpressions.Transformer.CSharpToCpp 15 | Unlicensed 16 | git 17 | git://github.com/linksplatform/RegularExpressions.Transformer.CSharpToCpp 18 | false 19 | false 20 | true 21 | true 22 | true 23 | true 24 | snupkg 25 | latest 26 | Update target framework from net7 to net8. 27 | enable 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /.github/workflows/csharp.yml: -------------------------------------------------------------------------------- 1 | name: csharp 2 | 3 | on: 4 | push: 5 | branches: main 6 | paths: 7 | - 'csharp/**' 8 | - '.github/workflows/csharp.yml' 9 | env: 10 | NUGETTOKEN: ${{ secrets.NUGET_TOKEN }} 11 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 12 | SCRIPTS_BASE_URL: https://raw.githubusercontent.com/linksplatform/Scripts/main/MultiProjectRepository 13 | 14 | defaults: 15 | run: 16 | working-directory: csharp 17 | 18 | jobs: 19 | test: 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/checkout@v1 23 | with: 24 | submodules: true 25 | - name: Test 26 | run: | 27 | dotnet test -c Release -f net8 28 | pushNuGetPackageToGitHubPackageRegistry: 29 | needs: test 30 | runs-on: ubuntu-latest 31 | steps: 32 | - uses: actions/checkout@v1 33 | with: 34 | submodules: true 35 | - uses: nuget/setup-nuget@v1 36 | - name: Publish NuGet package to GitHub Package Registry 37 | run: | 38 | dotnet build -c Release 39 | dotnet pack -c Release 40 | nuget source Add -Name "GitHub" -Source "https://nuget.pkg.github.com/linksplatform/index.json" -UserName linksplatform -Password ${{ secrets.GITHUB_TOKEN }} 41 | nuget push **/*.nupkg -Source "GitHub" -SkipDuplicate 42 | pusnToNuget: 43 | runs-on: ubuntu-latest 44 | needs: test 45 | steps: 46 | - uses: actions/checkout@v1 47 | with: 48 | submodules: true 49 | - name: Read project information 50 | run: | 51 | export REPOSITORY_NAME=$(basename ${{ github.repository }}) 52 | wget "$SCRIPTS_BASE_URL/read_csharp_package_info.sh" 53 | bash ./read_csharp_package_info.sh 54 | - name: Publish NuGet package 55 | run: | 56 | export REPOSITORY_NAME=$(basename ${{ github.repository }}) 57 | wget "$SCRIPTS_BASE_URL/push-csharp-nuget.sh" 58 | bash ./push-csharp-nuget.sh 59 | publiseRelease: 60 | runs-on: ubuntu-latest 61 | needs: test 62 | steps: 63 | - uses: actions/checkout@v1 64 | with: 65 | submodules: true 66 | - name: Read project information 67 | if: ${{ github.event_name == 'push' }} 68 | run: | 69 | export REPOSITORY_NAME=$(basename ${{ github.repository }}) 70 | wget "$SCRIPTS_BASE_URL/read_csharp_package_info.sh" 71 | bash ./read_csharp_package_info.sh 72 | - name: Publish release 73 | run: | 74 | export REPOSITORY_NAME=$(basename ${{ github.repository }}) 75 | wget "$SCRIPTS_BASE_URL/publish-release.sh" 76 | chmod +x ./publish-release.sh 77 | wget "$SCRIPTS_BASE_URL/publish-csharp-release.sh" 78 | bash ./publish-csharp-release.sh 79 | findChangedCsFiles: 80 | runs-on: ubuntu-latest 81 | needs: test 82 | outputs: 83 | isCsFilesChanged: ${{ steps.setIsCsFilesChangedOutput.outputs.isCsFilesChanged }} 84 | steps: 85 | - uses: actions/checkout@v3 86 | with: 87 | fetch-depth: 0 88 | - name: Get changed files using defaults 89 | id: changed-files 90 | uses: tj-actions/changed-files@v21 91 | - name: Set output isCsFilesChanged 92 | id: setIsCsFilesChangedOutput 93 | run: | 94 | isCsFilesChanged='false' 95 | echo "Changed files: ${{ steps.changed-files.outputs.all_changed_files }}" 96 | for changedFile in ${{ steps.changed-files.outputs.all_changed_files }}; do 97 | if [[ $changedFile == *.cs ]] 98 | then 99 | echo "isCsFilesChanged='true'" 100 | isCsFilesChanged='true' 101 | fi 102 | done 103 | echo "::set-output name=isCsFilesChanged::${isCsFilesChanged}" 104 | echo "isCsFilesChanged: ${isCsFilesChanged}" 105 | generatePdfWithCode: 106 | runs-on: ubuntu-latest 107 | needs: [findChangedCsFiles] 108 | if: ${{ needs.findChangedCsFiles.outputs.isCsFilesChanged == 'true' }} 109 | steps: 110 | - uses: actions/checkout@v1 111 | with: 112 | submodules: true 113 | - name: Generate PDF with code 114 | run: | 115 | export REPOSITORY_NAME=$(basename ${{ github.repository }}) 116 | wget "$SCRIPTS_BASE_URL/format-csharp-files.py" 117 | wget "$SCRIPTS_BASE_URL/format-csharp-document.sh" 118 | wget "$SCRIPTS_BASE_URL/generate-csharp-pdf.sh" 119 | bash ./generate-csharp-pdf.sh 120 | publishDocumentation: 121 | runs-on: ubuntu-latest 122 | needs: [findChangedCsFiles] 123 | if: ${{ needs.findChangedCsFiles.outputs.isCsFilesChanged == 'true' }} 124 | steps: 125 | - uses: actions/checkout@v1 126 | with: 127 | submodules: true 128 | - name: Publish documentation to gh-pages branch 129 | run: | 130 | export REPOSITORY_NAME=$(basename ${{ github.repository }}) 131 | wget "$SCRIPTS_BASE_URL/docfx.json" 132 | wget "$SCRIPTS_BASE_URL/filter.yml" 133 | wget "$SCRIPTS_BASE_URL/toc.yml" 134 | wget "$SCRIPTS_BASE_URL/publish-csharp-docs.sh" 135 | bash ./publish-csharp-docs.sh 136 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /python/cs2cpp/cs2cpp.py: -------------------------------------------------------------------------------- 1 | # -*- coding utf-8 -*- 2 | # authors: Ethosa, Konard 3 | from typing import NoReturn, Optional, List 4 | 5 | from retranslator import Translator, SubRule, SteppedTranslator 6 | from regex import search, sub 7 | 8 | 9 | class CSharpToCpp(Translator): 10 | def __init__( 11 | self, 12 | extra: List[SubRule] = [] 13 | ) -> NoReturn: 14 | """Initializes class 15 | 16 | :param extra: include your own rules 17 | """ 18 | # create little magic ... 19 | self.rules = CSharpToCpp.FIRST_RULES[:] 20 | self.rules.extend(extra) 21 | self.rules.extend(CSharpToCpp.LAST_RULES) 22 | Translator.__init__(self, self.rules) 23 | 24 | # Rules for translate code 25 | FIRST_RULES = [ 26 | # // ... 27 | # 28 | SubRule(r"(\r?\n)?[ \t]+//+.+", r"", max_repeat=0), 29 | # #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member 30 | # 31 | SubRule(r"^\s*?\#pragma[\sa-zA-Z0-9]+$", r"", max_repeat=0), 32 | # {\n\n\n 33 | # { 34 | SubRule(r"{\s+[\r\n]+", r"{\n", max_repeat=0), 35 | # Platform.Collections.Methods.Lists 36 | # Platform::Collections::Methods::Lists 37 | SubRule(r"(namespace[^\r\n]+?)\.([^\r\n]+?)", r"\1::\2", max_repeat=20), 38 | # nameof(numbers) 39 | # "numbers" 40 | SubRule(r"(?P\W)nameof\(([^)\n]+\.)?(?P[a-zA-Z0-9_]+)(<[^)\n]+>)?\)", r"\g\"\g\"", max_repeat=0), 41 | # Insert markers 42 | # EqualityComparer _equalityComparer = EqualityComparer.Default; 43 | # EqualityComparer _equalityComparer = EqualityComparer.Default;/*~_comparer~*/ 44 | SubRule(r"(?PEqualityComparer<(?P[^>\n]+)> (?P[a-zA-Z0-9_]+) = EqualityComparer<\k>\.Default;)", r"\g/*~\g~*/", max_repeat=0), 45 | # /*~_equalityComparer~*/..._equalityComparer.Equals(Minimum, value) 46 | # /*~_equalityComparer~*/...Minimum == value 47 | SubRule(r"(?P/\*~(?P[a-zA-Z0-9_]+)~\*/(.|\n)+\W)\k\.Equals\((?P[^,\n]+), (?P[^)\n]+)\)", r"\g\g == \g", max_repeat=50), 48 | # Remove markers 49 | # /*~_equalityComparer~*/ 50 | # 51 | SubRule(r"\r?\n[^\n]+/\*~[a-zA-Z0-9_]+~\*/", r"", max_repeat=10), 52 | # Insert markers 53 | # Comparer _comparer = Comparer.Default; 54 | # Comparer _comparer = Comparer.Default;/*~_comparer~*/ 55 | SubRule(r"(?PComparer<(?P[^>\n]+)> (?P[a-zA-Z0-9_]+) = Comparer<\k>\.Default;)", r"\g/*~\g~*/", max_repeat=0), 56 | # /*~_comparer~*/..._comparer.Compare(Minimum, value) <= 0 57 | # /*~_comparer~*/...Minimum <= value 58 | SubRule(r"(?P/\*~(?P[a-zA-Z0-9_]+)~\*/(.|\n)+\W)\k\.Compare\((?P[^,\n]+), (?P[^)\n]+)\)\s*(?P[<>=]=?)\s*0(?P\D)", r"\g\g \g \g\g", max_repeat=50), 59 | # Remove markers 60 | # private static readonly Comparer _comparer = Comparer.Default;/*~_comparer~*/ 61 | # 62 | SubRule(r"\r?\n[^\n]+/\*~[a-zA-Z0-9_]+~\*/", r"", max_repeat=10), 63 | # Comparer.Default.Compare(maximumArgument, minimumArgument) < 0 64 | # maximumArgument < minimumArgument 65 | SubRule(r"Comparer<[^>\n]+>\.Default\.Compare\(\s*(?P[^,)\n]+),\s*(?P[^\)\n]+)\s*\)\s*(?P[<>=]=?)\s*0(?P\D)", r"\g \g \g\g", max_repeat=0), 66 | # public static bool operator ==(Range left, Range right) => left.Equals(right); 67 | # 68 | SubRule(r"\r?\n[^\n]+bool operator ==\((?P[^\n]+) (?P[a-zA-Z0-9]+), \k (?P[a-zA-Z0-9]+)\) => (\k|\k)\.Equals\((\k|\k)\);", r"", max_repeat=10), 69 | # public static bool operator !=(Range left, Range right) => !(left == right); 70 | # 71 | SubRule(r"\r?\n[^\n]+bool operator !=\((?P[^\n]+) (?P[a-zA-Z0-9]+), \k (?P[a-zA-Z0-9]+)\) => !\((\k|\k) == (\k|\k)\);", r"", max_repeat=10), 72 | # public override bool Equals(object obj) => obj is Range range ? Equals(range) : false; 73 | # 74 | SubRule(r"\r?\n[^\n]+override bool Equals\((System\.)?[Oo]bject (?P[a-zA-Z0-9]+)\) => \k is [^\n]+ (?P[a-zA-Z0-9]+) \? Equals\(\k\) : false;", r"", max_repeat=10), 75 | # out TProduct 76 | # TProduct 77 | SubRule(r"(?P(<|, ))(in|out) (?P[a-zA-Z0-9]+)(?P(>|,))", r"\g\g\g", max_repeat=10), 78 | # public ... 79 | # public: ... 80 | SubRule(r"(?P\r?\n?[ \t]*)(?P[^\{\(\r\n]*)(?Pprivate|protected|public)[ \t]+(?![^\{\(\r\n]*((?<=\s)|\W)(interface|class|struct)(\W)[^\{\(\r\n]*[\{\(\r\n])", r"\g\g: \g", max_repeat=0), 81 | # public: static bool CollectExceptions { get; set; } 82 | # public: inline static bool CollectExceptions; 83 | SubRule(r"(?P(private|protected|public): )(?P(static )?[^\r\n]+ )(?P[a-zA-Z0-9]+) {[^;}]*(?<=\W)get;[^;}]*(?<=\W)set;[^;}]*}", r"\ginline \g\g;", max_repeat=0), 84 | # public abstract class 85 | # class 86 | SubRule(r"((public|protected|private|internal|abstract|static) )*(?Pinterface|class|struct)", r"\g", max_repeat=0), 87 | # class GenericCollectionMethodsBase { 88 | # template class GenericCollectionMethodsBase { 89 | SubRule(r"(?P\r?\n)(?P[ \t]*)(?Pclass|struct) (?P[a-zA-Z0-9]+)<(?P[a-zA-Z0-9 ,]+)>(?P[^{]+){", r"\g\gtemplate \g \g;\n" + "\gtemplate > \g \g<\g>\g{", max_repeat=0), 90 | # static void TestMultipleCreationsAndDeletions(SizedBinaryTreeMethodsBase tree, TElement* root) 91 | # template static void TestMultipleCreationsAndDeletions(SizedBinaryTreeMethodsBase tree, TElement* root) 92 | SubRule(r"static ([a-zA-Z0-9]+) ([a-zA-Z0-9]+)<([a-zA-Z0-9]+)>\(([^\)\r\n]+)\)", r"template static \1 \2(\4)", max_repeat=0), 93 | # interface IFactory { 94 | # template class IFactory;\ntemplate class IFactory 95 | SubRule(r"(?P\r?\n)(?P[ \t]*)interface (?P[a-zA-Z0-9]+)<(?P[a-zA-Z0-9 ,]+)>(?P[^{]+){", r"\g\gtemplate class \g;\n" + "\gtemplate > class \g<\g>\g{\n" + " public:", max_repeat=0), 96 | # template 97 | # template 98 | SubRule(r"(?Ptemplate <((, )?typename [a-zA-Z0-9]+)+, )(?P[a-zA-Z0-9]+)(?P(,|>))", r"\gtypename \g\g", max_repeat=10), 99 | # Insert markers 100 | # private: static void BuildExceptionString(this StringBuilder sb, Exception exception, int level) 101 | # /*~extensionMethod~BuildExceptionString~*/private: static void BuildExceptionString(this StringBuilder sb, Exception exception, int level) 102 | SubRule(r"private: static [^\r\n]+ (?P[a-zA-Z0-9]+)\(this [^\)\r\n]+\)", r"/*~extensionMethod~\g~*/\0", max_repeat=0), 103 | # Move all markers to the beginning of the file. 104 | SubRule(r"\A(?P[^\r\n]+\r?\n(.|\n)+)(?P/\*~extensionMethod~(?P[a-zA-Z0-9]+)~\*/)", r"\g\g", max_repeat=10), 105 | # /*~extensionMethod~BuildExceptionString~*/...sb.BuildExceptionString(exception.InnerException, level + 1); 106 | # /*~extensionMethod~BuildExceptionString~*/...BuildExceptionString(sb, exception.InnerException, level + 1); 107 | SubRule(r"(?P/\*~extensionMethod~(?P[a-zA-Z0-9]+)~\*/(.|\n)+\W)(?P[_a-zA-Z0-9]+)\.\k\(", r"\g\g(\g, ", max_repeat=50), 108 | # Remove markers 109 | # /*~extensionMethod~BuildExceptionString~*/ 110 | # 111 | SubRule(r"/\*~extensionMethod~[a-zA-Z0-9]+~\*/", r"", max_repeat=0), 112 | # (this 113 | # ( 114 | SubRule(r"\(this ", r"(", max_repeat=0), 115 | # private: static readonly Disposal _emptyDelegate = (manual, wasDisposed) => { }; 116 | # private: inline static std::function _emptyDelegate = [](auto manual, auto wasDisposed) { }; 117 | SubRule(r"(?P(private|protected|public): )?static readonly (?P[a-zA-Z][a-zA-Z0-9]*) (?P[a-zA-Z_][a-zA-Z0-9_]*) = \((?P[a-zA-Z_][a-zA-Z0-9_]*), (?P[a-zA-Z_][a-zA-Z0-9_]*)\) => {\s*};", r"\ginline static std::function<\g> \g = [](auto \g, auto \g) { };", max_repeat=0), 118 | # public: static readonly EnsureAlwaysExtensionRoot Always = new EnsureAlwaysExtensionRoot(); 119 | # public: inline static EnsureAlwaysExtensionRoot Always; 120 | SubRule(r"(?P(private|protected|public): )?static readonly (?P[a-zA-Z0-9]+(<[a-zA-Z0-9]+>)?) (?P[a-zA-Z0-9_]+) = new \k\(\);", r"\ginline static \g \g;", max_repeat=0), 121 | # public: static readonly Range SByte = new Range(std::numeric_limits::min(), std::numeric_limits::max()); 122 | # public: inline static Range SByte = Range(std::numeric_limits::min(), std::numeric_limits::max()); 123 | SubRule(r"(?P(private|protected|public): )?static readonly (?P[a-zA-Z0-9]+(<[a-zA-Z0-9]+>)?) (?P[a-zA-Z0-9_]+) = new \k\((?P[^\n]+)\);", r"\ginline static \g \g = \g(\g);", max_repeat=0), 124 | # public: static readonly string ExceptionContentsSeparator = "---"; 125 | # public: inline static std::string ExceptionContentsSeparator = "---"; 126 | SubRule(r"(?P(private|protected|public): )?(const|static readonly) string (?P[a-zA-Z0-9_]+) = \"\"(?P(\\\"\"|[^\"\"\r\n])+)\"\";", r"\ginline static std::string \g = \"\g\";", max_repeat=0), 127 | # private: const int MaxPath = 92; 128 | # private: inline static const int MaxPath = 92; 129 | SubRule(r"(?P(private|protected|public): )?(const|static readonly) (?P[a-zA-Z0-9]+) (?P[_a-zA-Z0-9]+) = (?P[^;\r\n]+);", r"\ginline static const \g \g = \g;", max_repeat=0), 130 | # ArgumentNotNull(EnsureAlwaysExtensionRoot root, TArgument argument) where TArgument : class 131 | # ArgumentNotNull(EnsureAlwaysExtensionRoot root, TArgument* argument) 132 | SubRule(r"(?P [a-zA-Z]+\(([a-zA-Z *,]+, |))(?P[a-zA-Z]+)(?P(| [a-zA-Z *,]+)\))[ \r\n]+where \k : class", r"\g\g*\g", max_repeat=0), 133 | # protected: abstract TElement GetFirst(); 134 | # protected: virtual TElement GetFirst() = 0; 135 | SubRule(r"(?P(private|protected|public): )?abstract (?P[^;\r\n]+);", r"\gvirtual \g = 0;", max_repeat=0), 136 | # TElement GetFirst(); 137 | # virtual TElement GetFirst() = 0; 138 | SubRule(r"(?P[\r\n]+[ ]+)(?P(?!return)[a-zA-Z0-9]+ [a-zA-Z0-9]+\([^\)\r\n]*\))(?P;[ ]*[\r\n]+)", r"\gvirtual \g = 0\g", max_repeat=1), 139 | # protected: readonly TreeElement[] _elements; 140 | # protected: TreeElement _elements[N]; 141 | SubRule(r"(?P(private|protected|public): )?readonly (?P[a-zA-Z<>0-9]+)([\[\]]+) (?P[_a-zA-Z0-9]+);", r"\g\g \g[N];", max_repeat=0), 142 | # protected: readonly TElement Zero; 143 | # protected: TElement Zero; 144 | SubRule(r"(?P(private|protected|public): )?readonly (?P[a-zA-Z<>0-9]+) (?P[_a-zA-Z0-9]+);", r"\g\g \g;", max_repeat=0), 145 | # internal 146 | # 147 | SubRule(r"(\W)internal\s+", r"\1", max_repeat=0), 148 | # static void NotImplementedException(ThrowExtensionRoot root) => throw new NotImplementedException(); 149 | # static void NotImplementedException(ThrowExtensionRoot root) { return throw new NotImplementedException(); } 150 | SubRule(r"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?([a-zA-Z0-9]+ )([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+throw([^;\r\n]+);", r"\1\2\3\4\5\6\7\8(\9) { throw\10; }", max_repeat=0), 151 | # SizeBalancedTree(int capacity) => a = b; 152 | # SizeBalancedTree(int capacity) { a = b; } 153 | SubRule(r"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?(void )?([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+([^;\r\n]+);", r"\1\2\3\4\5\6\7\8(\9) { \10; }", max_repeat=0), 154 | # int SizeBalancedTree(int capacity) => a; 155 | # int SizeBalancedTree(int capacity) { return a; } 156 | SubRule(r"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?([a-zA-Z0-9]+ )([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+([^;\r\n]+);", r"\1\2\3\4\5\6\7\8(\9) { return \10; }", max_repeat=0), 157 | # OnDispose = (manual, wasDisposed) => 158 | # OnDispose = [&](auto manual, auto wasDisposed) 159 | SubRule(r"(?P[a-zA-Z_][a-zA-Z0-9_]*)(?P\s*\+?=\s*)\((?P[a-zA-Z_][a-zA-Z0-9_]*), (?P[a-zA-Z_][a-zA-Z0-9_]*)\)\s*=>", r"\g\g[&](auto \g, auto \g)", max_repeat=0), 160 | # () => Integer.Zero, 161 | # () { return Integer.Zero; }, 162 | SubRule(r"\(\)\s+=>\s+(?P[^(),;\r\n]+(\(((?P\()|(?(parenthesis)\))|[^();\r\n]*?)*?\))?[^(),;\r\n]*)(?P,|\);)", r"() { return \g; }\g", max_repeat=0), 163 | # ~DisposableBase() => Destruct(); 164 | # ~DisposableBase() { Destruct(); } 165 | SubRule(r"~(?P[a-zA-Z_][a-zA-Z0-9_]*)\(\)\s+=>\s+([^;\r\n]+?);", r"~\g() { \1; }", max_repeat=0), 166 | # => Integer.Zero; 167 | # { return Integer.Zero; } 168 | SubRule(r"\)\s+=>\s+([^;\r\n]+?);", r") { return \1; }", max_repeat=0), 169 | # () { return avlTree.Count; } 170 | # [&]()-> auto { return avlTree.Count; } 171 | SubRule(r"(?P, |\()\(\) { return (?P[^;\r\n]+); }", r"\g[&]()-> auto { return \g; }", max_repeat=0), 172 | # Count => GetSizeOrZero(Root); 173 | # Count() { return GetSizeOrZero(Root); } 174 | SubRule(r"(\W)([A-Z][a-zA-Z]+)\s+=>\s+([^;\r\n]+);", r"\1\2() { return \3; }", max_repeat=0), 175 | # Insert scope borders. 176 | # interface IDisposable { ... } 177 | # interface IDisposable {/*~start~interface~IDisposable~*/ ... /*~end~interface~IDisposable~*/} 178 | SubRule(r"(?P\r?\n(?P[\t ]*)interface[\t ]*(?P[a-zA-Z][a-zA-Z0-9]*(<[^<>\n]*>)?)[^{}]*{)(?P(.|\n)*)(?P(?<=\r?\n)\k)(?P})", r"\g/*~start~interface~\g~*/\g\g/*~end~interface~\g~*/\g", max_repeat=0), 179 | # Inside the scope replace: 180 | # /*~start~interface~IDisposable~*/ ... bool IsDisposed { get; } ... /*~end~interface~IDisposable~*/ 181 | # /*~start~interface~IDisposable~*/ ... virtual bool IsDisposed() = 0; /*~end~interface~IDisposable~*/ 182 | SubRule(r"(?P(?P/\*~start~interface~(?P[^~\n\*]+)~\*/)(.|\n)+?)(?P(?P(private|protected|public): )?(?P[a-zA-Z_][a-zA-Z0-9_:<>]*) (?P[a-zA-Z_][a-zA-Z0-9_]*)(?P[\n\s]*{[\n\s]*)(\[[^\n]+\][\n\s]*)?get;(?P[\n\s]*}))(?P(.|\n)+?(?P/\*~end~interface~\k~\*/))", r"\gvirtual \g \g() = 0;\g", max_repeat=20), 183 | # Remove scope borders. 184 | # /*~start~interface~IDisposable~*/ 185 | # 186 | SubRule(r"/\*~[^~\*\n]+(~[^~\*\n]+)*~\*/", r"", max_repeat=0), 187 | # public: T Object { get; } 188 | # public: const T Object; 189 | SubRule(r"(?P[^\r]\r?\n[ \t]*)(?P(private|protected|public): )?(?P[a-zA-Z_][a-zA-Z0-9_:<>]*) (?P[a-zA-Z_][a-zA-Z0-9_]*)(?P[\n\s]*{[\n\s]*)(\[[^\n]+\][\n\s]*)?get;(?P[\n\s]*})(?P[\n\s]*)", r"\g\gconst \g \g;\g", max_repeat=2), 190 | # public: bool IsDisposed { get => _disposed > 0; } 191 | # public: bool IsDisposed() { return _disposed > 0; } 192 | SubRule(r"(?P[^\r]\r?\n[ \t]*)(?P(private|protected|public): )?(?Pvirtual )?bool (?P[a-zA-Z_][a-zA-Z0-9_]*)(?P[\n\s]*{[\n\s]*)(\[[^\n]+\][\n\s]*)?get\s*=>\s*(?P[^\n]+);(?P[\n\s]*}[\n\s]*)", r"\g\g\gbool \g()\greturn \g;\g", max_repeat=2), 193 | # protected: virtual std::string ObjectName { get => GetType().Name; } 194 | # protected: virtual std::string ObjectName() { return GetType().Name; } 195 | SubRule(r"(?P[^\r]\r?\n[ \t]*)(?P(private|protected|public): )?(?Pvirtual )?(?P[a-zA-Z_][a-zA-Z0-9_:<>]*) (?P[a-zA-Z_][a-zA-Z0-9_]*)(?P[\n\s]*{[\n\s]*)(\[[^\n]+\][\n\s]*)?get\s*=>\s*(?P[^\n]+);(?P[\n\s]*}[\n\s]*)", r"\g\g\g\g \g()\greturn \g;\g", max_repeat=2), 196 | # ArgumentInRange(string message) { string messageBuilder() { return message; } 197 | # ArgumentInRange(string message) { auto messageBuilder = [&]() -> string { return message; }; 198 | SubRule(r"(?P\W[_a-zA-Z0-9]+\([^\)\n]*\)[\s\n]*{[\s\n]*([^{}]|\n)*?(\r?\n)?[ \t]*)(?P[_a-zA-Z0-9*:]+[_a-zA-Z0-9*: ]*) (?P[_a-zA-Z0-9]+)\((?P[^\)\n]*)\)\s*{(?P(""[^""\n]+""|[^}]|\n)+?)}", r"\gauto \g = [&]() -> \g {\g};", max_repeat=10), 199 | # Func treeCount 200 | # std::function treeCount 201 | SubRule(r"Func<([a-zA-Z0-9]+)> ([a-zA-Z0-9]+)", r"std::function<\1()> \2", max_repeat=0), 202 | # Action free 203 | # std::function free 204 | SubRule(r"Action(<(?P[a-zA-Z0-9]+(, ([a-zA-Z0-9]+))*)>)?(?P>| (?P[a-zA-Z0-9]+))", r"std::function)>\g", max_repeat=0), 205 | # Predicate predicate 206 | # std::function predicate 207 | SubRule(r"Predicate<([a-zA-Z0-9]+)> ([a-zA-Z0-9]+)", r"std::function \2", max_repeat=0), 208 | # var 209 | # auto 210 | SubRule(r"(\W)var(\W)", r"\1auto\2", max_repeat=0), 211 | # unchecked 212 | # 213 | SubRule(r"[\r\n]{2}\s*?unchecked\s*?$", r"", max_repeat=0), 214 | # throw new 215 | # throw 216 | SubRule(r"(\W)throw new(\W)", r"\1throw\2", max_repeat=0), 217 | # void RaiseExceptionIgnoredEvent(Exception exception) 218 | # void RaiseExceptionIgnoredEvent(const std::exception& exception) 219 | SubRule(r"(\(|, )(System\.Exception|Exception)( |\))", r"\1const std::exception&\3", max_repeat=0), 220 | # EventHandler 221 | # EventHandler 222 | SubRule(r"(\W)(System\.Exception|Exception)(\W)", r"\1std::exception\3", max_repeat=0), 223 | # override void PrintNode(TElement node, StringBuilder sb, int level) 224 | # void PrintNode(TElement node, StringBuilder sb, int level) override 225 | SubRule(r"override ([a-zA-Z0-9 \*\+]+)(\([^\)\r\n]+?\))", r"\1\2 override", max_repeat=0), 226 | # return (range.Minimum, range.Maximum) 227 | # return {range.Minimum, range.Maximum} 228 | SubRule(r"(?Preturn\s*)\((?P[^\)\n]+)\)(?!\()(?P\W)", r"\g{\g}\g", max_repeat=0), 229 | # string 230 | # std::string 231 | SubRule(r"(?P\W)(?\W)", r"\gstd::string\g", max_repeat=0), 232 | # System.ValueTuple 233 | # std::tuple 234 | SubRule(r"(?P\W)(System\.)?ValueTuple(?!\s*=|\()(?P\W)", r"\gstd::tuple\g", max_repeat=0), 235 | # sbyte 236 | # std::int8_t 237 | SubRule(r"(?P\W)((System\.)?SB|sb)yte(?!\s*=|\()(?P\W)", r"\gstd::int8_t\g", max_repeat=0), 238 | # short 239 | # std::int16_t 240 | SubRule(r"(?P\W)((System\.)?Int16|short)(?!\s*=|\()(?P\W)", r"\gstd::int16_t\g", max_repeat=0), 241 | # int 242 | # std::int32_t 243 | SubRule(r"(?P\W)((System\.)?I|i)nt(32)?(?!\s*=|\()(?P\W)", r"\gstd::int32_t\g", max_repeat=0), 244 | # long 245 | # std::int64_t 246 | SubRule(r"(?P\W)((System\.)?Int64|long)(?!\s*=|\()(?P\W)", r"\gstd::int64_t\g", max_repeat=0), 247 | # byte 248 | # std::uint8_t 249 | SubRule(r"(?P\W)((System\.)?Byte|byte)(?!\s*=|\()(?P\W)", r"\gstd::uint8_t\g", max_repeat=0), 250 | # ushort 251 | # std::uint16_t 252 | SubRule(r"(?P\W)((System\.)?UInt16|ushort)(?!\s*=|\()(?P\W)", r"\gstd::uint16_t\g", max_repeat=0), 253 | # uint 254 | # std::uint32_t 255 | SubRule(r"(?P\W)((System\.)?UI|ui)nt(32)?(?!\s*=|\()(?P\W)", r"\gstd::uint32_t\g", max_repeat=0), 256 | # ulong 257 | # std::uint64_t 258 | SubRule(r"(?P\W)((System\.)?UInt64|ulong)(?!\s*=|\()(?P\W)", r"\gstd::uint64_t\g", max_repeat=0), 259 | # char*[] args 260 | # char* args[] 261 | SubRule(r"([_a-zA-Z0-9:\*]?)\[\] ([a-zA-Z0-9]+)", r"\1 \2[]", max_repeat=0), 262 | # float.MinValue 263 | # std::numeric_limits::lowest() 264 | SubRule(r"(?P\W)(?Pstd::[a-z0-9_]+|float|double)\.MinValue(?P\W)", r"\gstd::numeric_limits<\g>::lowest()\g", max_repeat=0), 265 | # double.MaxValue 266 | # std::numeric_limits::max() 267 | SubRule(r"(?P\W)(?Pstd::[a-z0-9_]+|float|double)\.MaxValue(?P\W)", r"\gstd::numeric_limits<\g>::max()\g", max_repeat=0), 268 | # using Platform.Numbers; 269 | # 270 | SubRule(r"([\r\n]{2}|^)\s*?using [\.a-zA-Z0-9]+;\s*?$", r"", max_repeat=0), 271 | # class SizedBinaryTreeMethodsBase : GenericCollectionMethodsBase 272 | # class SizedBinaryTreeMethodsBase : public GenericCollectionMethodsBase 273 | SubRule(r"(struct|class) ([a-zA-Z0-9]+)(<[a-zA-Z0-9 ,]+>)? : ([a-zA-Z0-9]+)", r"\1 \2\3 : public \4", max_repeat=0), 274 | # System.IDisposable 275 | # System::IDisposable 276 | SubRule(r"(?PSystem(::[a-zA-Z_]\w*)*)\.(?P[a-zA-Z_]\w*)", r"\g::\g", max_repeat=20), 277 | # class IProperty : ISetter, IProvider 278 | # class IProperty : public ISetter, public IProvider 279 | SubRule(r"(?P(interface|struct|class) [a-zA-Z_]\w* : ((public [a-zA-Z_][\w:]*(<[a-zA-Z0-9 ,]+>)?, )+)?)(?P(?!public)[a-zA-Z_][\w:]*(<[a-zA-Z0-9 ,]+>)?)(?P(, [a-zA-Z_][\w:]*(?!>)|[ \r\n]+))", r"\gpublic \g\g", max_repeat=10), 280 | # interface IDisposable { 281 | # class IDisposable { public: 282 | SubRule(r"(?P\r?\n)(?P[ \t]*)interface (?P[a-zA-Z_]\w*)(?P[^{]+){", r"\g\gclass \g\g{\n" + " public:", max_repeat=0), 283 | # struct TreeElement { } 284 | # struct TreeElement { }; 285 | SubRule(r"(struct|class) ([a-zA-Z0-9]+)(\s+){([\sa-zA-Z0-9;:_]+?)}([^;])", r"\1 \2\3{\4};\5", max_repeat=0), 286 | # class Program { } 287 | # class Program { }; 288 | SubRule(r"(?Pstruct|class) (?P[a-zA-Z0-9]+[^\r\n]*)(?P[\r\n]+(?P[\t ]*)?)\{(?P[\S\s]+?[\r\n]+\k)\}(?P[^;]|$)", r"\g \g\g{\g};\g", max_repeat=0), 289 | # Insert scope borders. 290 | # ref TElement root 291 | # ~!root!~ref TElement root 292 | SubRule(r"(?P(?<= |\()(ref [a-zA-Z0-9]+|[a-zA-Z0-9]+(?[a-zA-Z0-9]+)(?=\)|, | =))", r"~!\g!~\g", max_repeat=0), 293 | # Inside the scope of ~!root!~ replace: 294 | # root 295 | # *root 296 | SubRule(r"(?P~!(?P[a-zA-Z0-9]+)!~ref [a-zA-Z0-9]+ \k(?=\)|, | =))(?P((?!~)(.|\n))*?)(?P(\W |\())\k(?P( |\)|;|,))", r"\g\g\g*\g\g", max_repeat=70), 297 | # Remove scope borders. 298 | # ~!root!~ 299 | # 300 | SubRule(r"~!(?P[a-zA-Z0-9]+)!~", r"", max_repeat=5), 301 | # ref auto root = ref 302 | # ref auto root = 303 | SubRule(r"ref ([a-zA-Z0-9]+) ([a-zA-Z0-9]+) = ref(\W)", r"\1* \2 =\3", max_repeat=0), 304 | # *root = ref left; 305 | # root = left; 306 | SubRule(r"\*([a-zA-Z0-9]+) = ref ([a-zA-Z0-9]+)(\W)", r"\1 = \2\3", max_repeat=0), 307 | # (ref left) 308 | # (left) 309 | SubRule(r"\(ref ([a-zA-Z0-9]+)(\)|\(|,)", r"(\1\2", max_repeat=0), 310 | # ref TElement 311 | # TElement* 312 | SubRule(r"( |\()ref ([a-zA-Z0-9]+) ", r"\1\2* ", max_repeat=0), 313 | # ref sizeBalancedTree.Root 314 | # &sizeBalancedTree->Root 315 | SubRule(r"ref ([a-zA-Z0-9]+)\.([a-zA-Z0-9\*]+)", r"&\1->\2", max_repeat=0), 316 | # ref GetElement(node).Right 317 | # &GetElement(node)->Right 318 | SubRule(r"ref ([a-zA-Z0-9]+)\(([a-zA-Z0-9\*]+)\)\.([a-zA-Z0-9]+)", r"&\1(\2)->\3", max_repeat=0), 319 | # GetElement(node).Right 320 | # GetElement(node)->Right 321 | SubRule(r"([a-zA-Z0-9]+)\(([a-zA-Z0-9\*]+)\)\.([a-zA-Z0-9]+)", r"\1(\2)->\3", max_repeat=0), 322 | # [Fact]\npublic: static void SizeBalancedTreeMultipleAttachAndDetachTest() 323 | # public: TEST_METHOD(SizeBalancedTreeMultipleAttachAndDetachTest) 324 | SubRule(r"\[Fact\][\s\n]+(public: )?(static )?void ([a-zA-Z0-9]+)\(\)", r"public: TEST_METHOD(\3)", max_repeat=0), 325 | # class TreesTests 326 | # TEST_CLASS(TreesTests) 327 | SubRule(r"class ([a-zA-Z0-9]+Tests)", r"TEST_CLASS(\1)", max_repeat=0), 328 | # Assert.Equal 329 | # Assert::AreEqual 330 | SubRule(r"(?PAssert)\.(?P(Not)?Equal)", r"\g::Are\g", max_repeat=0), 331 | # Assert.Throws 332 | # Assert::ExpectException 333 | SubRule(r"(Assert)\.Throws", r"\1::ExpectException", max_repeat=0), 334 | # Assert.True 335 | # Assert::IsTrue 336 | SubRule(r"(Assert)\.(True|False)", r"\1::Is\2", max_repeat=0), 337 | # $"Argument {argumentName} is null." 338 | # std::string("Argument ").append(Platform::Converters::To(argumentName)).append(" is null.") 339 | SubRule(r"\$\"\"(?P(\\\"\"|[^\"\"\r\n])*){(?P[_a-zA-Z0-9]+)}(?P(\\\"\"|[^\"\"\r\n])*)\"\"", r"std::string($\"\g\").append(Platform::Converters::To(\g)).append(\"\g\")", max_repeat=10), 340 | # $" 341 | # " 342 | SubRule(r"\$""", r"\"", max_repeat=0), 343 | # std::string(std::string("[").append(Platform::Converters::To(Minimum)).append(", ")).append(Platform::Converters::To(Maximum)).append("]") 344 | # std::string("[").append(Platform::Converters::To(Minimum)).append(", ").append(Platform::Converters::To(Maximum)).append("]") 345 | SubRule(r"std::string\((?Pstd::string\(\"\"(\\\"\"|[^\"\"])*\"\"\)(\.append\((Platform::Converters::To\([^)\n]+\)|[^)\n]+)\))+)\)\.append", r"\g.append", max_repeat=10), 346 | # Console.WriteLine("...") 347 | # printf("...\n") 348 | SubRule(r"Console\.WriteLine\(\"\"([^\"\"\r\n]+)\"\"\)", r"printf(\"\1\\n\")", max_repeat=0), 349 | # TElement Root; 350 | # TElement Root = 0; 351 | SubRule(r"(?P\r?\n[\t ]+)(?P(private|protected|public)(: )?)?(?P[a-zA-Z0-9:_]+(?[_a-zA-Z0-9]+);", r"\g\g\g \g = 0;", max_repeat=0), 352 | # TreeElement _elements[N]; 353 | # TreeElement _elements[N] = { {0} }; 354 | SubRule(r"(\r?\n[\t ]+)(private|protected|public)?(: )?([a-zA-Z0-9]+) ([_a-zA-Z0-9]+)\[([_a-zA-Z0-9]+)\];", r"\1\2\3\4 \5[\6] = { {0} };", max_repeat=0), 355 | # auto path = new TElement[MaxPath]; 356 | # TElement path[MaxPath] = { {0} }; 357 | SubRule(r"(\r?\n[\t ]+)[a-zA-Z0-9]+ ([a-zA-Z0-9]+) = new ([a-zA-Z0-9]+)\[([_a-zA-Z0-9]+)\];", r"\1\3 \2[\4] = { {0} };", max_repeat=0), 358 | # bool Equals(Range other) { ... } 359 | # bool operator ==(const Key &other) const { ... } 360 | SubRule(r"(?P\r?\n[^\n]+bool )Equals\((?P[^\n{]+) (?P[a-zA-Z0-9]+)\)(?P(\s|\n)*{)", r"\goperator ==(const \g &\g) const\g", max_repeat=0), 361 | # Insert scope borders. 362 | # class Range { ... public: override std::string ToString() { return ...; } 363 | # class Range {/*~Range~*/ ... public: override std::string ToString() { return ...; } 364 | SubRule(r"(?P\r?\n(?P[\t ]*)template [^<>\n]+)> (struct|class) (?P[a-zA-Z0-9]+<\k>)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)(?P((?!class|struct).|\n)+?)(?P(?P(private|protected|public): )override std::string ToString\(\))", r"\g/*~\g~*/\g\g", max_repeat=0), 365 | # Inside the scope of ~!Range!~ replace: 366 | # public: override std::string ToString() { return ...; } 367 | # public: operator std::string() const { return ...; }\n\npublic: friend std::ostream & operator <<(std::ostream &out, const A &obj) { return out << (std::string)obj; } 368 | SubRule(r"(?P/\*~(?P[_a-zA-Z0-9<>:]+)~\*/)(?P.|\n)(?P((?~\*/)(.|\n))*?)(?P\r?\n(?P[ \t]*)(?P(private|protected|public): )override std::string ToString\(\) (?P{[^}\n]+}))", r"\g\g\g\n\g\goperator std::string() const \g\n\n\g\gfriend std::ostream & operator <<(std::ostream &out, const \g &obj) { return out << (std::string)obj; }", max_repeat=0), 369 | # Remove scope borders. 370 | # /*~Range~*/ 371 | # 372 | SubRule(r"/\*~[_a-zA-Z0-9<>:]+~\*/", r"", max_repeat=0), 373 | # private: inline static ConcurrentBag _exceptionsBag; 374 | # private: inline static std::mutex _exceptionsBag_mutex; \n\n private: inline static std::vector _exceptionsBag; 375 | SubRule(r"(?P\r?\n?(?P[ \t]+))(?P(private|protected|public): )?inline static ConcurrentBag<(?P[^;\r\n]+)> (?P[_a-zA-Z0-9]+);", r"\gprivate: inline static std::mutex \g_mutex;\n\n\g\ginline static std::vector<\g> \g;", max_repeat=0), 376 | # public: static IReadOnlyCollection GetCollectedExceptions() { return _exceptionsBag; } 377 | # public: static std::vector GetCollectedExceptions() { return std::vector(_exceptionsBag); } 378 | SubRule(r"(?P(private|protected|public): )?static IReadOnlyCollection<(?P[^;\r\n]+)> (?P[_a-zA-Z0-9]+)\(\) { return (?P[_a-zA-Z0-9]+); }", r"\gstatic std::vector<\g> \g() { return std::vector<\g>(\g); }", max_repeat=0), 379 | # public: static event EventHandler ExceptionIgnored = OnExceptionIgnored; ... }; 380 | # ... public: static inline Platform::Delegates::MulticastDelegate ExceptionIgnored = OnExceptionIgnored; }; 381 | SubRule(r"(?P\r?\n(\r?\n)?(?P[ \t]+)\k)(?P(private|protected|public): )?static event EventHandler<(?P[^;\r\n]+)> (?P[_a-zA-Z0-9]+) = (?P[_a-zA-Z0-9]+);(?P(.|\n)+?)(?P\r?\n\k};)", r"\g\n\n\g\g\gstatic inline Platform::Delegates::MulticastDelegate&)> \g = \g;\g", max_repeat=0), 382 | # public: event Disposal OnDispose; 383 | # public: Platform::Delegates::MulticastDelegate OnDispose; 384 | SubRule(r"(?P(?P(private|protected|public): )?(static )?)event (?P[a-zA-Z][:_a-zA-Z0-9]+) (?P[a-zA-Z][_a-zA-Z0-9]+);", r"\gPlatform::Delegates::MulticastDelegate<\g> \g;", max_repeat=0), 385 | # Insert scope borders. 386 | # class IgnoredExceptions { ... private: inline static std::vector _exceptionsBag; 387 | # class IgnoredExceptions {/*~_exceptionsBag~*/ ... private: inline static std::vector _exceptionsBag; 388 | SubRule(r"(?P\r?\n(?P[\t ]*)class [^{\r\n]+\r\n[\t ]*{)(?P((?!class).|\n)+?)(?P(?P(private|protected|public): )inline static std::vector<(?P[^;\r\n]+)> (?P[_a-zA-Z0-9]+);)", r"\g/*~\g~*/\g\g", max_repeat=0), 389 | # Inside the scope of ~!_exceptionsBag!~ replace: 390 | # _exceptionsBag.Add(exception); 391 | # _exceptionsBag.push_back(exception); 392 | SubRule(r"(?P/\*~(?P[_a-zA-Z0-9]+)~\*/)(?P.|\n)(?P((?~\*/)(.|\n))*?)\k\.Add", r"\g\g\g\g.push_back", max_repeat=10), 393 | # Remove scope borders. 394 | # /*~_exceptionsBag~*/ 395 | # 396 | SubRule(r"/\*~[_a-zA-Z0-9]+~\*/", r"", max_repeat=0), 397 | # Insert scope borders. 398 | # class IgnoredExceptions { ... private: static std::mutex _exceptionsBag_mutex; 399 | # class IgnoredExceptions {/*~_exceptionsBag~*/ ... private: static std::mutex _exceptionsBag_mutex; 400 | SubRule(r"(?P\r?\n(?P[\t ]*)class [^{\r\n]+\r\n[\t ]*{)(?P((?!class).|\n)+?)(?Pprivate: inline static std::mutex (?P[_a-zA-Z0-9]+)_mutex;)", r"\g/*~\g~*/\g\g", max_repeat=0), 401 | # Inside the scope of ~!_exceptionsBag!~ replace: 402 | # return std::vector(_exceptionsBag); 403 | # std::lock_guard guard(_exceptionsBag_mutex); return std::vector(_exceptionsBag); 404 | SubRule(r"(?P/\*~(?P[_a-zA-Z0-9]+)~\*/)(?P.|\n)(?P((?~\*/)(.|\n))*?){(?P((?!lock_guard)[^{};\r\n])*\k[^;}\r\n]*;)", r"\g\g\g{ std::lock_guard guard(\g_mutex);\g", max_repeat=10), 405 | # Inside the scope of ~!_exceptionsBag!~ replace: 406 | # _exceptionsBag.Add(exception); 407 | # std::lock_guard guard(_exceptionsBag_mutex); \r\n _exceptionsBag.Add(exception); 408 | SubRule(r"(?P/\*~(?P[_a-zA-Z0-9]+)~\*/)(?P.|\n)(?P((?~\*/)(.|\n))*?){(?P((?!lock_guard)([^{};]|\n))*?\r?\n(?P[ \t]*)\k[^;}\r\n]*;)", r"\g\g\g{\n" + "\gstd::lock_guard guard(\g_mutex);\g", max_repeat=10), 409 | # Remove scope borders. 410 | # /*~_exceptionsBag~*/ 411 | # 412 | SubRule(r"/\*~[_a-zA-Z0-9]+~\*/", r"", max_repeat=0), 413 | # Insert scope borders. 414 | # class IgnoredExceptions { ... public: static inline Platform::Delegates::MulticastDelegate ExceptionIgnored = OnExceptionIgnored; 415 | # class IgnoredExceptions {/*~ExceptionIgnored~*/ ... public: static inline Platform::Delegates::MulticastDelegate ExceptionIgnored = OnExceptionIgnored; 416 | SubRule(r"(?P\r?\n(?P[\t ]*)class [^{\r\n]+\r\n[\t ]*{)(?P((?!class).|\n)+?)(?P(?P(private|protected|public): )static inline Platform::Delegates::MulticastDelegate<(?P[^;\r\n]+)> (?P[_a-zA-Z0-9]+) = (?P[_a-zA-Z0-9]+);)", r"\g/*~\g~*/\g\g", max_repeat=0), 417 | # Inside the scope of ~!ExceptionIgnored!~ replace: 418 | # ExceptionIgnored.Invoke(NULL, exception); 419 | # ExceptionIgnored(NULL, exception); 420 | SubRule(r"(?P/\*~(?P[a-zA-Z0-9]+)~\*/)(?P.|\n)(?P((?~\*/)(.|\n))*?)\k\.Invoke", r"\g\g\g\g", max_repeat=10), 421 | # Remove scope borders. 422 | # /*~ExceptionIgnored~*/ 423 | # 424 | SubRule(r"/\*~[a-zA-Z0-9]+~\*/", r"", max_repeat=0), 425 | # Insert scope borders. 426 | # auto added = new StringBuilder(); 427 | # /*~sb~*/std::string added; 428 | SubRule(r"(auto|(System\.Text\.)?StringBuilder) (?P[a-zA-Z0-9]+) = new (System\.Text\.)?StringBuilder\(\);", r"/*~\g~*/std::string \g;", max_repeat=0), 429 | # static void Indent(StringBuilder sb, int level) 430 | # static void Indent(/*~sb~*/StringBuilder sb, int level) 431 | SubRule(r"(?P, |\()(System\.Text\.)?StringBuilder (?P[a-zA-Z0-9]+)(?P,|\))", r"\g/*~\g~*/std::string& \g\g", max_repeat=0), 432 | # Inside the scope of ~!added!~ replace: 433 | # sb.ToString() 434 | # sb 435 | SubRule(r"(?P/\*~(?P[a-zA-Z0-9]+)~\*/)(?P.|\n)(?P((?~\*/)(.|\n))*?)\k\.ToString\(\)", r"\g\g\g\g", max_repeat=10), 436 | # sb.AppendLine(argument) 437 | # sb.append(Platform::Converters::To(argument)).append(1, '\n') 438 | SubRule(r"(?P/\*~(?P[a-zA-Z0-9]+)~\*/)(?P.|\n)(?P((?~\*/)(.|\n))*?)\k\.AppendLine\((?P[^\),\r\n]+)\)", r"\g\g\g\g.append(Platform::Converters::To(\g)).append(1, '\\n')", max_repeat=10), 439 | # sb.Append('\t', level); 440 | # sb.append(level, '\t'); 441 | SubRule(r"(?P/\*~(?P[a-zA-Z0-9]+)~\*/)(?P.|\n)(?P((?~\*/)(.|\n))*?)\k\.Append\('(?P[^'\r\n]+)', (?P[^\),\r\n]+)\)", r"\g\g\g\g.append(\g, '\g')", max_repeat=10), 442 | # sb.Append(argument) 443 | # sb.append(Platform::Converters::To(argument)) 444 | SubRule(r"(?P/\*~(?P[a-zA-Z0-9]+)~\*/)(?P.|\n)(?P((?~\*/)(.|\n))*?)\k\.Append\((?P[^\),\r\n]+)\)", r"\g\g\g\g.append(Platform::Converters::To(\g))", max_repeat=10), 445 | # Remove scope borders. 446 | # /*~sb~*/ 447 | # 448 | SubRule(r"/\*~[a-zA-Z0-9]+~\*/", r"", max_repeat=0), 449 | # Insert scope borders. 450 | # auto added = new HashSet(); 451 | # ~!added!~std::unordered_set added; 452 | SubRule(r"auto (?P[a-zA-Z0-9]+) = new HashSet<(?P[a-zA-Z0-9]+)>\(\);", r"~!\g!~std::unordered_set<\g> \g;", max_repeat=0), 453 | # Inside the scope of ~!added!~ replace: 454 | # added.Add(node) 455 | # added.insert(node) 456 | SubRule(r"(?P~!(?P[a-zA-Z0-9]+)!~)(?P.|\n)(?P((?!~)(.|\n))*?)\k\.Add\((?P[a-zA-Z0-9]+)\)", r"\g\g\g\g.insert(\g)", max_repeat=10), 457 | # Inside the scope of ~!added!~ replace: 458 | # added.Remove(node) 459 | # added.erase(node) 460 | SubRule(r"(?P~!(?P[a-zA-Z0-9]+)!~)(?P.|\n)(?P((?!~)(.|\n))*?)\k\.Remove\((?P[a-zA-Z0-9]+)\)", r"\g\g\g\g.erase(\g)", max_repeat=10), 461 | # if (added.insert(node)) { 462 | # if (!added.contains(node)) { added.insert(node); 463 | SubRule(r"if \((?P[a-zA-Z0-9]+)\.insert\((?P[a-zA-Z0-9]+)\)\)(?P[\t ]*[\r\n]+)(?P[\t ]*){", r"if (!\g.contains(\g))\g\g{\n" + "\g \g.insert(\g);", max_repeat=0), 464 | # Remove scope borders. 465 | # ~!added!~ 466 | # 467 | SubRule(r"~![a-zA-Z0-9]+!~", r"", max_repeat=5), 468 | # Insert scope borders. 469 | # auto random = new System::Random(0); 470 | # std::srand(0); 471 | SubRule(r"[a-zA-Z0-9\.]+ ([a-zA-Z0-9]+) = new (System::)?Random\(([a-zA-Z0-9]+)\);", r"~!\1!~std::srand(\3);", max_repeat=0), 472 | # Inside the scope of ~!random!~ replace: 473 | # random.Next(1, N) 474 | # (std::rand() % N) + 1 475 | SubRule(r"(?P~!(?P[a-zA-Z0-9]+)!~)(?P.|\n)(?P((?!~)(.|\n))*?)\k\.Next\((?P[a-zA-Z0-9]+), (?P[a-zA-Z0-9]+)\)", r"\g\g\g(std::rand() % \g) + \g", max_repeat=10), 476 | # Remove scope borders. 477 | # ~!random!~ 478 | # 479 | SubRule(r"~![a-zA-Z0-9]+!~", r"", max_repeat=5), 480 | # Insert method body scope starts. 481 | # void PrintNodes(TElement node, StringBuilder sb, int level) { 482 | # void PrintNodes(TElement node, StringBuilder sb, int level) {/*method-start*/ 483 | SubRule(r"(?P\r?\n[\t ]+)(?P((private|protected|public): )?(virtual )?[a-zA-Z0-9:_]+ )?(?P[a-zA-Z][a-zA-Z0-9]*)\((?P[^\)]*)\)(?P( override)?)(?P[ \t\r\n]*)\{(?P[^~])", r"\g\g\g(\g)\g\g{/*method-start*/\g", max_repeat=0), 484 | # Insert method body scope ends. 485 | # {/*method-start*/...} 486 | # {/*method-start*/.../*method-end*/} 487 | SubRule(r"\{/\*method-start\*/(?P((?P\{)|(?(bracket)\})|[^\{\}]*)+)\}", r"{/*method-start*/\g/*method-end*/}", max_repeat=0), 488 | # Inside method bodies replace: 489 | # GetFirst( 490 | # this->GetFirst( 491 | SubRule(r"(?P/\*method-start\*/)(?P((?[\W](?|throw\s+)))(?P(?!sizeof)[a-zA-Z0-9]+)\((?!\) \{)(?P(.|\n)*?)(?P/\*method-end\*/)", r"\g\g\gthis->\g(\g\g", max_repeat=100), 492 | # Remove scope borders. 493 | # /*method-start*/ 494 | # 495 | SubRule(r"/\*method-(start|end)\*/", r"", max_repeat=0), 496 | # Insert scope borders. 497 | # const std::exception& ex 498 | # const std::exception& ex/*~ex~*/ 499 | SubRule(r"(?P\(| )(?P(const )?(std::)?exception&? (?P[_a-zA-Z0-9]+))(?P\W)", r"\g\g/*~\g~*/\g", max_repeat=0), 500 | # Inside the scope of ~!ex!~ replace: 501 | # ex.Message 502 | # ex.what() 503 | SubRule(r"(?P/\*~(?P[_a-zA-Z0-9]+)~\*/)(?P.|\n)(?P((?~\*/)(.|\n))*?)(Platform::Converters::To\(\k\.Message\)|\k\.Message)", r"\g\g\g\g.what()", max_repeat=10), 504 | # Remove scope borders. 505 | # /*~ex~*/ 506 | # 507 | SubRule(r"/\*~[_a-zA-Z0-9]+~\*/", r"", max_repeat=0), 508 | # throw ObjectDisposedException(objectName, message); 509 | # throw std::runtime_error(std::string("Attempt to access disposed object [").append(objectName).append("]: ").append(message).append(".")); 510 | SubRule(r"throw ObjectDisposedException\((?P[a-zA-Z_][a-zA-Z0-9_]*), (?P[a-zA-Z0-9_]*[Mm]essage[a-zA-Z0-9_]*(\(\))?|[a-zA-Z_][a-zA-Z0-9_]*)\);", r"throw std::runtime_error(std::string(\"Attempt to access disposed object [\").append(\g).append(\"]: \").append(\g).append(\".\"));", max_repeat=0), 511 | # throw ArgumentNullException(argumentName, message); 512 | # throw std::invalid_argument(std::string("Argument ").append(argumentName).append(" is null: ").append(message).append(".")); 513 | SubRule(r"throw ArgumentNullException\((?P[a-zA-Z]*[Aa]rgument[a-zA-Z]*), (?P[a-zA-Z]*[Mm]essage[a-zA-Z]*(\(\))?)\);", r"throw std::invalid_argument(std::string(\"Argument \").append(\g).append(\" is null: \").append(\g).append(\".\"));", max_repeat=0), 514 | # throw ArgumentException(message, argumentName); 515 | # throw std::invalid_argument(std::string("Invalid ").append(argumentName).append(" argument: ").append(message).append(".")); 516 | SubRule(r"throw ArgumentException\((?P[a-zA-Z]*[Mm]essage[a-zA-Z]*(\(\))?), (?P[a-zA-Z]*[Aa]rgument[a-zA-Z]*)\);", r"throw std::invalid_argument(std::string(\"Invalid \").append(\g).append(\" argument: \").append(\g).append(\".\"));", max_repeat=0), 517 | # throw ArgumentOutOfRangeException(argumentName, argumentValue, messageBuilder()); 518 | # throw std::invalid_argument(std::string("Value [").append(Platform::Converters::To(argumentValue)).append("] of argument [").append(argumentName).append("] is out of range: ").append(messageBuilder()).append(".")); 519 | SubRule(r"throw ArgumentOutOfRangeException\((?P[a-zA-Z]*[Aa]rgument[a-zA-Z]*([Nn]ame[a-zA-Z]*)?), (?P[a-zA-Z]*[Aa]rgument[a-zA-Z]*([Vv]alue[a-zA-Z]*)?), (?P[a-zA-Z]*[Mm]essage[a-zA-Z]*(\(\))?)\);", r"throw std::invalid_argument(std::string(\"Value [\").append(Platform::Converters::To(\g)).append(\"] of argument [\").append(\g).append(\"] is out of range: \").append(\g).append(\".\"));", max_repeat=0), 520 | # throw NotSupportedException(); 521 | # throw std::logic_error("Not supported exception."); 522 | SubRule(r"throw NotSupportedException\(\);", r"throw std::logic_error(\"Not supported exception.\");", max_repeat=0), 523 | # throw NotImplementedException(); 524 | # throw std::logic_error("Not implemented exception."); 525 | SubRule(r"throw NotImplementedException\(\);", r"throw std::logic_error(\"Not implemented exception.\");", max_repeat=0), 526 | # Insert scope borders. 527 | # const std::string& message 528 | # const std::string& message/*~message~*/ 529 | SubRule(r"(?P\(| )(?P(const )?((std::)?string&?|char\*) (?P[_a-zA-Z0-9]+))(?P\W)", r"\g\g/*~\g~*/\g", max_repeat=0), 530 | # Inside the scope of /*~message~*/ replace: 531 | # Platform::Converters::To(message) 532 | # message 533 | SubRule(r"(?P/\*~(?P[_a-zA-Z0-9]+)~\*/)(?P.|\n)(?P((?~\*/)(.|\n))*?)Platform::Converters::To\(\k\)", r"\g\g\g\g", max_repeat=10), 534 | # Remove scope borders. 535 | # /*~ex~*/ 536 | # 537 | SubRule(r"/\*~[_a-zA-Z0-9]+~\*/", r"", max_repeat=0), 538 | # Insert scope borders. 539 | # std::tuple tuple 540 | # std::tuple tuple/*~tuple~*/ 541 | SubRule(r"(?P\(| )(?P(const )?(std::)?tuple<[^\n]+>&? (?P[_a-zA-Z0-9]+))(?P\W)", r"\g\g/*~\g~*/\g", max_repeat=0), 542 | # Inside the scope of ~!ex!~ replace: 543 | # tuple.Item1 544 | # std::get<1-1>(tuple) 545 | SubRule(r"(?P/\*~(?P[_a-zA-Z0-9]+)~\*/)(?P.|\n)(?P((?~\*/)(.|\n))*?)\k\.Item(?P\d+)(?P\W)", r"\g\g\gstd::get<\g-1>(\g)\g", max_repeat=10), 546 | # Remove scope borders. 547 | # /*~ex~*/ 548 | # 549 | SubRule(r"/\*~[_a-zA-Z0-9]+~\*/", r"", max_repeat=0), 550 | # Insert scope borders. 551 | # class Range { 552 | # class Range {/*~type~Range~*/ 553 | SubRule(r"(?P\r?\n(?P[\t ]*)(template\s*<[^<>\n]*> )?(struct|class) (?P(?P[a-zA-Z0-9]+)(<[^:\n]*>)?)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)", r"\g/*~type~\g~\g~*/", max_repeat=0), 554 | # Inside the scope of /*~type~Range~*/ insert inner scope and replace: 555 | # public: static implicit operator std::tuple(Range range) 556 | # public: operator std::tuple() const {/*~variable~Range~*/ 557 | SubRule(r"(?P/\*~type~(?P[^~\n\*]+)~(?P[^~\n\*]+)~\*/)(?P.|\n)(?P((?~\k~\*/)(.|\n))*?)(?P(private|protected|public): )static implicit operator (?P[^\(\n]+)\((?P\k (?P[a-zA-Z0-9]+))\)(?P\s*\n?\s*{)", r"\g\g\g\goperator \g() const\g/*~variable~\g~*/", max_repeat=10), 558 | # Inside the scope of /*~type~Range~*/ replace: 559 | # public: static implicit operator Range(std::tuple tuple) { return new Range(std::get<1-1>(tuple), std::get<2-1>(tuple)); } 560 | # public: Range(std::tuple tuple) : Range(std::get<1-1>(tuple), std::get<2-1>(tuple)) { } 561 | SubRule(r"(?P/\*~type~(?P[^~\n\*]+)~(?P[^~\n\*]+)~\*/)(?P.|\n)(?P((?~\k~\*/)(.|\n))*?)(?P(private|protected|public): )static implicit operator (\k|\k)\((?P[^{}\n]+)\)(\s|\n)*{(\s|\n)*return (new )?(\k|\k)\((?P[^\n]+)\);(\s|\n)*}", r"\g\g\g\g\g(\g) : \g(\g) { }", max_repeat=10), 562 | # Inside the scope of /*~variable~range~*/ replace: 563 | # range.Minimum 564 | # this->Minimum 565 | SubRule(r"(?P{/\*~variable~(?P[^~\n]+)~\*/)(?P.|\n)(?P(?P(?P{)|(?(bracket)})|[^{}]|\n)*?)\k\.(?P[_a-zA-Z0-9]+)(?P(,|;|}| |\))(?P(?P{)|(?(bracket)})|[^{}]|\n)*?})", r"\g\g\gthis->\g\g", max_repeat=10), 566 | # Remove scope borders. 567 | # /*~ex~*/ 568 | # 569 | SubRule(r"/\*~[^~\n]+~[^~\n]+~\*/", r"", max_repeat=0), 570 | # Insert scope borders. 571 | # namespace Platform::Ranges { ... } 572 | # namespace Platform::Ranges {/*~start~namespace~Platform::Ranges~*/ ... /*~end~namespace~Platform::Ranges~*/} 573 | SubRule(r"(?P\r?\n(?P[\t ]*)namespace (?P(?P[a-zA-Z][a-zA-Z0-9]+)(?P::[a-zA-Z][a-zA-Z0-9]+)+)(\s|\n)*{)(?P(.|\n)*)(?P(?<=\r?\n)\k}(?!;))", r"\g/*~start~namespace~\g~*/\g/*~end~namespace~\g~*/\g", max_repeat=0), 574 | # Insert scope borders. 575 | # class Range { ... }; 576 | # class Range {/*~start~type~Range~T~*/ ... /*~end~type~Range~T~*/}; 577 | SubRule(r"(?P\r?\n(?P[\t ]*)template [^\n]+)> (struct|class) (?P[a-zA-Z0-9]+<\k>)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)(?P(.|\n)*)(?P(?<=\r?\n)\k)(?P};)", r"\g/*~start~type~\g~\g~*/\g\g/*~end~type~\g~\g~*/\g", max_repeat=0), 578 | # Inside the scope replace: 579 | # /*~start~namespace~Platform::Ranges~*/ ... /*~start~type~Range~T~*/ ... public: override std::int32_t GetHashCode() { return {Minimum, Maximum}.GetHashCode(); } ... /*~end~type~Range~T~*/ ... /*~end~namespace~Platform::Ranges~*/ 580 | # /*~start~namespace~Platform::Ranges~*/ ... /*~start~type~Range~T~*/ ... /*~end~type~Range~T~*/ ... /*~end~namespace~Platform::Ranges~*/ namespace std { template struct hash> { std::size_t operator()(const Platform::Ranges::Range &obj) const { return {Minimum, Maximum}.GetHashCode(); } }; } 581 | SubRule(r"(?P/\*~start~namespace~(?P[^~\n\*]+)~\*/)(?P(.|\n)+)(?P/\*~start~type~(?P[^~\n\*]+)~(?P[^~\n\*]+)~\*/)(?P(.|\n)+?)(?P\r?\n[ \t]*(?P(private|protected|public): )override std::int32_t GetHashCode\(\)(\s|\n)*{\s*(?P[^\s][^\n]+[^\s])\s*}\s*)(?P(.|\n)+?)(?P/\*~end~type~\k~\k~\*/)(?P(.|\n)+)(?P/\*~end~namespace~\k~\*/)}\r?\n", r"\g\g\g\g\g\g\g\g}\n" + "\nnamespace std\n" + "{\n" + " template >\n" + " struct hash<\g::\g>\n" + " {\n" + " std::size_t operator()(const \g::\g &obj) const\n" + " {\n" + " /*~start~method~*/\g/*~end~method~*/\n" + " }\n" + " };\n" + "}\n", max_repeat=10), 582 | # Inside scope of /*~start~method~*/ replace: 583 | # /*~start~method~*/ ... Minimum ... /*~end~method~*/ 584 | # /*~start~method~*/ ... obj.Minimum ... /*~end~method~*/ 585 | SubRule(r"(?P/\*~start~method~\*/)(?P.+({|, ))(?P[a-zA-Z][a-zA-Z0-9]+)(?P[^\n\.\(a-zA-Z0-9]((?!/\*~end~method~\*/)[^\n])+)(?P/\*~end~method~\*/)", r"\g\gobj.\g\g\g", max_repeat=10), 586 | # Remove scope borders. 587 | # /*~start~type~Range~*/ 588 | # 589 | SubRule(r"/\*~[^~\*\n]+(~[^~\*\n]+)*~\*/", r"", max_repeat=0), 590 | # class Disposable : public Disposable 591 | # class Disposable : public Disposable<> 592 | SubRule(r"(?P(struct|class) (?P[a-zA-Z][a-zA-Z0-9]*)<[^<>\n]+> : (?P(private|protected|public) )?\k)(?P\b(?!<))", r"\g<>\g", max_repeat=0), 593 | # Insert scope borders. 594 | # class Disposable : public Disposable<> { ... }; 595 | # class Disposable : public Disposable<> {/*~start~type~Disposable~Disposable~Disposable~Disposable<>~*/ ... /*~end~type~Disposable~Disposable~Disposable~Disposable<>~*/}; 596 | SubRule(r"(?P\r?\n(?P[\t ]*)template[\t ]*<(?P[^\n]*)>[\t ]*(struct|class)[\t ]+(?P(?P[a-zA-Z][a-zA-Z0-9]*)(<[^<>\n]*>)?)[\t ]*:[\t ]*(?P(private|protected|public)[\t ]+)?(?P(?P[a-zA-Z][a-zA-Z0-9]*)(<[^<>\n]*>)?)[\t ]*(\r?\n)?[\t ]*{)(?P(.|\n)*)(?P(?<=\r?\n)\k)(?P};)", r"\g/*~start~type~\g~\g~\g~\g~*/\g\g/*~end~type~\g~\g~\g~\g~*/\g", max_repeat=0), 597 | # Inside the scope replace: 598 | # /*~start~type~Disposable~Disposable~Disposable~Disposable<>~*/ ... ) : base( ... /*~end~type~Disposable~Disposable~Disposable~Disposable<>~*/ 599 | # /*~start~type~Disposable~Disposable~Disposable~Disposable<>~*/ ... ) : Disposable<>( /*~end~type~Disposable~Disposable~Disposable~Disposable<>~*/ 600 | SubRule(r"(?P(?P/\*~start~type~(?P(?P[^~\n\*]+)~(?P[^~\n\*]+)~\k~(?P[^~\n\*]+))~\*/)(.|\n)+?\)\s*:\s)base(?P\((.|\n)+?(?P/\*~end~type~\k~\*/))", r"\g\g\g", max_repeat=20), 601 | # Inside the scope replace: 602 | # /*~start~type~Disposable~Disposable~X~X<>~*/ ... ) : base( ... /*~end~type~Disposable~Disposable~X~X<>~*/ 603 | # /*~start~type~Disposable~Disposable~X~X<>~*/ ... ) : X( /*~end~type~Disposable~Disposable~X~X<>~*/ 604 | SubRule(r"(?P(?P/\*~start~type~(?P(?P[^~\n\*]+)~(?P[^~\n\*]+)~(?P[^~\n\*]+)~(?P[^~\n\*]+))~\*/)(.|\n)+?\)\s*:\s)base(?P\((.|\n)+?(?P/\*~end~type~\k~\*/))", r"\g\g\g", max_repeat=20), 605 | # Inside the scope replace: 606 | # /*~start~type~Disposable~Disposable~X~X<>~*/ ... public: Disposable(T object) { Object = object; } ... public: Disposable(T object) : Disposable(object) { } ... /*~end~type~Disposable~Disposable~X~X<>~*/ 607 | # /*~start~type~Disposable~Disposable~X~X<>~*/ ... public: Disposable(T object) { Object = object; } /*~end~type~Disposable~Disposable~X~X<>~*/ 608 | SubRule(r"(?P(?P/\*~start~type~(?P(?P[^~\n\*]+)~(?P[^~\n\*]+)~(?P[^~\n\*]+)~(?P[^~\n\*]+))~\*/)(.|\n)+?(?P(?P(private|protected|public):[\t ]*)?\k\((?P[^()\n]+)\)\s*{[^{}\n]+})(.|\n)+?)(?P(?P(private|protected|public):[\t ]*)?\k\(\k\)\s*:[^{}\n]+\s*{[^{}\n]+})(?P(.|\n)+?(?P/\*~end~type~\k~\*/))", r"\g\g", max_repeat=20), 609 | # Remove scope borders. 610 | # /*~start~type~Disposable~Disposable~Disposable~Disposable<>~*/ 611 | # 612 | SubRule(r"/\*~[^~\*\n]+(~[^~\*\n]+)*~\*/", r"", max_repeat=0), 613 | # Insert scope borders. 614 | # private: inline static const AppDomain _currentDomain = AppDomain.CurrentDomain; 615 | # private: inline static const AppDomain _currentDomain = AppDomain.CurrentDomain;/*~app-domain~_currentDomain~*/ 616 | SubRule(r"(?P(?P(private|protected|public):[\t ]*)?(inline[\t ]+)?(static[\t ]+)?(const[\t ]+)?AppDomain[\t ]+(?P[a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*AppDomain\.CurrentDomain;)", r"\g/*~app-domain~\g~*/", max_repeat=0), 617 | # Inside the scope replace: 618 | # /*~app-domain~_currentDomain~*/ ... _currentDomain.ProcessExit += OnProcessExit; 619 | # /*~app-domain~_currentDomain~*/ ... std::atexit(OnProcessExit); 620 | SubRule(r"(?P(?P/\*~app-domain~(?P[^~\n\*]+)~\*/)(.|\n)+?)\k\.ProcessExit[\t ]*\+=[\t ]*(?P[a-zA-Z_][a-zA-Z0-9_]*);", r"\gstd::atexit(\g);/*~process-exit-handler~\g~*/", max_repeat=20), 621 | # Inside the scope replace: 622 | # /*~app-domain~_currentDomain~*/ ... _currentDomain.ProcessExit -= OnProcessExit; 623 | # /*~app-domain~_currentDomain~*/ ... /* No translation. It is not possible to unsubscribe from std::atexit. */ 624 | SubRule(r"(?P(?P/\*~app-domain~(?P[^~\n\*]+)~\*/)(.|\n)+?\r?\n[\t ]*)\k\.ProcessExit[\t ]*\-=[\t ]*(?P[a-zA-Z_][a-zA-Z0-9_]*);", r"\g/* No translation. It is not possible to unsubscribe from std::atexit. */", max_repeat=20), 625 | # Inside the scope replace: 626 | # /*~process-exit-handler~OnProcessExit~*/ ... static void OnProcessExit(void *sender, EventArgs e) 627 | # /*~process-exit-handler~OnProcessExit~*/ ... static void OnProcessExit() 628 | SubRule(r"(?P(?P/\*~process-exit-handler~(?P[^~\n\*]+)~\*/)(.|\n)+?static[\t ]+void[\t ]+\k\()[^()\n]+\)", r"\g)", max_repeat=20), 629 | # Remove scope borders. 630 | # /*~app-domain~_currentDomain~*/ 631 | # 632 | SubRule(r"/\*~[^~\*\n]+(~[^~\*\n]+)*~\*/", r"", max_repeat=0), 633 | # AppDomain.CurrentDomain.ProcessExit -= OnProcessExit; 634 | # /* No translation. It is not possible to unsubscribe from std::atexit. */ 635 | SubRule(r"AppDomain\.CurrentDomain\.ProcessExit -= ([a-zA-Z_][a-zA-Z0-9_]*);", r"/* No translation. It is not possible to unsubscribe from std::atexit. */", max_repeat=0), 636 | ] 637 | 638 | 639 | LAST_RULES = [ 640 | # IDisposable disposable) 641 | # IDisposable &disposable) 642 | SubRule(r"(?PI[A-Z][a-zA-Z0-9]+(<[^>\r\n]+>)?) (?P[_a-zA-Z0-9]+)(?P,|\))", r"\g &\g\g", max_repeat=0), 643 | # ICounter c1; 644 | # ICounter* c1; 645 | SubRule(r"(?PI[A-Z][a-zA-Z0-9]+(<[^>\r\n]+>)?) (?P[_a-zA-Z0-9]+)(?P = null)?;", r"\g *\g\g;", max_repeat=0), 646 | # (expression) 647 | # expression 648 | SubRule(r"(\(| )\(([a-zA-Z0-9_\*:]+)\)(,| |;|\))", r"\1\2\3", max_repeat=0), 649 | # (method(expression)) 650 | # method(expression) 651 | SubRule(r"(?P(\(| ))\((?P[a-zA-Z0-9_\->\*:]+)\((?P((?P\()|(?(parenthesis)\))|[a-zA-Z0-9_\->\*:]*)+)(?(parenthesis)(?!))\)\)(?P(,| |;|\)))", r"\g\g(\g)\g", max_repeat=0), 652 | # .append(".") 653 | # .append(1, '.'); 654 | SubRule(r"\.append\(""([^\\""]|\\[^""])""\)", r".append(1, '\1')", max_repeat=0), 655 | # return ref _elements[node]; 656 | # return &_elements[node]; 657 | SubRule(r"return ref ([_a-zA-Z0-9]+)\[([_a-zA-Z0-9\*]+)\];", r"return &\1[\2];", max_repeat=0), 658 | # ((1, 2)) 659 | # ({1, 2}) 660 | SubRule(r"(?P\(|, )\((?P[^\n()]+), (?P[^\n()]+)\)(?P\)|, )", r"\g{\g, \g}\g", max_repeat=10), 661 | # {1, 2}.GetHashCode() 662 | # Platform::Hashing::Hash(1, 2) 663 | SubRule(r"{(?P[^\n{}]+), (?P[^\n{}]+)}\.GetHashCode\(\)", r"Platform::Hashing::Hash(\g, \g)", max_repeat=10), 664 | # range.ToString() 665 | # Platform::Converters::To(range).data() 666 | SubRule(r"(?P\W)(?P[_a-zA-Z][_a-zA-Z0-9]+)\.ToString\(\)", r"\gPlatform::Converters::To(\g).data()", max_repeat=10), 667 | # new 668 | # 669 | SubRule(r"(?P\r?\n[^\"\"\r\n]*(\"\"(\\\"\"|[^\"\"\r\n])*\"\"[^\"\"\r\n]*)*)(?<=\W)new\s+", r"\g", max_repeat=10), 670 | # x == null 671 | # x == nullptr 672 | SubRule(r"(?P\r?\n[^\"\"\r\n]*(\"\"(\\\"\"|[^\"\"\r\n])*\"\"[^\"\"\r\n]*)*)(?<=\W)(?P[_a-zA-Z][_a-zA-Z0-9]+)(?P\s*(==|!=)\s*)null(?P\W)", r"\g\g\gnullptr\g", max_repeat=10), 673 | # null 674 | # {} 675 | SubRule(r"(?P\r?\n[^\"\"\r\n]*(\"\"(\\\"\"|[^\"\"\r\n])*\"\"[^\"\"\r\n]*)*)(?<=\W)null(?P\W)", r"\g{}\g", max_repeat=10), 676 | # default 677 | # 0 678 | SubRule(r"(?P\r?\n[^\"\"\r\n]*(\"\"(\\\"\"|[^\"\"\r\n])*\"\"[^\"\"\r\n]*)*)(?<=\W)default(?P\W)", r"\g0\g", max_repeat=10), 679 | # object x 680 | # void *x 681 | SubRule(r"(?P\r?\n[^\"\"\r\n]*(\"\"(\\\"\"|[^\"\"\r\n])*\"\"[^\"\"\r\n]*)*)(?<=\W)(?\w)", r"\gvoid *\g", max_repeat=10), 682 | # 683 | # 684 | SubRule(r"(?P\r?\n[^\"\"\r\n]*(\"\"(\\\"\"|[^\"\"\r\n])*\"\"[^\"\"\r\n]*)*)(?<=\W)(?\W)", r"\gvoid*\g", max_repeat=10), 685 | # @object 686 | # object 687 | SubRule(r"@([_a-zA-Z0-9]+)", r"\1", max_repeat=0), 688 | # this->GetType().Name 689 | # typeid(this).name() 690 | SubRule(r"(this)->GetType\(\)\.Name", r"typeid(\1).name()", max_repeat=0), 691 | # ArgumentNullException 692 | # std::invalid_argument 693 | SubRule(r"(?P\r?\n[^\"\"\r\n]*(\"\"(\\\"\"|[^\"\"\r\n])*\"\"[^\"\"\r\n]*)*)(?<=\W)(System\.)?ArgumentNullException(?P\W)", r"\gstd::invalid_argument\g", max_repeat=10), 694 | # InvalidOperationException 695 | # std::runtime_error 696 | SubRule(r"(\W)(InvalidOperationException|Exception)(\W)", r"\1std::runtime_error\3", max_repeat=0), 697 | # ArgumentException 698 | # std::invalid_argument 699 | SubRule(r"(\W)(ArgumentException|ArgumentOutOfRangeException)(\W)", r"\1std::invalid_argument\3", max_repeat=0), 700 | # template struct Range : IEquatable> 701 | # template struct Range { 702 | SubRule(r"(?Ptemplate [^\n]+)> (struct|class) (?P[a-zA-Z0-9]+<[^\n]+>)) : (public )?IEquatable<\k>(?P(\s|\n)*{)", r"\g\g", max_repeat=0), 703 | # public: delegate void Disposal(bool manual, bool wasDisposed); 704 | # public: delegate void Disposal(bool, bool); 705 | SubRule(r"(?P(?P(private|protected|public): )delegate (?P[a-zA-Z][a-zA-Z0-9:]+) (?P[a-zA-Z][a-zA-Z0-9]+)\(((?P[a-zA-Z][a-zA-Z0-9:]+), )*)(?P[a-zA-Z][a-zA-Z0-9:]+) (?P[a-zA-Z][a-zA-Z0-9]+)(?P(, (?P[a-zA-Z][a-zA-Z0-9:]+) (?P[a-zA-Z][a-zA-Z0-9]+))*\);)", r"\g\g\g", max_repeat=20), 706 | # public: delegate void Disposal(bool, bool); 707 | # using Disposal = void(bool, bool); 708 | SubRule(r"(?P(private|protected|public): )delegate (?P[a-zA-Z][a-zA-Z0-9:]+) (?P[a-zA-Z][a-zA-Z0-9]+)\((?P[^\(\)\n]*)\);", r"using \g = \g(\g);", max_repeat=20), 709 | # <4-1> 710 | # <3> 711 | SubRule(r"(?P<)4-1(?P>)", r"\g3\g", max_repeat=0), 712 | # <3-1> 713 | # <2> 714 | SubRule(r"(?P<)3-1(?P>)", r"\g2\g", max_repeat=0), 715 | # <2-1> 716 | # <1> 717 | SubRule(r"(?P<)2-1(?P>)", r"\g1\g", max_repeat=0), 718 | # <1-1> 719 | # <0> 720 | SubRule(r"(?P<)1-1(?P>)", r"\g0\g", max_repeat=0), 721 | # #region Always 722 | # 723 | SubRule(r"(^|\r?\n)[ \t]*\#(region|endregion)[^\r\n]*(\r?\n|$)", r"", max_repeat=0), 724 | # //#define ENABLE_TREE_AUTO_DEBUG_AND_VALIDATION 725 | # 726 | SubRule(r"\/\/[ \t]*\#define[ \t]+[_a-zA-Z0-9]+[ \t]*", r"", max_repeat=0), 727 | # #if USEARRAYPOOL\r\n#endif 728 | # 729 | SubRule(r"#if [a-zA-Z0-9]+\s+#endif", r"", max_repeat=0), 730 | # [Fact] 731 | # 732 | SubRule(r"(?P\r?\n|\A)(?P[\t ]+)\[[a-zA-Z0-9]+(\((?P((?P\()|(?(parenthesis)\))|[^()\r\n]*)+)(?(parenthesis)(?!))\))?\][ \t]*(\r?\n\k)?", r"\g\g", max_repeat=5), 733 | # \A \n ... namespace 734 | # \Anamespace 735 | SubRule(r"(\A)(\r?\n)+namespace", r"\1namespace", max_repeat=0), 736 | # \A \n ... class 737 | # \Aclass 738 | SubRule(r"(\A)(\r?\n)+class", r"\1class", max_repeat=0), 739 | # \n\n\n 740 | # \n\n 741 | SubRule(r"\r?\n[ \t]*\r?\n[ \t]*\r?\n", r"\n\n", max_repeat=50), 742 | # {\n\n 743 | # {\n 744 | SubRule(r"{[ \t]*\r?\n[ \t]*\r?\n", r"{\n", max_repeat=10), 745 | # \n\n} 746 | # \n} 747 | SubRule(r"\r?\n[ \t]*\r?\n(?P[ \t]*})", "\n\g", max_repeat=10), 748 | ] 749 | -------------------------------------------------------------------------------- /csharp/Platform.RegularExpressions.Transformer.CSharpToCpp/CSharpToCppTransformer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text.RegularExpressions; 5 | 6 | #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member 7 | 8 | namespace Platform.RegularExpressions.Transformer.CSharpToCpp 9 | { 10 | /// 11 | /// 12 | /// Represents the sharp to cpp transformer. 13 | /// 14 | /// 15 | /// 16 | /// 17 | public class CSharpToCppTransformer : TextTransformer 18 | { 19 | /// 20 | /// 21 | /// The to list. 22 | /// 23 | /// 24 | /// 25 | public static readonly IList FirstStage = new List 26 | { 27 | // // ... 28 | // 29 | (new Regex(@"(\r?\n)?[ \t]+//+.+"), "", 0), 30 | // #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member 31 | // 32 | (new Regex(@"^\s*?\#pragma[\sa-zA-Z0-9]+$"), "", 0), 33 | // {\n\n\n 34 | // { 35 | (new Regex(@"{\s+[\r\n]+"), "{" + Environment.NewLine, 0), 36 | // Platform.Collections.Methods.Lists 37 | // Platform::Collections::Methods::Lists 38 | (new Regex(@"(namespace[^\r\n]+?)\.([^\r\n]+?)"), "$1::$2", 20), 39 | // nameof(numbers) 40 | // "numbers" 41 | (new Regex(@"(?\W)nameof\(([^)\n]+\.)?(?[a-zA-Z0-9_]+)(<[^)\n]+>)?\)"), "${before}\"${name}\"", 0), 42 | // Insert markers 43 | // EqualityComparer _equalityComparer = EqualityComparer.Default; 44 | // EqualityComparer _equalityComparer = EqualityComparer.Default;/*~_comparer~*/ 45 | (new Regex(@"(?EqualityComparer<(?[^>\n]+)> (?[a-zA-Z0-9_]+) = EqualityComparer<\k>\.Default;)"), "${declaration}/*~${comparer}~*/", 0), 46 | // /*~_equalityComparer~*/..._equalityComparer.Equals(Minimum, value) 47 | // /*~_equalityComparer~*/...Minimum == value 48 | (new Regex(@"(?/\*~(?[a-zA-Z0-9_]+)~\*/(.|\n)+\W)\k\.Equals\((?[^,\n]+), (?[^)\n]+)\)"), "${before}${left} == ${right}", 50), 49 | // Remove markers 50 | // /*~_equalityComparer~*/ 51 | // 52 | (new Regex(@"\r?\n[^\n]+/\*~[a-zA-Z0-9_]+~\*/"), "", 10), 53 | // Insert markers 54 | // Comparer _comparer = Comparer.Default; 55 | // Comparer _comparer = Comparer.Default;/*~_comparer~*/ 56 | (new Regex(@"(?Comparer<(?[^>\n]+)> (?[a-zA-Z0-9_]+) = Comparer<\k>\.Default;)"), "${declaration}/*~${comparer}~*/", 0), 57 | // /*~_comparer~*/..._comparer.Compare(Minimum, value) <= 0 58 | // /*~_comparer~*/...Minimum <= value 59 | (new Regex(@"(?/\*~(?[a-zA-Z0-9_]+)~\*/(.|\n)+\W)\k\.Compare\((?[^,\n]+), (?[^)\n]+)\)\s*(?[<>=]=?)\s*0(?\D)"), "${before}${left} ${comparison} ${right}${after}", 50), 60 | // Remove markers 61 | // private static readonly Comparer _comparer = Comparer.Default;/*~_comparer~*/ 62 | // 63 | (new Regex(@"\r?\n[^\n]+/\*~[a-zA-Z0-9_]+~\*/"), "", 10), 64 | // Comparer.Default.Compare(maximumArgument, minimumArgument) < 0 65 | // maximumArgument < minimumArgument 66 | (new Regex(@"Comparer<[^>\n]+>\.Default\.Compare\(\s*(?[^,)\n]+),\s*(?[^\)\n]+)\s*\)\s*(?[<>=]=?)\s*0(?\D)"), "${first} ${comparison} ${second}${after}", 0), 67 | // public static bool operator ==(Range left, Range right) => left.Equals(right); 68 | // 69 | (new Regex(@"\r?\n[^\n]+bool operator ==\((?[^\n]+) (?[a-zA-Z0-9]+), \k (?[a-zA-Z0-9]+)\) => (\k|\k)\.Equals\((\k|\k)\);"), "", 10), 70 | // public static bool operator !=(Range left, Range right) => !(left == right); 71 | // 72 | (new Regex(@"\r?\n[^\n]+bool operator !=\((?[^\n]+) (?[a-zA-Z0-9]+), \k (?[a-zA-Z0-9]+)\) => !\((\k|\k) == (\k|\k)\);"), "", 10), 73 | // public override bool Equals(object obj) => obj is Range range ? Equals(range) : false; 74 | // 75 | (new Regex(@"\r?\n[^\n]+override bool Equals\((System\.)?[Oo]bject (?[a-zA-Z0-9]+)\) => \k is [^\n]+ (?[a-zA-Z0-9]+) \? Equals\(\k\) : false;"), "", 10), 76 | // out TProduct 77 | // TProduct 78 | (new Regex(@"(?(<|, ))(in|out) (?[a-zA-Z0-9]+)(?(>|,))"), "${before}${typeParameter}${after}", 10), 79 | // public ... 80 | // public: ... 81 | (new Regex(@"(?\r?\n?[ \t]*)(?[^\{\(\r\n]*)(?private|protected|public)[ \t]+(?![^\{\(\r\n]*((?<=\s)|\W)(interface|class|struct)(\W)[^\{\(\r\n]*[\{\(\r\n])"), "${newLineAndIndent}${access}: ${before}", 0), 82 | // public: static bool CollectExceptions { get; set; } 83 | // public: inline static bool CollectExceptions; 84 | (new Regex(@"(?(private|protected|public): )(?(static )?[^\r\n]+ )(?[a-zA-Z0-9]+) {[^;}]*(?<=\W)get;[^;}]*(?<=\W)set;[^;}]*}"), "${access}inline ${before}${name};", 0), 85 | // public abstract class 86 | // class 87 | (new Regex(@"((public|protected|private|internal|abstract|static) )*(?interface|class|struct)"), "${category}", 0), 88 | // class GenericCollectionMethodsBase { 89 | // template class GenericCollectionMethodsBase { 90 | (new Regex(@"(?\r?\n)(?[ \t]*)(?class|struct) (?[a-zA-Z0-9]+)<(?[a-zA-Z0-9 ,]+)>(?[^{]+){"), "${before}${indent}template ${type} ${typeName};" + Environment.NewLine + "${indent}template ${type} ${typeName}<${typeParameters}>${typeDefinitionEnding}{", 0), 91 | // static void TestMultipleCreationsAndDeletions(SizedBinaryTreeMethodsBase tree, TElement* root) 92 | // template static void TestMultipleCreationsAndDeletions(SizedBinaryTreeMethodsBase tree, TElement* root) 93 | (new Regex(@"static ([a-zA-Z0-9]+) ([a-zA-Z0-9]+)<([a-zA-Z0-9]+)>\(([^\)\r\n]+)\)"), "template static $1 $2($4)", 0), 94 | // interface IFactory { 95 | // template class IFactory;\ntemplate class IFactory 96 | (new Regex(@"(?\r?\n)(?[ \t]*)interface (?[a-zA-Z0-9]+)<(?[a-zA-Z0-9 ,]+)>(?[^{]+){"), "${before}${indent}template class ${interface};" + Environment.NewLine + "${indent}template class ${interface}<${typeParameters}>${typeDefinitionEnding}{" + Environment.NewLine + " public:", 0), 97 | // template 98 | // template 99 | (new Regex(@"(?template <((, )?typename [a-zA-Z0-9]+)+, )(?[a-zA-Z0-9]+)(?(,|>))"), "${before}typename ${typeParameter}${after}", 10), 100 | // Insert markers 101 | // private: static void BuildExceptionString(this StringBuilder sb, Exception exception, int level) 102 | // /*~extensionMethod~BuildExceptionString~*/private: static void BuildExceptionString(this StringBuilder sb, Exception exception, int level) 103 | (new Regex(@"private: static [^\r\n]+ (?[a-zA-Z0-9]+)\(this [^\)\r\n]+\)"), "/*~extensionMethod~${name}~*/$0", 0), 104 | // Move all markers to the beginning of the file. 105 | (new Regex(@"\A(?[^\r\n]+\r?\n(.|\n)+)(?/\*~extensionMethod~(?[a-zA-Z0-9]+)~\*/)"), "${marker}${before}", 10), 106 | // /*~extensionMethod~BuildExceptionString~*/...sb.BuildExceptionString(exception.InnerException, level + 1); 107 | // /*~extensionMethod~BuildExceptionString~*/...BuildExceptionString(sb, exception.InnerException, level + 1); 108 | (new Regex(@"(?/\*~extensionMethod~(?[a-zA-Z0-9]+)~\*/(.|\n)+\W)(?[_a-zA-Z0-9]+)\.\k\("), "${before}${name}(${variable}, ", 50), 109 | // Remove markers 110 | // /*~extensionMethod~BuildExceptionString~*/ 111 | // 112 | (new Regex(@"/\*~extensionMethod~[a-zA-Z0-9]+~\*/"), "", 0), 113 | // (this 114 | // ( 115 | (new Regex(@"\(this "), "(", 0), 116 | // private: static readonly Disposal _emptyDelegate = (manual, wasDisposed) => { }; 117 | // private: inline static std::function _emptyDelegate = [](auto manual, auto wasDisposed) { }; 118 | (new Regex(@"(?(private|protected|public): )?static readonly (?[a-zA-Z][a-zA-Z0-9]*) (?[a-zA-Z_][a-zA-Z0-9_]*) = \((?[a-zA-Z_][a-zA-Z0-9_]*), (?[a-zA-Z_][a-zA-Z0-9_]*)\) => {\s*};"), "${access}inline static std::function<${type}> ${name} = [](auto ${firstArgument}, auto ${secondArgument}) { };", 0), 119 | // public: static readonly EnsureAlwaysExtensionRoot Always = new EnsureAlwaysExtensionRoot(); 120 | // public: inline static EnsureAlwaysExtensionRoot Always; 121 | (new Regex(@"(?(private|protected|public): )?static readonly (?[a-zA-Z0-9]+(<[a-zA-Z0-9]+>)?) (?[a-zA-Z0-9_]+) = new \k\(\);"), "${access}inline static ${type} ${name};", 0), 122 | // public: static readonly Range SByte = new Range(std::numeric_limits::min(), std::numeric_limits::max()); 123 | // public: inline static Range SByte = Range(std::numeric_limits::min(), std::numeric_limits::max()); 124 | (new Regex(@"(?(private|protected|public): )?static readonly (?[a-zA-Z0-9]+(<[a-zA-Z0-9]+>)?) (?[a-zA-Z0-9_]+) = new \k\((?[^\n]+)\);"), "${access}inline static ${type} ${name} = ${type}(${arguments});", 0), 125 | // public: static readonly string ExceptionContentsSeparator = "---"; 126 | // public: inline static std::string ExceptionContentsSeparator = "---"; 127 | (new Regex(@"(?(private|protected|public): )?(const|static readonly) string (?[a-zA-Z0-9_]+) = ""(?(\\""|[^""\r\n])+)"";"), "${access}inline static std::string ${name} = \"${string}\";", 0), 128 | // private: const int MaxPath = 92; 129 | // private: inline static const int MaxPath = 92; 130 | (new Regex(@"(?(private|protected|public): )?(const|static readonly) (?[a-zA-Z0-9]+) (?[_a-zA-Z0-9]+) = (?[^;\r\n]+);"), "${access}inline static const ${type} ${name} = ${value};", 0), 131 | // ArgumentNotNull(EnsureAlwaysExtensionRoot root, TArgument argument) where TArgument : class 132 | // ArgumentNotNull(EnsureAlwaysExtensionRoot root, TArgument* argument) 133 | (new Regex(@"(? [a-zA-Z]+\(([a-zA-Z *,]+, |))(?[a-zA-Z]+)(?(| [a-zA-Z *,]+)\))[ \r\n]+where \k : class"), "${before}${type}*${after}", 0), 134 | // protected: abstract TElement GetFirst(); 135 | // protected: virtual TElement GetFirst() = 0; 136 | (new Regex(@"(?(private|protected|public): )?abstract (?[^;\r\n]+);"), "${access}virtual ${method} = 0;", 0), 137 | // TElement GetFirst(); 138 | // virtual TElement GetFirst() = 0; 139 | (new Regex(@"(?[\r\n]+[ ]+)(?(?!return)[a-zA-Z0-9]+ [a-zA-Z0-9]+\([^\)\r\n]*\))(?;[ ]*[\r\n]+)"), "${before}virtual ${methodDeclaration} = 0${after}", 1), 140 | // protected: readonly TreeElement[] _elements; 141 | // protected: TreeElement _elements[N]; 142 | (new Regex(@"(?(private|protected|public): )?readonly (?[a-zA-Z<>0-9]+)([\[\]]+) (?[_a-zA-Z0-9]+);"), "${access}${type} ${name}[N];", 0), 143 | // protected: readonly TElement Zero; 144 | // protected: TElement Zero; 145 | (new Regex(@"(?(private|protected|public): )?readonly (?[a-zA-Z<>0-9]+) (?[_a-zA-Z0-9]+);"), "${access}${type} ${name};", 0), 146 | // internal 147 | // 148 | (new Regex(@"(\W)internal\s+"), "$1", 0), 149 | // static void NotImplementedException(ThrowExtensionRoot root) => throw new NotImplementedException(); 150 | // static void NotImplementedException(ThrowExtensionRoot root) { return throw new NotImplementedException(); } 151 | (new Regex(@"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?([a-zA-Z0-9]+ )([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+throw([^;\r\n]+);"), "$1$2$3$4$5$6$7$8($9) { throw$10; }", 0), 152 | // SizeBalancedTree(int capacity) => a = b; 153 | // SizeBalancedTree(int capacity) { a = b; } 154 | (new Regex(@"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?(void )?([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+([^;\r\n]+);"), "$1$2$3$4$5$6$7$8($9) { $10; }", 0), 155 | // int SizeBalancedTree(int capacity) => a; 156 | // int SizeBalancedTree(int capacity) { return a; } 157 | (new Regex(@"(^\s+)(private|protected|public)?(: )?(template \<[^>\r\n]+\> )?(static )?(override )?([a-zA-Z0-9]+ )([a-zA-Z0-9]+)\(([^\(\r\n]*)\)\s+=>\s+([^;\r\n]+);"), "$1$2$3$4$5$6$7$8($9) { return $10; }", 0), 158 | // OnDispose = (manual, wasDisposed) => 159 | // OnDispose = [&](auto manual, auto wasDisposed) 160 | (new Regex(@"(?[a-zA-Z_][a-zA-Z0-9_]*)(?\s*\+?=\s*)\((?[a-zA-Z_][a-zA-Z0-9_]*), (?[a-zA-Z_][a-zA-Z0-9_]*)\)\s*=>"), "${variable}${operator}[&](auto ${firstArgument}, auto ${secondArgument})", 0), 161 | // () => Integer.Zero, 162 | // () { return Integer.Zero; }, 163 | (new Regex(@"\(\)\s+=>\s+(?[^(),;\r\n]+(\(((?\()|(?<-parenthesis>\))|[^();\r\n]*?)*?\))?[^(),;\r\n]*)(?,|\);)"), "() { return ${expression}; }${after}", 0), 164 | // ~DisposableBase() => Destruct(); 165 | // ~DisposableBase() { Destruct(); } 166 | (new Regex(@"~(?[a-zA-Z_][a-zA-Z0-9_]*)\(\)\s+=>\s+([^;\r\n]+?);"), "~${class}() { $1; }", 0), 167 | // => Integer.Zero; 168 | // { return Integer.Zero; } 169 | (new Regex(@"\)\s+=>\s+([^;\r\n]+?);"), ") { return $1; }", 0), 170 | // () { return avlTree.Count; } 171 | // [&]()-> auto { return avlTree.Count; } 172 | (new Regex(@"(?, |\()\(\) { return (?[^;\r\n]+); }"), "${before}[&]()-> auto { return ${expression}; }", 0), 173 | // Count => GetSizeOrZero(Root); 174 | // Count() { return GetSizeOrZero(Root); } 175 | (new Regex(@"(\W)([A-Z][a-zA-Z]+)\s+=>\s+([^;\r\n]+);"), "$1$2() { return $3; }", 0), 176 | // Insert scope borders. 177 | // interface IDisposable { ... } 178 | // interface IDisposable {/*~start~interface~IDisposable~*/ ... /*~end~interface~IDisposable~*/} 179 | (new Regex(@"(?\r?\n(?[\t ]*)interface[\t ]*(?[a-zA-Z][a-zA-Z0-9]*(<[^<>\n]*>)?)[^{}]*{)(?(.|\n)*)(?(?<=\r?\n)\k)(?})"), "${classDeclarationBegin}/*~start~interface~${type}~*/${middle}${beforeEnd}/*~end~interface~${type}~*/${end}", 0), 180 | // Inside the scope replace: 181 | // /*~start~interface~IDisposable~*/ ... bool IsDisposed { get; } ... /*~end~interface~IDisposable~*/ 182 | // /*~start~interface~IDisposable~*/ ... virtual bool IsDisposed() = 0; /*~end~interface~IDisposable~*/ 183 | (new Regex(@"(?(?/\*~start~interface~(?[^~\n\*]+)~\*/)(.|\n)+?)(?(?(private|protected|public): )?(?[a-zA-Z_][a-zA-Z0-9_:<>]*) (?[a-zA-Z_][a-zA-Z0-9_]*)(?[\n\s]*{[\n\s]*)(\[[^\n]+\][\n\s]*)?get;(?[\n\s]*}))(?(.|\n)+?(?/\*~end~interface~\k~\*/))"), "${before}virtual ${propertyType} ${property}() = 0;${after}", 20), 184 | // Remove scope borders. 185 | // /*~start~interface~IDisposable~*/ 186 | // 187 | (new Regex(@"/\*~[^~\*\n]+(~[^~\*\n]+)*~\*/"), "", 0), 188 | // public: T Object { get; } 189 | // public: const T Object; 190 | (new Regex(@"(?[^\r]\r?\n[ \t]*)(?(private|protected|public): )?(?[a-zA-Z_][a-zA-Z0-9_:<>]*) (?[a-zA-Z_][a-zA-Z0-9_]*)(?[\n\s]*{[\n\s]*)(\[[^\n]+\][\n\s]*)?get;(?[\n\s]*})(?[\n\s]*)"), "${before}${access}const ${type} ${property};${after}", 2), 191 | // public: bool IsDisposed { get => _disposed > 0; } 192 | // public: bool IsDisposed() { return _disposed > 0; } 193 | (new Regex(@"(?[^\r]\r?\n[ \t]*)(?(private|protected|public): )?(?virtual )?bool (?[a-zA-Z_][a-zA-Z0-9_]*)(?[\n\s]*{[\n\s]*)(\[[^\n]+\][\n\s]*)?get\s*=>\s*(?[^\n]+);(?[\n\s]*}[\n\s]*)"), "${before}${access}${virtual}bool ${property}()${blockOpen}return ${expression};${blockClose}", 2), 194 | // protected: virtual std::string ObjectName { get => GetType().Name; } 195 | // protected: virtual std::string ObjectName() { return GetType().Name; } 196 | (new Regex(@"(?[^\r]\r?\n[ \t]*)(?(private|protected|public): )?(?virtual )?(?[a-zA-Z_][a-zA-Z0-9_:<>]*) (?[a-zA-Z_][a-zA-Z0-9_]*)(?[\n\s]*{[\n\s]*)(\[[^\n]+\][\n\s]*)?get\s*=>\s*(?[^\n]+);(?[\n\s]*}[\n\s]*)"), "${before}${access}${virtual}${type} ${property}()${blockOpen}return ${expression};${blockClose}", 2), 197 | // ArgumentInRange(string message) { string messageBuilder() { return message; } 198 | // ArgumentInRange(string message) { auto messageBuilder = [&]() -> string { return message; }; 199 | (new Regex(@"(?\W[_a-zA-Z0-9]+\([^\)\n]*\)[\s\n]*{[\s\n]*([^{}]|\n)*?(\r?\n)?[ \t]*)(?[_a-zA-Z0-9*:]+[_a-zA-Z0-9*: ]*) (?[_a-zA-Z0-9]+)\((?[^\)\n]*)\)\s*{(?(""[^""\n]+""|[^}]|\n)+?)}"), "${before}auto ${methodName} = [&]() -> ${returnType} {${body}};", 10), 200 | // Func treeCount 201 | // std::function treeCount 202 | (new Regex(@"Func<([a-zA-Z0-9]+)> ([a-zA-Z0-9]+)"), "std::function<$1()> $2", 0), 203 | // Action free 204 | // std::function free 205 | (new Regex(@"Action(<(?[a-zA-Z0-9]+(, ([a-zA-Z0-9]+))*)>)?(?>| (?[a-zA-Z0-9]+))"), "std::function${after}", 0), 206 | // Predicate predicate 207 | // std::function predicate 208 | (new Regex(@"Predicate<([a-zA-Z0-9]+)> ([a-zA-Z0-9]+)"), "std::function $2", 0), 209 | // var 210 | // auto 211 | (new Regex(@"(\W)var(\W)"), "$1auto$2", 0), 212 | // unchecked 213 | // 214 | (new Regex(@"[\r\n]{2}\s*?unchecked\s*?$"), "", 0), 215 | // throw new 216 | // throw 217 | (new Regex(@"(\W)throw new(\W)"), "$1throw$2", 0), 218 | // void RaiseExceptionIgnoredEvent(Exception exception) 219 | // void RaiseExceptionIgnoredEvent(const std::exception& exception) 220 | (new Regex(@"(\(|, )(System\.Exception|Exception)( |\))"), "$1const std::exception&$3", 0), 221 | // EventHandler 222 | // EventHandler 223 | (new Regex(@"(\W)(System\.Exception|Exception)(\W)"), "$1std::exception$3", 0), 224 | // override void PrintNode(TElement node, StringBuilder sb, int level) 225 | // void PrintNode(TElement node, StringBuilder sb, int level) override 226 | (new Regex(@"override ([a-zA-Z0-9 \*\+]+)(\([^\)\r\n]+?\))"), "$1$2 override", 0), 227 | // return (range.Minimum, range.Maximum) 228 | // return {range.Minimum, range.Maximum} 229 | (new Regex(@"(?return\s*)\((?[^\)\n]+)\)(?!\()(?\W)"), "${before}{${values}}${after}", 0), 230 | // string 231 | // std::string 232 | (new Regex(@"(?\W)(?\W)"), "${before}std::string${after}", 0), 233 | // System.ValueTuple 234 | // std::tuple 235 | (new Regex(@"(?\W)(System\.)?ValueTuple(?!\s*=|\()(?\W)"), "${before}std::tuple${after}", 0), 236 | // sbyte 237 | // std::int8_t 238 | (new Regex(@"(?\W)((System\.)?SB|sb)yte(?!\s*=|\()(?\W)"), "${before}std::int8_t${after}", 0), 239 | // short 240 | // std::int16_t 241 | (new Regex(@"(?\W)((System\.)?Int16|short)(?!\s*=|\()(?\W)"), "${before}std::int16_t${after}", 0), 242 | // int 243 | // std::int32_t 244 | (new Regex(@"(?\W)((System\.)?I|i)nt(32)?(?!\s*=|\()(?\W)"), "${before}std::int32_t${after}", 0), 245 | // long 246 | // std::int64_t 247 | (new Regex(@"(?\W)((System\.)?Int64|long)(?!\s*=|\()(?\W)"), "${before}std::int64_t${after}", 0), 248 | // byte 249 | // std::uint8_t 250 | (new Regex(@"(?\W)((System\.)?Byte|byte)(?!\s*=|\()(?\W)"), "${before}std::uint8_t${after}", 0), 251 | // ushort 252 | // std::uint16_t 253 | (new Regex(@"(?\W)((System\.)?UInt16|ushort)(?!\s*=|\()(?\W)"), "${before}std::uint16_t${after}", 0), 254 | // uint 255 | // std::uint32_t 256 | (new Regex(@"(?\W)((System\.)?UI|ui)nt(32)?(?!\s*=|\()(?\W)"), "${before}std::uint32_t${after}", 0), 257 | // ulong 258 | // std::uint64_t 259 | (new Regex(@"(?\W)((System\.)?UInt64|ulong)(?!\s*=|\()(?\W)"), "${before}std::uint64_t${after}", 0), 260 | // char*[] args 261 | // char* args[] 262 | (new Regex(@"([_a-zA-Z0-9:\*]?)\[\] ([a-zA-Z0-9]+)"), "$1 $2[]", 0), 263 | // float.MinValue 264 | // std::numeric_limits::lowest() 265 | (new Regex(@"(?\W)(?std::[a-z0-9_]+|float|double)\.MinValue(?\W)"), "${before}std::numeric_limits<${type}>::lowest()${after}", 0), 266 | // double.MaxValue 267 | // std::numeric_limits::max() 268 | (new Regex(@"(?\W)(?std::[a-z0-9_]+|float|double)\.MaxValue(?\W)"), "${before}std::numeric_limits<${type}>::max()${after}", 0), 269 | // using Platform.Numbers; 270 | // 271 | (new Regex(@"([\r\n]{2}|^)\s*?using [\.a-zA-Z0-9]+;\s*?$"), "", 0), 272 | // class SizedBinaryTreeMethodsBase : GenericCollectionMethodsBase 273 | // class SizedBinaryTreeMethodsBase : public GenericCollectionMethodsBase 274 | (new Regex(@"(struct|class) ([a-zA-Z0-9]+)(<[a-zA-Z0-9 ,]+>)? : ([a-zA-Z0-9]+)"), "$1 $2$3 : public $4", 0), 275 | // System.IDisposable 276 | // System::IDisposable 277 | (new Regex(@"(?System(::[a-zA-Z_]\w*)*)\.(?[a-zA-Z_]\w*)"), "${before}::${after}", 20), 278 | // class IProperty : ISetter, IProvider 279 | // class IProperty : public ISetter, public IProvider 280 | (new Regex(@"(?(interface|struct|class) [a-zA-Z_]\w* : ((public [a-zA-Z_][\w:]*(<[a-zA-Z0-9 ,]+>)?, )+)?)(?(?!public)[a-zA-Z_][\w:]*(<[a-zA-Z0-9 ,]+>)?)(?(, [a-zA-Z_][\w:]*(?!>)|[ \r\n]+))"), "${before}public ${inheritedType}${after}", 10), 281 | // interface IDisposable { 282 | // class IDisposable { public: 283 | (new Regex(@"(?\r?\n)(?[ \t]*)interface (?[a-zA-Z_]\w*)(?[^{]+){"), "${before}${indent}class ${interface}${typeDefinitionEnding}{" + Environment.NewLine + " public:", 0), 284 | // struct TreeElement { } 285 | // struct TreeElement { }; 286 | (new Regex(@"(struct|class) ([a-zA-Z0-9]+)(\s+){([\sa-zA-Z0-9;:_]+?)}([^;])"), "$1 $2$3{$4};$5", 0), 287 | // class Program { } 288 | // class Program { }; 289 | (new Regex(@"(?struct|class) (?[a-zA-Z0-9]+[^\r\n]*)(?[\r\n]+(?[\t ]*)?)\{(?[\S\s]+?[\r\n]+\k)\}(?[^;]|$)"), "${type} ${name}${beforeBody}{${body}};${afterBody}", 0), 290 | // Insert scope borders. 291 | // ref TElement root 292 | // ~!root!~ref TElement root 293 | (new Regex(@"(?(?<= |\()(ref [a-zA-Z0-9]+|[a-zA-Z0-9]+(?[a-zA-Z0-9]+)(?=\)|, | =))"), "~!${variable}!~${definition}", 0), 294 | // Inside the scope of ~!root!~ replace: 295 | // root 296 | // *root 297 | (new Regex(@"(?~!(?[a-zA-Z0-9]+)!~ref [a-zA-Z0-9]+ \k(?=\)|, | =))(?((?!~)(.|\n))*?)(?(\W |\())\k(?( |\)|;|,))"), "${definition}${before}${prefix}*${pointer}${suffix}", 70), 298 | // Remove scope borders. 299 | // ~!root!~ 300 | // 301 | (new Regex(@"~!(?[a-zA-Z0-9]+)!~"), "", 5), 302 | // ref auto root = ref 303 | // ref auto root = 304 | (new Regex(@"ref ([a-zA-Z0-9]+) ([a-zA-Z0-9]+) = ref(\W)"), "$1* $2 =$3", 0), 305 | // *root = ref left; 306 | // root = left; 307 | (new Regex(@"\*([a-zA-Z0-9]+) = ref ([a-zA-Z0-9]+)(\W)"), "$1 = $2$3", 0), 308 | // (ref left) 309 | // (left) 310 | (new Regex(@"\(ref ([a-zA-Z0-9]+)(\)|\(|,)"), "($1$2", 0), 311 | // ref TElement 312 | // TElement* 313 | (new Regex(@"( |\()ref ([a-zA-Z0-9]+) "), "$1$2* ", 0), 314 | // ref sizeBalancedTree.Root 315 | // &sizeBalancedTree->Root 316 | (new Regex(@"ref ([a-zA-Z0-9]+)\.([a-zA-Z0-9\*]+)"), "&$1->$2", 0), 317 | // ref GetElement(node).Right 318 | // &GetElement(node)->Right 319 | (new Regex(@"ref ([a-zA-Z0-9]+)\(([a-zA-Z0-9\*]+)\)\.([a-zA-Z0-9]+)"), "&$1($2)->$3", 0), 320 | // GetElement(node).Right 321 | // GetElement(node)->Right 322 | (new Regex(@"([a-zA-Z0-9]+)\(([a-zA-Z0-9\*]+)\)\.([a-zA-Z0-9]+)"), "$1($2)->$3", 0), 323 | // [Fact]\npublic: static void SizeBalancedTreeMultipleAttachAndDetachTest() 324 | // public: TEST_METHOD(SizeBalancedTreeMultipleAttachAndDetachTest) 325 | (new Regex(@"\[Fact\][\s\n]+(public: )?(static )?void ([a-zA-Z0-9]+)\(\)"), "public: TEST_METHOD($3)", 0), 326 | // class TreesTests 327 | // TEST_CLASS(TreesTests) 328 | (new Regex(@"class ([a-zA-Z0-9]+Tests)"), "TEST_CLASS($1)", 0), 329 | // Assert.Equal 330 | // Assert::AreEqual 331 | (new Regex(@"(?Assert)\.(?(Not)?Equal)"), "${type}::Are${method}", 0), 332 | // Assert.Throws 333 | // Assert::ExpectException 334 | (new Regex(@"(Assert)\.Throws"), "$1::ExpectException", 0), 335 | // Assert.True 336 | // Assert::IsTrue 337 | (new Regex(@"(Assert)\.(True|False)"), "$1::Is$2", 0), 338 | // $"Argument {argumentName} is null." 339 | // std::string("Argument ").append(Platform::Converters::To(argumentName)).append(" is null.") 340 | (new Regex(@"\$""(?(\\""|[^""\r\n])*){(?[_a-zA-Z0-9]+)}(?(\\""|[^""\r\n])*)"""), "std::string($\"${left}\").append(Platform::Converters::To(${expression})).append(\"${right}\")", 10), 341 | // $" 342 | // " 343 | (new Regex(@"\$"""), "\"", 0), 344 | // std::string(std::string("[").append(Platform::Converters::To(Minimum)).append(", ")).append(Platform::Converters::To(Maximum)).append("]") 345 | // std::string("[").append(Platform::Converters::To(Minimum)).append(", ").append(Platform::Converters::To(Maximum)).append("]") 346 | (new Regex(@"std::string\((?std::string\(""(\\""|[^""])*""\)(\.append\((Platform::Converters::To\([^)\n]+\)|[^)\n]+)\))+)\)\.append"), "${begin}.append", 10), 347 | // Console.WriteLine("...") 348 | // printf("...\n") 349 | (new Regex(@"Console\.WriteLine\(""([^""\r\n]+)""\)"), "printf(\"$1\\n\")", 0), 350 | // TElement Root; 351 | // TElement Root = 0; 352 | (new Regex(@"(?\r?\n[\t ]+)(?(private|protected|public)(: )?)?(?[a-zA-Z0-9:_]+(?[_a-zA-Z0-9]+);"), "${before}${access}${type} ${name} = 0;", 0), 353 | // TreeElement _elements[N]; 354 | // TreeElement _elements[N] = { {0} }; 355 | (new Regex(@"(\r?\n[\t ]+)(private|protected|public)?(: )?([a-zA-Z0-9]+) ([_a-zA-Z0-9]+)\[([_a-zA-Z0-9]+)\];"), "$1$2$3$4 $5[$6] = { {0} };", 0), 356 | // auto path = new TElement[MaxPath]; 357 | // TElement path[MaxPath] = { {0} }; 358 | (new Regex(@"(\r?\n[\t ]+)[a-zA-Z0-9]+ ([a-zA-Z0-9]+) = new ([a-zA-Z0-9]+)\[([_a-zA-Z0-9]+)\];"), "$1$3 $2[$4] = { {0} };", 0), 359 | // bool Equals(Range other) { ... } 360 | // bool operator ==(const Key &other) const { ... } 361 | (new Regex(@"(?\r?\n[^\n]+bool )Equals\((?[^\n{]+) (?[a-zA-Z0-9]+)\)(?(\s|\n)*{)"), "${before}operator ==(const ${type} &${variable}) const${after}", 0), 362 | // Insert scope borders. 363 | // class Range { ... public: override std::string ToString() { return ...; } 364 | // class Range {/*~Range~*/ ... public: override std::string ToString() { return ...; } 365 | (new Regex(@"(?\r?\n(?[\t ]*)template [^<>\n]+)> (struct|class) (?[a-zA-Z0-9]+<\k>)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)(?((?!class|struct).|\n)+?)(?(?(private|protected|public): )override std::string ToString\(\))"), "${classDeclarationBegin}/*~${type}~*/${middle}${toStringDeclaration}", 0), 366 | // Inside the scope of ~!Range!~ replace: 367 | // public: override std::string ToString() { return ...; } 368 | // public: operator std::string() const { return ...; }\n\npublic: friend std::ostream & operator <<(std::ostream &out, const A &obj) { return out << (std::string)obj; } 369 | (new Regex(@"(?/\*~(?[_a-zA-Z0-9<>:]+)~\*/)(?.|\n)(?((?~\*/)(.|\n))*?)(?\r?\n(?[ \t]*)(?(private|protected|public): )override std::string ToString\(\) (?{[^}\n]+}))"), "${scope}${separator}${before}" + Environment.NewLine + "${indent}${access}operator std::string() const ${toStringMethodBody}" + Environment.NewLine + Environment.NewLine + "${indent}${access}friend std::ostream & operator <<(std::ostream &out, const ${type} &obj) { return out << (std::string)obj; }", 0), 370 | // Remove scope borders. 371 | // /*~Range~*/ 372 | // 373 | (new Regex(@"/\*~[_a-zA-Z0-9<>:]+~\*/"), "", 0), 374 | // private: inline static ConcurrentBag _exceptionsBag; 375 | // private: inline static std::mutex _exceptionsBag_mutex; \n\n private: inline static std::vector _exceptionsBag; 376 | (new Regex(@"(?\r?\n?(?[ \t]+))(?(private|protected|public): )?inline static ConcurrentBag<(?[^;\r\n]+)> (?[_a-zA-Z0-9]+);"), "${begin}private: inline static std::mutex ${name}_mutex;" + Environment.NewLine + Environment.NewLine + "${indent}${access}inline static std::vector<${argumentType}> ${name};", 0), 377 | // public: static IReadOnlyCollection GetCollectedExceptions() { return _exceptionsBag; } 378 | // public: static std::vector GetCollectedExceptions() { return std::vector(_exceptionsBag); } 379 | (new Regex(@"(?(private|protected|public): )?static IReadOnlyCollection<(?[^;\r\n]+)> (?[_a-zA-Z0-9]+)\(\) { return (?[_a-zA-Z0-9]+); }"), "${access}static std::vector<${argumentType}> ${methodName}() { return std::vector<${argumentType}>(${fieldName}); }", 0), 380 | // public: static event EventHandler ExceptionIgnored = OnExceptionIgnored; ... }; 381 | // ... public: static inline Platform::Delegates::MulticastDelegate ExceptionIgnored = OnExceptionIgnored; }; 382 | (new Regex(@"(?\r?\n(\r?\n)?(?[ \t]+)\k)(?(private|protected|public): )?static event EventHandler<(?[^;\r\n]+)> (?[_a-zA-Z0-9]+) = (?[_a-zA-Z0-9]+);(?(.|\n)+?)(?\r?\n\k};)"), "${middle}" + Environment.NewLine + Environment.NewLine + "${halfIndent}${halfIndent}${access}static inline Platform::Delegates::MulticastDelegate ${name} = ${defaultDelegate};${end}", 0), 383 | // public: event Disposal OnDispose; 384 | // public: Platform::Delegates::MulticastDelegate OnDispose; 385 | (new Regex(@"(?(?(private|protected|public): )?(static )?)event (?[a-zA-Z][:_a-zA-Z0-9]+) (?[a-zA-Z][_a-zA-Z0-9]+);"), "${begin}Platform::Delegates::MulticastDelegate<${type}> ${name};", 0), 386 | // Insert scope borders. 387 | // class IgnoredExceptions { ... private: inline static std::vector _exceptionsBag; 388 | // class IgnoredExceptions {/*~_exceptionsBag~*/ ... private: inline static std::vector _exceptionsBag; 389 | (new Regex(@"(?\r?\n(?[\t ]*)class [^{\r\n]+\r\n[\t ]*{)(?((?!class).|\n)+?)(?(?(private|protected|public): )inline static std::vector<(?[^;\r\n]+)> (?[_a-zA-Z0-9]+);)"), "${classDeclarationBegin}/*~${fieldName}~*/${middle}${vectorFieldDeclaration}", 0), 390 | // Inside the scope of ~!_exceptionsBag!~ replace: 391 | // _exceptionsBag.Add(exception); 392 | // _exceptionsBag.push_back(exception); 393 | (new Regex(@"(?/\*~(?[_a-zA-Z0-9]+)~\*/)(?.|\n)(?((?~\*/)(.|\n))*?)\k\.Add"), "${scope}${separator}${before}${fieldName}.push_back", 10), 394 | // Remove scope borders. 395 | // /*~_exceptionsBag~*/ 396 | // 397 | (new Regex(@"/\*~[_a-zA-Z0-9]+~\*/"), "", 0), 398 | // Insert scope borders. 399 | // class IgnoredExceptions { ... private: static std::mutex _exceptionsBag_mutex; 400 | // class IgnoredExceptions {/*~_exceptionsBag~*/ ... private: static std::mutex _exceptionsBag_mutex; 401 | (new Regex(@"(?\r?\n(?[\t ]*)class [^{\r\n]+\r\n[\t ]*{)(?((?!class).|\n)+?)(?private: inline static std::mutex (?[_a-zA-Z0-9]+)_mutex;)"), "${classDeclarationBegin}/*~${fieldName}~*/${middle}${mutexDeclaration}", 0), 402 | // Inside the scope of ~!_exceptionsBag!~ replace: 403 | // return std::vector(_exceptionsBag); 404 | // std::lock_guard guard(_exceptionsBag_mutex); return std::vector(_exceptionsBag); 405 | (new Regex(@"(?/\*~(?[_a-zA-Z0-9]+)~\*/)(?.|\n)(?((?~\*/)(.|\n))*?){(?((?!lock_guard)[^{};\r\n])*\k[^;}\r\n]*;)"), "${scope}${separator}${before}{ std::lock_guard guard(${fieldName}_mutex);${after}", 10), 406 | // Inside the scope of ~!_exceptionsBag!~ replace: 407 | // _exceptionsBag.Add(exception); 408 | // std::lock_guard guard(_exceptionsBag_mutex); \r\n _exceptionsBag.Add(exception); 409 | (new Regex(@"(?/\*~(?[_a-zA-Z0-9]+)~\*/)(?.|\n)(?((?~\*/)(.|\n))*?){(?((?!lock_guard)([^{};]|\n))*?\r?\n(?[ \t]*)\k[^;}\r\n]*;)"), "${scope}${separator}${before}{" + Environment.NewLine + "${indent}std::lock_guard guard(${fieldName}_mutex);${after}", 10), 410 | // Remove scope borders. 411 | // /*~_exceptionsBag~*/ 412 | // 413 | (new Regex(@"/\*~[_a-zA-Z0-9]+~\*/"), "", 0), 414 | // Insert scope borders. 415 | // class IgnoredExceptions { ... public: static inline Platform::Delegates::MulticastDelegate ExceptionIgnored = OnExceptionIgnored; 416 | // class IgnoredExceptions {/*~ExceptionIgnored~*/ ... public: static inline Platform::Delegates::MulticastDelegate ExceptionIgnored = OnExceptionIgnored; 417 | (new Regex(@"(?\r?\n(?[\t ]*)class [^{\r\n]+\r\n[\t ]*{)(?((?!class).|\n)+?)(?(?(private|protected|public): )static inline Platform::Delegates::MulticastDelegate<(?[^;\r\n]+)> (?[_a-zA-Z0-9]+) = (?[_a-zA-Z0-9]+);)"), "${classDeclarationBegin}/*~${name}~*/${middle}${eventDeclaration}", 0), 418 | // Inside the scope of ~!ExceptionIgnored!~ replace: 419 | // ExceptionIgnored.Invoke(NULL, exception); 420 | // ExceptionIgnored(NULL, exception); 421 | (new Regex(@"(?/\*~(?[a-zA-Z0-9]+)~\*/)(?.|\n)(?((?~\*/)(.|\n))*?)\k\.Invoke"), "${scope}${separator}${before}${eventName}", 10), 422 | // Remove scope borders. 423 | // /*~ExceptionIgnored~*/ 424 | // 425 | (new Regex(@"/\*~[a-zA-Z0-9]+~\*/"), "", 0), 426 | // Insert scope borders. 427 | // auto added = new StringBuilder(); 428 | // /*~sb~*/std::string added; 429 | (new Regex(@"(auto|(System\.Text\.)?StringBuilder) (?[a-zA-Z0-9]+) = new (System\.Text\.)?StringBuilder\(\);"), "/*~${variable}~*/std::string ${variable};", 0), 430 | // static void Indent(StringBuilder sb, int level) 431 | // static void Indent(/*~sb~*/StringBuilder sb, int level) 432 | (new Regex(@"(?, |\()(System\.Text\.)?StringBuilder (?[a-zA-Z0-9]+)(?,|\))"), "${start}/*~${variable}~*/std::string& ${variable}${end}", 0), 433 | // Inside the scope of ~!added!~ replace: 434 | // sb.ToString() 435 | // sb 436 | (new Regex(@"(?/\*~(?[a-zA-Z0-9]+)~\*/)(?.|\n)(?((?~\*/)(.|\n))*?)\k\.ToString\(\)"), "${scope}${separator}${before}${variable}", 10), 437 | // sb.AppendLine(argument) 438 | // sb.append(Platform::Converters::To(argument)).append(1, '\n') 439 | (new Regex(@"(?/\*~(?[a-zA-Z0-9]+)~\*/)(?.|\n)(?((?~\*/)(.|\n))*?)\k\.AppendLine\((?[^\),\r\n]+)\)"), "${scope}${separator}${before}${variable}.append(Platform::Converters::To(${argument})).append(1, '\\n')", 10), 440 | // sb.Append('\t', level); 441 | // sb.append(level, '\t'); 442 | (new Regex(@"(?/\*~(?[a-zA-Z0-9]+)~\*/)(?.|\n)(?((?~\*/)(.|\n))*?)\k\.Append\('(?[^'\r\n]+)', (?[^\),\r\n]+)\)"), "${scope}${separator}${before}${variable}.append(${count}, '${character}')", 10), 443 | // sb.Append(argument) 444 | // sb.append(Platform::Converters::To(argument)) 445 | (new Regex(@"(?/\*~(?[a-zA-Z0-9]+)~\*/)(?.|\n)(?((?~\*/)(.|\n))*?)\k\.Append\((?[^\),\r\n]+)\)"), "${scope}${separator}${before}${variable}.append(Platform::Converters::To(${argument}))", 10), 446 | // Remove scope borders. 447 | // /*~sb~*/ 448 | // 449 | (new Regex(@"/\*~[a-zA-Z0-9]+~\*/"), "", 0), 450 | // Insert scope borders. 451 | // auto added = new HashSet(); 452 | // ~!added!~std::unordered_set added; 453 | (new Regex(@"auto (?[a-zA-Z0-9]+) = new HashSet<(?[a-zA-Z0-9]+)>\(\);"), "~!${variable}!~std::unordered_set<${element}> ${variable};", 0), 454 | // Inside the scope of ~!added!~ replace: 455 | // added.Add(node) 456 | // added.insert(node) 457 | (new Regex(@"(?~!(?[a-zA-Z0-9]+)!~)(?.|\n)(?((?!~)(.|\n))*?)\k\.Add\((?[a-zA-Z0-9]+)\)"), "${scope}${separator}${before}${variable}.insert(${argument})", 10), 458 | // Inside the scope of ~!added!~ replace: 459 | // added.Remove(node) 460 | // added.erase(node) 461 | (new Regex(@"(?~!(?[a-zA-Z0-9]+)!~)(?.|\n)(?((?!~)(.|\n))*?)\k\.Remove\((?[a-zA-Z0-9]+)\)"), "${scope}${separator}${before}${variable}.erase(${argument})", 10), 462 | // if (added.insert(node)) { 463 | // if (!added.contains(node)) { added.insert(node); 464 | (new Regex(@"if \((?[a-zA-Z0-9]+)\.insert\((?[a-zA-Z0-9]+)\)\)(?[\t ]*[\r\n]+)(?[\t ]*){"), "if (!${variable}.contains(${argument}))${separator}${indent}{" + Environment.NewLine + "${indent} ${variable}.insert(${argument});", 0), 465 | // Remove scope borders. 466 | // ~!added!~ 467 | // 468 | (new Regex(@"~![a-zA-Z0-9]+!~"), "", 5), 469 | // Insert scope borders. 470 | // auto random = new System::Random(0); 471 | // std::srand(0); 472 | (new Regex(@"[a-zA-Z0-9\.]+ ([a-zA-Z0-9]+) = new (System::)?Random\(([a-zA-Z0-9]+)\);"), "~!$1!~std::srand($3);", 0), 473 | // Inside the scope of ~!random!~ replace: 474 | // random.Next(1, N) 475 | // (std::rand() % N) + 1 476 | (new Regex(@"(?~!(?[a-zA-Z0-9]+)!~)(?.|\n)(?((?!~)(.|\n))*?)\k\.Next\((?[a-zA-Z0-9]+), (?[a-zA-Z0-9]+)\)"), "${scope}${separator}${before}(std::rand() % ${to}) + ${from}", 10), 477 | // Remove scope borders. 478 | // ~!random!~ 479 | // 480 | (new Regex(@"~![a-zA-Z0-9]+!~"), "", 5), 481 | // Insert method body scope starts. 482 | // void PrintNodes(TElement node, StringBuilder sb, int level) { 483 | // void PrintNodes(TElement node, StringBuilder sb, int level) {/*method-start*/ 484 | (new Regex(@"(?\r?\n[\t ]+)(?((private|protected|public): )?(virtual )?[a-zA-Z0-9:_]+ )?(?[a-zA-Z][a-zA-Z0-9]*)\((?[^\)]*)\)(?( override)?)(?[ \t\r\n]*)\{(?[^~])"), "${start}${prefix}${method}(${arguments})${override}${separator}{/*method-start*/${end}", 0), 485 | // Insert method body scope ends. 486 | // {/*method-start*/...} 487 | // {/*method-start*/.../*method-end*/} 488 | (new Regex(@"\{/\*method-start\*/(?((?\{)|(?<-bracket>\})|[^\{\}]*)+)\}"), "{/*method-start*/${body}/*method-end*/}", 0), 489 | // Inside method bodies replace: 490 | // GetFirst( 491 | // this->GetFirst( 492 | (new Regex(@"(?/\*method-start\*/)(?((?[\W](?|throw\s+)))(?(?!sizeof)[a-zA-Z0-9]+)\((?!\) \{)(?(.|\n)*?)(?/\*method-end\*/)"), "${scope}${before}${separator}this->${method}(${after}${scopeEnd}", 100), 493 | // Remove scope borders. 494 | // /*method-start*/ 495 | // 496 | (new Regex(@"/\*method-(start|end)\*/"), "", 0), 497 | // Insert scope borders. 498 | // const std::exception& ex 499 | // const std::exception& ex/*~ex~*/ 500 | (new Regex(@"(?\(| )(?(const )?(std::)?exception&? (?[_a-zA-Z0-9]+))(?\W)"), "${before}${variableDefinition}/*~${variable}~*/${after}", 0), 501 | // Inside the scope of ~!ex!~ replace: 502 | // ex.Message 503 | // ex.what() 504 | (new Regex(@"(?/\*~(?[_a-zA-Z0-9]+)~\*/)(?.|\n)(?((?~\*/)(.|\n))*?)(Platform::Converters::To\(\k\.Message\)|\k\.Message)"), "${scope}${separator}${before}${variable}.what()", 10), 505 | // Remove scope borders. 506 | // /*~ex~*/ 507 | // 508 | (new Regex(@"/\*~[_a-zA-Z0-9]+~\*/"), "", 0), 509 | // throw ObjectDisposedException(objectName, message); 510 | // throw std::runtime_error(std::string("Attempt to access disposed object [").append(objectName).append("]: ").append(message).append(".")); 511 | (new Regex(@"throw ObjectDisposedException\((?[a-zA-Z_][a-zA-Z0-9_]*), (?[a-zA-Z0-9_]*[Mm]essage[a-zA-Z0-9_]*(\(\))?|[a-zA-Z_][a-zA-Z0-9_]*)\);"), "throw std::runtime_error(std::string(\"Attempt to access disposed object [\").append(${objectName}).append(\"]: \").append(${message}).append(\".\"));", 0), 512 | // throw ArgumentNullException(argumentName, message); 513 | // throw std::invalid_argument(std::string("Argument ").append(argumentName).append(" is null: ").append(message).append(".")); 514 | (new Regex(@"throw ArgumentNullException\((?[a-zA-Z]*[Aa]rgument[a-zA-Z]*), (?[a-zA-Z]*[Mm]essage[a-zA-Z]*(\(\))?)\);"), "throw std::invalid_argument(std::string(\"Argument \").append(${argument}).append(\" is null: \").append(${message}).append(\".\"));", 0), 515 | // throw ArgumentException(message, argumentName); 516 | // throw std::invalid_argument(std::string("Invalid ").append(argumentName).append(" argument: ").append(message).append(".")); 517 | (new Regex(@"throw ArgumentException\((?[a-zA-Z]*[Mm]essage[a-zA-Z]*(\(\))?), (?[a-zA-Z]*[Aa]rgument[a-zA-Z]*)\);"), "throw std::invalid_argument(std::string(\"Invalid \").append(${argument}).append(\" argument: \").append(${message}).append(\".\"));", 0), 518 | // throw ArgumentOutOfRangeException(argumentName, argumentValue, messageBuilder()); 519 | // throw std::invalid_argument(std::string("Value [").append(Platform::Converters::To(argumentValue)).append("] of argument [").append(argumentName).append("] is out of range: ").append(messageBuilder()).append(".")); 520 | (new Regex(@"throw ArgumentOutOfRangeException\((?[a-zA-Z]*[Aa]rgument[a-zA-Z]*([Nn]ame[a-zA-Z]*)?), (?[a-zA-Z]*[Aa]rgument[a-zA-Z]*([Vv]alue[a-zA-Z]*)?), (?[a-zA-Z]*[Mm]essage[a-zA-Z]*(\(\))?)\);"), "throw std::invalid_argument(std::string(\"Value [\").append(Platform::Converters::To(${argumentValue})).append(\"] of argument [\").append(${argument}).append(\"] is out of range: \").append(${message}).append(\".\"));", 0), 521 | // throw NotSupportedException(); 522 | // throw std::logic_error("Not supported exception."); 523 | (new Regex(@"throw NotSupportedException\(\);"), "throw std::logic_error(\"Not supported exception.\");", 0), 524 | // throw NotImplementedException(); 525 | // throw std::logic_error("Not implemented exception."); 526 | (new Regex(@"throw NotImplementedException\(\);"), "throw std::logic_error(\"Not implemented exception.\");", 0), 527 | // Insert scope borders. 528 | // const std::string& message 529 | // const std::string& message/*~message~*/ 530 | (new Regex(@"(?\(| )(?(const )?((std::)?string&?|char\*) (?[_a-zA-Z0-9]+))(?\W)"), "${before}${variableDefinition}/*~${variable}~*/${after}", 0), 531 | // Inside the scope of /*~message~*/ replace: 532 | // Platform::Converters::To(message) 533 | // message 534 | (new Regex(@"(?/\*~(?[_a-zA-Z0-9]+)~\*/)(?.|\n)(?((?~\*/)(.|\n))*?)Platform::Converters::To\(\k\)"), "${scope}${separator}${before}${variable}", 10), 535 | // Remove scope borders. 536 | // /*~ex~*/ 537 | // 538 | (new Regex(@"/\*~[_a-zA-Z0-9]+~\*/"), "", 0), 539 | // Insert scope borders. 540 | // std::tuple tuple 541 | // std::tuple tuple/*~tuple~*/ 542 | (new Regex(@"(?\(| )(?(const )?(std::)?tuple<[^\n]+>&? (?[_a-zA-Z0-9]+))(?\W)"), "${before}${variableDefinition}/*~${variable}~*/${after}", 0), 543 | // Inside the scope of ~!ex!~ replace: 544 | // tuple.Item1 545 | // std::get<1-1>(tuple) 546 | (new Regex(@"(?/\*~(?[_a-zA-Z0-9]+)~\*/)(?.|\n)(?((?~\*/)(.|\n))*?)\k\.Item(?\d+)(?\W)"), "${scope}${separator}${before}std::get<${itemNumber}-1>(${variable})${after}", 10), 547 | // Remove scope borders. 548 | // /*~ex~*/ 549 | // 550 | (new Regex(@"/\*~[_a-zA-Z0-9]+~\*/"), "", 0), 551 | // Insert scope borders. 552 | // class Range { 553 | // class Range {/*~type~Range~*/ 554 | (new Regex(@"(?\r?\n(?[\t ]*)(template\s*<[^<>\n]*> )?(struct|class) (?(?[a-zA-Z0-9]+)(<[^:\n]*>)?)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)"), "${classDeclarationBegin}/*~type~${typeName}~${fullType}~*/", 0), 555 | // Inside the scope of /*~type~Range~*/ insert inner scope and replace: 556 | // public: static implicit operator std::tuple(Range range) 557 | // public: operator std::tuple() const {/*~variable~Range~*/ 558 | (new Regex(@"(?/\*~type~(?[^~\n\*]+)~(?[^~\n\*]+)~\*/)(?.|\n)(?((?~\k~\*/)(.|\n))*?)(?(private|protected|public): )static implicit operator (?[^\(\n]+)\((?\k (?[a-zA-Z0-9]+))\)(?\s*\n?\s*{)"), "${scope}${separator}${before}${access}operator ${targetType}() const${after}/*~variable~${variable}~*/", 10), 559 | // Inside the scope of /*~type~Range~*/ replace: 560 | // public: static implicit operator Range(std::tuple tuple) { return new Range(std::get<1-1>(tuple), std::get<2-1>(tuple)); } 561 | // public: Range(std::tuple tuple) : Range(std::get<1-1>(tuple), std::get<2-1>(tuple)) { } 562 | (new Regex(@"(?/\*~type~(?[^~\n\*]+)~(?[^~\n\*]+)~\*/)(?.|\n)(?((?~\k~\*/)(.|\n))*?)(?(private|protected|public): )static implicit operator (\k|\k)\((?[^{}\n]+)\)(\s|\n)*{(\s|\n)*return (new )?(\k|\k)\((?[^\n]+)\);(\s|\n)*}"), "${scope}${separator}${before}${access}${typeName}(${arguments}) : ${typeName}(${passedArguments}) { }", 10), 563 | // Inside the scope of /*~variable~range~*/ replace: 564 | // range.Minimum 565 | // this->Minimum 566 | (new Regex(@"(?{/\*~variable~(?[^~\n]+)~\*/)(?.|\n)(?(?(?{)|(?<-bracket>})|[^{}]|\n)*?)\k\.(?[_a-zA-Z0-9]+)(?(,|;|}| |\))(?(?{)|(?<-bracket>})|[^{}]|\n)*?})"), "${scope}${separator}${before}this->${field}${after}", 10), 567 | // Remove scope borders. 568 | // /*~ex~*/ 569 | // 570 | (new Regex(@"/\*~[^~\n]+~[^~\n]+~\*/"), "", 0), 571 | // Insert scope borders. 572 | // namespace Platform::Ranges { ... } 573 | // namespace Platform::Ranges {/*~start~namespace~Platform::Ranges~*/ ... /*~end~namespace~Platform::Ranges~*/} 574 | (new Regex(@"(?\r?\n(?[\t ]*)namespace (?(?[a-zA-Z][a-zA-Z0-9]+)(?::[a-zA-Z][a-zA-Z0-9]+)+)(\s|\n)*{)(?(.|\n)*)(?(?<=\r?\n)\k}(?!;))"), "${namespaceDeclarationBegin}/*~start~namespace~${namespaceName}~*/${middle}/*~end~namespace~${namespaceName}~*/${end}", 0), 575 | // Insert scope borders. 576 | // class Range { ... }; 577 | // class Range {/*~start~type~Range~T~*/ ... /*~end~type~Range~T~*/}; 578 | (new Regex(@"(?\r?\n(?[\t ]*)template [^\n]+)> (struct|class) (?[a-zA-Z0-9]+<\k>)(\s*:\s*[^{\n]+)?[\t ]*(\r?\n)?[\t ]*{)(?(.|\n)*)(?(?<=\r?\n)\k)(?};)"), "${classDeclarationBegin}/*~start~type~${type}~${typeParameter}~*/${middle}${endIndent}/*~end~type~${type}~${typeParameter}~*/${end}", 0), 579 | // Inside the scope replace: 580 | // /*~start~namespace~Platform::Ranges~*/ ... /*~start~type~Range~T~*/ ... public: override std::int32_t GetHashCode() { return {Minimum, Maximum}.GetHashCode(); } ... /*~end~type~Range~T~*/ ... /*~end~namespace~Platform::Ranges~*/ 581 | // /*~start~namespace~Platform::Ranges~*/ ... /*~start~type~Range~T~*/ ... /*~end~type~Range~T~*/ ... /*~end~namespace~Platform::Ranges~*/ namespace std { template struct hash> { std::size_t operator()(const Platform::Ranges::Range &obj) const { return {Minimum, Maximum}.GetHashCode(); } }; } 582 | (new Regex(@"(?/\*~start~namespace~(?[^~\n\*]+)~\*/)(?(.|\n)+)(?/\*~start~type~(?[^~\n\*]+)~(?[^~\n\*]+)~\*/)(?(.|\n)+?)(?\r?\n[ \t]*(?(private|protected|public): )override std::int32_t GetHashCode\(\)(\s|\n)*{\s*(?[^\s][^\n]+[^\s])\s*}\s*)(?(.|\n)+?)(?/\*~end~type~\k~\k~\*/)(?(.|\n)+)(?/\*~end~namespace~\k~\*/)}\r?\n"), "${namespaceScopeStart}${betweenStartScopes}${typeScopeStart}${before}${after}${typeScopeEnd}${betweenEndScopes}${namespaceScopeEnd}}" + Environment.NewLine + Environment.NewLine + "namespace std" + Environment.NewLine + "{" + Environment.NewLine + " template " + Environment.NewLine + " struct hash<${namespace}::${type}>" + Environment.NewLine + " {" + Environment.NewLine + " std::size_t operator()(const ${namespace}::${type} &obj) const" + Environment.NewLine + " {" + Environment.NewLine + " /*~start~method~*/${methodBody}/*~end~method~*/" + Environment.NewLine + " }" + Environment.NewLine + " };" + Environment.NewLine + "}" + Environment.NewLine, 10), 583 | // Inside scope of /*~start~method~*/ replace: 584 | // /*~start~method~*/ ... Minimum ... /*~end~method~*/ 585 | // /*~start~method~*/ ... obj.Minimum ... /*~end~method~*/ 586 | (new Regex(@"(?/\*~start~method~\*/)(?.+({|, ))(?[a-zA-Z][a-zA-Z0-9]+)(?[^\n\.\(a-zA-Z0-9]((?!/\*~end~method~\*/)[^\n])+)(?/\*~end~method~\*/)"), "${methodScopeStart}${before}obj.${name}${after}${methodScopeEnd}", 10), 587 | // Remove scope borders. 588 | // /*~start~type~Range~*/ 589 | // 590 | (new Regex(@"/\*~[^~\*\n]+(~[^~\*\n]+)*~\*/"), "", 0), 591 | // class Disposable : public Disposable 592 | // class Disposable : public Disposable<> 593 | (new Regex(@"(?(struct|class) (?[a-zA-Z][a-zA-Z0-9]*)<[^<>\n]+> : (?(private|protected|public) )?\k)(?\b(?!<))"), "${before}<>${after}", 0), 594 | // Insert scope borders. 595 | // class Disposable : public Disposable<> { ... }; 596 | // class Disposable : public Disposable<> {/*~start~type~Disposable~Disposable~Disposable~Disposable<>~*/ ... /*~end~type~Disposable~Disposable~Disposable~Disposable<>~*/}; 597 | (new Regex(@"(?\r?\n(?[\t ]*)template[\t ]*<(?[^\n]*)>[\t ]*(struct|class)[\t ]+(?(?[a-zA-Z][a-zA-Z0-9]*)(<[^<>\n]*>)?)[\t ]*:[\t ]*(?(private|protected|public)[\t ]+)?(?(?[a-zA-Z][a-zA-Z0-9]*)(<[^<>\n]*>)?)[\t ]*(\r?\n)?[\t ]*{)(?(.|\n)*)(?(?<=\r?\n)\k)(?};)"), "${classDeclarationBegin}/*~start~type~${type}~${fullType}~${baseType}~${fullBaseType}~*/${middle}${beforeEnd}/*~end~type~${type}~${fullType}~${baseType}~${fullBaseType}~*/${end}", 0), 598 | // Inside the scope replace: 599 | // /*~start~type~Disposable~Disposable~Disposable~Disposable<>~*/ ... ) : base( ... /*~end~type~Disposable~Disposable~Disposable~Disposable<>~*/ 600 | // /*~start~type~Disposable~Disposable~Disposable~Disposable<>~*/ ... ) : Disposable<>( /*~end~type~Disposable~Disposable~Disposable~Disposable<>~*/ 601 | (new Regex(@"(?(?/\*~start~type~(?(?[^~\n\*]+)~(?[^~\n\*]+)~\k~(?[^~\n\*]+))~\*/)(.|\n)+?\)\s*:\s)base(?\((.|\n)+?(?/\*~end~type~\k~\*/))"), "${before}${fullBaseType}${after}", 20), 602 | // Inside the scope replace: 603 | // /*~start~type~Disposable~Disposable~X~X<>~*/ ... ) : base( ... /*~end~type~Disposable~Disposable~X~X<>~*/ 604 | // /*~start~type~Disposable~Disposable~X~X<>~*/ ... ) : X( /*~end~type~Disposable~Disposable~X~X<>~*/ 605 | (new Regex(@"(?(?/\*~start~type~(?(?[^~\n\*]+)~(?[^~\n\*]+)~(?[^~\n\*]+)~(?[^~\n\*]+))~\*/)(.|\n)+?\)\s*:\s)base(?\((.|\n)+?(?/\*~end~type~\k~\*/))"), "${before}${baseType}${after}", 20), 606 | // Inside the scope replace: 607 | // /*~start~type~Disposable~Disposable~X~X<>~*/ ... public: Disposable(T object) { Object = object; } ... public: Disposable(T object) : Disposable(object) { } ... /*~end~type~Disposable~Disposable~X~X<>~*/ 608 | // /*~start~type~Disposable~Disposable~X~X<>~*/ ... public: Disposable(T object) { Object = object; } /*~end~type~Disposable~Disposable~X~X<>~*/ 609 | (new Regex(@"(?(?/\*~start~type~(?(?[^~\n\*]+)~(?[^~\n\*]+)~(?[^~\n\*]+)~(?[^~\n\*]+))~\*/)(.|\n)+?(?(?(private|protected|public):[\t ]*)?\k\((?[^()\n]+)\)\s*{[^{}\n]+})(.|\n)+?)(?(?(private|protected|public):[\t ]*)?\k\(\k\)\s*:[^{}\n]+\s*{[^{}\n]+})(?(.|\n)+?(?/\*~end~type~\k~\*/))"), "${before}${after}", 20), 610 | // Remove scope borders. 611 | // /*~start~type~Disposable~Disposable~Disposable~Disposable<>~*/ 612 | // 613 | (new Regex(@"/\*~[^~\*\n]+(~[^~\*\n]+)*~\*/"), "", 0), 614 | // Insert scope borders. 615 | // private: inline static const AppDomain _currentDomain = AppDomain.CurrentDomain; 616 | // private: inline static const AppDomain _currentDomain = AppDomain.CurrentDomain;/*~app-domain~_currentDomain~*/ 617 | (new Regex(@"(?(?(private|protected|public):[\t ]*)?(inline[\t ]+)?(static[\t ]+)?(const[\t ]+)?AppDomain[\t ]+(?[a-zA-Z_][a-zA-Z0-9_]*)[\t ]*=[\t ]*AppDomain\.CurrentDomain;)"), "${declaration}/*~app-domain~${field}~*/", 0), 618 | // Inside the scope replace: 619 | // /*~app-domain~_currentDomain~*/ ... _currentDomain.ProcessExit += OnProcessExit; 620 | // /*~app-domain~_currentDomain~*/ ... std::atexit(OnProcessExit); 621 | (new Regex(@"(?(?/\*~app-domain~(?[^~\n\*]+)~\*/)(.|\n)+?)\k\.ProcessExit[\t ]*\+=[\t ]*(?[a-zA-Z_][a-zA-Z0-9_]*);"), "${before}std::atexit(${eventHandler});/*~process-exit-handler~${eventHandler}~*/", 20), 622 | // Inside the scope replace: 623 | // /*~app-domain~_currentDomain~*/ ... _currentDomain.ProcessExit -= OnProcessExit; 624 | // /*~app-domain~_currentDomain~*/ ... /* No translation. It is not possible to unsubscribe from std::atexit. */ 625 | (new Regex(@"(?(?/\*~app-domain~(?[^~\n\*]+)~\*/)(.|\n)+?\r?\n[\t ]*)\k\.ProcessExit[\t ]*\-=[\t ]*(?[a-zA-Z_][a-zA-Z0-9_]*);"), "${before}/* No translation. It is not possible to unsubscribe from std::atexit. */", 20), 626 | // Inside the scope replace: 627 | // /*~process-exit-handler~OnProcessExit~*/ ... static void OnProcessExit(void *sender, EventArgs e) 628 | // /*~process-exit-handler~OnProcessExit~*/ ... static void OnProcessExit() 629 | (new Regex(@"(?(?/\*~process-exit-handler~(?[^~\n\*]+)~\*/)(.|\n)+?static[\t ]+void[\t ]+\k\()[^()\n]+\)"), "${before})", 20), 630 | // Remove scope borders. 631 | // /*~app-domain~_currentDomain~*/ 632 | // 633 | (new Regex(@"/\*~[^~\*\n]+(~[^~\*\n]+)*~\*/"), "", 0), 634 | // AppDomain.CurrentDomain.ProcessExit -= OnProcessExit; 635 | // /* No translation. It is not possible to unsubscribe from std::atexit. */ 636 | (new Regex(@"AppDomain\.CurrentDomain\.ProcessExit -= ([a-zA-Z_][a-zA-Z0-9_]*);"), "/* No translation. It is not possible to unsubscribe from std::atexit. */", 0), 637 | }.Cast().ToList(); 638 | 639 | /// 640 | /// 641 | /// The to list. 642 | /// 643 | /// 644 | /// 645 | public static readonly IList LastStage = new List 646 | { 647 | // IDisposable disposable) 648 | // IDisposable &disposable) 649 | (new Regex(@"(?I[A-Z][a-zA-Z0-9]+(<[^>\r\n]+>)?) (?[_a-zA-Z0-9]+)(?,|\))"), "${argumentAbstractType} &${argument}${after}", 0), 650 | // ICounter c1; 651 | // ICounter* c1; 652 | (new Regex(@"(?I[A-Z][a-zA-Z0-9]+(<[^>\r\n]+>)?) (?[_a-zA-Z0-9]+)(? = null)?;"), "${abstractType} *${variable}${after};", 0), 653 | // (expression) 654 | // expression 655 | (new Regex(@"(\(| )\(([a-zA-Z0-9_\*:]+)\)(,| |;|\))"), "$1$2$3", 0), 656 | // (method(expression)) 657 | // method(expression) 658 | (new Regex(@"(?(\(| ))\((?[a-zA-Z0-9_\->\*:]+)\((?((?\()|(?<-parenthesis>\))|[a-zA-Z0-9_\->\*:]*)+)(?(parenthesis)(?!))\)\)(?(,| |;|\)))"), "${firstSeparator}${method}(${expression})${lastSeparator}", 0), 659 | // .append(".") 660 | // .append(1, '.'); 661 | (new Regex(@"\.append\(""([^\\""]|\\[^""])""\)"), ".append(1, '$1')", 0), 662 | // return ref _elements[node]; 663 | // return &_elements[node]; 664 | (new Regex(@"return ref ([_a-zA-Z0-9]+)\[([_a-zA-Z0-9\*]+)\];"), "return &$1[$2];", 0), 665 | // ((1, 2)) 666 | // ({1, 2}) 667 | (new Regex(@"(?\(|, )\((?[^\n()]+), (?[^\n()]+)\)(?\)|, )"), "${before}{${first}, ${second}}${after}", 10), 668 | // {1, 2}.GetHashCode() 669 | // Platform::Hashing::Hash(1, 2) 670 | (new Regex(@"{(?[^\n{}]+), (?[^\n{}]+)}\.GetHashCode\(\)"), "Platform::Hashing::Hash(${first}, ${second})", 10), 671 | // range.ToString() 672 | // Platform::Converters::To(range).data() 673 | (new Regex(@"(?\W)(?[_a-zA-Z][_a-zA-Z0-9]+)\.ToString\(\)"), "${before}Platform::Converters::To(${variable}).data()", 10), 674 | // new 675 | // 676 | (new Regex(@"(?\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)new\s+"), "${before}", 10), 677 | // x == null 678 | // x == nullptr 679 | (new Regex(@"(?\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)(?[_a-zA-Z][_a-zA-Z0-9]+)(?\s*(==|!=)\s*)null(?\W)"), "${before}${variable}${operator}nullptr${after}", 10), 680 | // null 681 | // {} 682 | (new Regex(@"(?\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)null(?\W)"), "${before}{}${after}", 10), 683 | // default 684 | // 0 685 | (new Regex(@"(?\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)default(?\W)"), "${before}0${after}", 10), 686 | // object x 687 | // void *x 688 | (new Regex(@"(?\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)(?\w)"), "${before}void *${after}", 10), 689 | // 690 | // 691 | (new Regex(@"(?\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)(?\W)"), "${before}void*${after}", 10), 692 | // @object 693 | // object 694 | (new Regex(@"@([_a-zA-Z0-9]+)"), "$1", 0), 695 | // this->GetType().Name 696 | // typeid(this).name() 697 | (new Regex(@"(this)->GetType\(\)\.Name"), "typeid($1).name()", 0), 698 | // ArgumentNullException 699 | // std::invalid_argument 700 | (new Regex(@"(?\r?\n[^""\r\n]*(""(\\""|[^""\r\n])*""[^""\r\n]*)*)(?<=\W)(System\.)?ArgumentNullException(?\W)"), "${before}std::invalid_argument${after}", 10), 701 | // InvalidOperationException 702 | // std::runtime_error 703 | (new Regex(@"(\W)(InvalidOperationException|Exception)(\W)"), "$1std::runtime_error$3", 0), 704 | // ArgumentException 705 | // std::invalid_argument 706 | (new Regex(@"(\W)(ArgumentException|ArgumentOutOfRangeException)(\W)"), "$1std::invalid_argument$3", 0), 707 | // template struct Range : IEquatable> 708 | // template struct Range { 709 | (new Regex(@"(?template [^\n]+)> (struct|class) (?[a-zA-Z0-9]+<[^\n]+>)) : (public )?IEquatable<\k>(?(\s|\n)*{)"), "${before}${after}", 0), 710 | // public: delegate void Disposal(bool manual, bool wasDisposed); 711 | // public: delegate void Disposal(bool, bool); 712 | (new Regex(@"(?(?(private|protected|public): )delegate (?[a-zA-Z][a-zA-Z0-9:]+) (?[a-zA-Z][a-zA-Z0-9]+)\(((?[a-zA-Z][a-zA-Z0-9:]+), )*)(?[a-zA-Z][a-zA-Z0-9:]+) (?[a-zA-Z][a-zA-Z0-9]+)(?(, (?[a-zA-Z][a-zA-Z0-9:]+) (?[a-zA-Z][a-zA-Z0-9]+))*\);)"), "${before}${argumentType}${after}", 20), 713 | // public: delegate void Disposal(bool, bool); 714 | // using Disposal = void(bool, bool); 715 | (new Regex(@"(?(private|protected|public): )delegate (?[a-zA-Z][a-zA-Z0-9:]+) (?[a-zA-Z][a-zA-Z0-9]+)\((?[^\(\)\n]*)\);"), "using ${delegate} = ${returnType}(${argumentTypes});", 20), 716 | // <4-1> 717 | // <3> 718 | (new Regex(@"(?<)4-1(?>)"), "${before}3${after}", 0), 719 | // <3-1> 720 | // <2> 721 | (new Regex(@"(?<)3-1(?>)"), "${before}2${after}", 0), 722 | // <2-1> 723 | // <1> 724 | (new Regex(@"(?<)2-1(?>)"), "${before}1${after}", 0), 725 | // <1-1> 726 | // <0> 727 | (new Regex(@"(?<)1-1(?>)"), "${before}0${after}", 0), 728 | // #region Always 729 | // 730 | (new Regex(@"(^|\r?\n)[ \t]*\#(region|endregion)[^\r\n]*(\r?\n|$)"), "", 0), 731 | // //#define ENABLE_TREE_AUTO_DEBUG_AND_VALIDATION 732 | // 733 | (new Regex(@"\/\/[ \t]*\#define[ \t]+[_a-zA-Z0-9]+[ \t]*"), "", 0), 734 | // #if USEARRAYPOOL\r\n#endif 735 | // 736 | (new Regex(@"#if [a-zA-Z0-9]+\s+#endif"), "", 0), 737 | // [Fact] 738 | // 739 | (new Regex(@"(?\r?\n|\A)(?[\t ]+)\[[a-zA-Z0-9]+(\((?((?\()|(?<-parenthesis>\))|[^()\r\n]*)+)(?(parenthesis)(?!))\))?\][ \t]*(\r?\n\k)?"), "${firstNewLine}${indent}", 5), 740 | // \A \n ... namespace 741 | // \Anamespace 742 | (new Regex(@"(\A)(\r?\n)+namespace"), "$1namespace", 0), 743 | // \A \n ... class 744 | // \Aclass 745 | (new Regex(@"(\A)(\r?\n)+class"), "$1class", 0), 746 | // \n\n\n 747 | // \n\n 748 | (new Regex(@"\r?\n[ \t]*\r?\n[ \t]*\r?\n"), Environment.NewLine + Environment.NewLine, 50), 749 | // {\n\n 750 | // {\n 751 | (new Regex(@"{[ \t]*\r?\n[ \t]*\r?\n"), "{" + Environment.NewLine, 10), 752 | // \n\n} 753 | // \n} 754 | (new Regex(@"\r?\n[ \t]*\r?\n(?[ \t]*})"), Environment.NewLine + "${end}", 10), 755 | }.Cast().ToList(); 756 | 757 | /// 758 | /// 759 | /// Initializes a new instance. 760 | /// 761 | /// 762 | /// 763 | /// 764 | /// A extra rules. 765 | /// 766 | /// 767 | public CSharpToCppTransformer(IList extraRules) : base(FirstStage.Concat(extraRules).Concat(LastStage).ToList()) { } 768 | 769 | /// 770 | /// 771 | /// Initializes a new instance. 772 | /// 773 | /// 774 | /// 775 | public CSharpToCppTransformer() : base(FirstStage.Concat(LastStage).ToList()) { } 776 | } 777 | } 778 | --------------------------------------------------------------------------------