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/Mammoth/Couscous | |
| parent | f8ace2ab808441e55ffc95634bc8b88575de78ca (diff) | |
Replace parboiled parser with hand-written parser
Diffstat (limited to 'dotnet/Mammoth/Couscous')
6 files changed, 69 insertions, 0 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); + } +} |
