diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-04-27 20:54:50 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-04-28 21:38:41 +0100 |
| commit | 5bdef288372d3a6a8134479a6497c44f3b17c4dc (patch) | |
| tree | faac4e716212c78394b7b982e13f916cb6523d7f /dotnet | |
| parent | f8ace2ab808441e55ffc95634bc8b88575de78ca (diff) | |
Replace parboiled parser with hand-written parser
Diffstat (limited to 'dotnet')
| -rw-r--r-- | dotnet/Mammoth/Couscous/HorribleHacks.cs | 9 | ||||
| -rw-r--r-- | dotnet/Mammoth/Couscous/JavaStringExtensions.cs | 16 | ||||
| -rw-r--r-- | dotnet/Mammoth/Couscous/java/lang/IllegalArgumentException.cs | 8 | ||||
| -rw-r--r-- | dotnet/Mammoth/Couscous/java/math/BigInteger.cs | 24 | ||||
| -rw-r--r-- | dotnet/Mammoth/Couscous/java/util/Arrays.cs | 7 | ||||
| -rw-r--r-- | dotnet/Mammoth/Couscous/java/util/function/BiConsumer.cs | 5 | ||||
| -rw-r--r-- | dotnet/Mammoth/Mammoth.csproj | 5 |
7 files changed, 73 insertions, 1 deletions
diff --git a/dotnet/Mammoth/Couscous/HorribleHacks.cs b/dotnet/Mammoth/Couscous/HorribleHacks.cs index 88c746b..9f1ac30 100644 --- a/dotnet/Mammoth/Couscous/HorribleHacks.cs +++ b/dotnet/Mammoth/Couscous/HorribleHacks.cs @@ -1,9 +1,14 @@ using Mammoth.Couscous.java.util; using Mammoth.Couscous.org.zwobble.mammoth.@internal.documents; +using Mammoth.Couscous.org.zwobble.mammoth.@internal.styles.parsing; using System.Linq; namespace Mammoth.Couscous { internal static class HorribleHacks { + internal static bool equals(this char first, int second) { + return first == second; + } + internal static bool equals(this Optional<string> first, Optional<string> second) { return (!first.isPresent() && !second.isPresent()) || (first.isPresent() && second.isPresent() && first.get() == second.get()); } @@ -17,5 +22,9 @@ namespace Mammoth.Couscous { internal static bool equals(this NoteType first, NoteType second) { return first == second; } + + internal static bool equals(this TokenType first, TokenType second) { + return first == second; + } } } diff --git a/dotnet/Mammoth/Couscous/JavaStringExtensions.cs b/dotnet/Mammoth/Couscous/JavaStringExtensions.cs index 429bc7d..bf4e73f 100644 --- a/dotnet/Mammoth/Couscous/JavaStringExtensions.cs +++ b/dotnet/Mammoth/Couscous/JavaStringExtensions.cs @@ -2,6 +2,10 @@ using System; namespace Mammoth.Couscous { internal static class JavaStringExtensions { + internal static char charAt(this string value, int index) { + return value[index]; + } + internal static bool equalsIgnoreCase(this string first, string second) { return first.Equals(second, StringComparison.InvariantCultureIgnoreCase); } @@ -13,5 +17,17 @@ namespace Mammoth.Couscous { internal static bool isEmpty(this string value) { return value.Length == 0; } + + internal static bool startsWith(this string value, string prefix) { + return value.StartsWith(prefix); + } + + internal static string trim(this string value) { + return value.Trim(); + } + + internal static string[] split(this string value, string separator) { + return System.Text.RegularExpressions.Regex.Split(value, separator); + } } } diff --git a/dotnet/Mammoth/Couscous/java/lang/IllegalArgumentException.cs b/dotnet/Mammoth/Couscous/java/lang/IllegalArgumentException.cs new file mode 100644 index 0000000..57ef62b --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/lang/IllegalArgumentException.cs @@ -0,0 +1,8 @@ +using System; + +namespace Mammoth.Couscous.java.lang { + internal class IllegalArgumentException : RuntimeException { + internal IllegalArgumentException(string message) : base(message) { + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/math/BigInteger.cs b/dotnet/Mammoth/Couscous/java/math/BigInteger.cs new file mode 100644 index 0000000..40ac3d3 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/math/BigInteger.cs @@ -0,0 +1,24 @@ +namespace Mammoth.Couscous.java.math { + internal class BigInteger { + internal static readonly BigInteger _ONE = new BigInteger(1); + + // TOOD: use proper BigInteger + private readonly long _value; + + internal BigInteger(string value) { + _value = long.Parse(value); + } + + internal BigInteger(long value) { + _value = value; + } + + internal BigInteger subtract(BigInteger other) { + return new BigInteger(_value - other._value); + } + + internal string toString() { + return _value.ToString(); + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/util/Arrays.cs b/dotnet/Mammoth/Couscous/java/util/Arrays.cs new file mode 100644 index 0000000..093db83 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/Arrays.cs @@ -0,0 +1,7 @@ +namespace Mammoth.Couscous.java.util { + internal static class Arrays { + internal static List<T> asList<T>(T[] elements) { + return ToJava.ListToList(elements); + } + } +} diff --git a/dotnet/Mammoth/Couscous/java/util/function/BiConsumer.cs b/dotnet/Mammoth/Couscous/java/util/function/BiConsumer.cs new file mode 100644 index 0000000..9479a78 --- /dev/null +++ b/dotnet/Mammoth/Couscous/java/util/function/BiConsumer.cs @@ -0,0 +1,5 @@ +namespace Mammoth.Couscous.java.util.function { + internal interface BiConsumer<T1, T2> { + void accept(T1 first, T2 second); + } +} diff --git a/dotnet/Mammoth/Mammoth.csproj b/dotnet/Mammoth/Mammoth.csproj index 68e7d70..4e945d0 100644 --- a/dotnet/Mammoth/Mammoth.csproj +++ b/dotnet/Mammoth/Mammoth.csproj @@ -48,15 +48,18 @@ <Compile Include="Couscous\java\io\IOException.cs" /> <Compile Include="Couscous\java\io\Closeable.cs" /> <Compile Include="Couscous\java\nio\file\Path.cs" /> + <Compile Include="Couscous\java\lang\IllegalArgumentException.cs" /> <Compile Include="Couscous\java\lang\IndexOutOfBoundsException.cs" /> <Compile Include="Couscous\java\lang\Iterable.cs" /> <Compile Include="Couscous\java\lang\RuntimeException.cs" /> <Compile Include="Couscous\java\lang\String.cs" /> <Compile Include="Couscous\java\lang\StringBuilder.cs" /> <Compile Include="Couscous\java\lang\UnsupportedOperationException.cs" /> + <Compile Include="Couscous\java\math\BigInteger.cs" /> <Compile Include="Couscous\java\net\URI.cs" /> <Compile Include="Couscous\java\net\URISyntaxException.cs" /> <Compile Include="Couscous\java\net\URL.cs" /> + <Compile Include="Couscous\java\util\function\BiConsumer.cs" /> <Compile Include="Couscous\java\util\function\BiFunction.cs" /> <Compile Include="Couscous\java\util\function\BiPredicate.cs" /> <Compile Include="Couscous\java\util\function\Consumer.cs" /> @@ -65,6 +68,7 @@ <Compile Include="Couscous\java\util\function\Supplier.cs" /> <Compile Include="Couscous\java\util\ArrayDeque.cs" /> <Compile Include="Couscous\java\util\ArrayList.cs" /> + <Compile Include="Couscous\java\util\Arrays.cs" /> <Compile Include="Couscous\java\util\Collection.cs" /> <Compile Include="Couscous\java\util\Deque.cs" /> <Compile Include="Couscous\java\util\HashMap.cs" /> @@ -77,7 +81,6 @@ <Compile Include="Couscous\java\util\Set.cs" /> <Compile Include="Couscous\mammoth\internal\docx\InMemoryDocxFile.cs" /> <Compile Include="Couscous\mammoth\internal\docx\ZippedDocxFile.cs" /> - <Compile Include="Couscous\mammoth\internal\styles\parsing\StyleMapParser.cs" /> <Compile Include="Couscous\mammoth\internal\util\Base64Encoding.cs" /> <Compile Include="Couscous\mammoth\internal\util\Casts.cs" /> <Compile Include="Couscous\mammoth\internal\util\Lists.cs" /> |
