summaryrefslogtreecommitdiff
path: root/src/thue/rule.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2022-09-03 16:07:58 +1200
committerMatthew Hall <hallmatthew314@gmail.com>2022-09-03 16:07:58 +1200
commitcd9f3bc3f3ecb04eaee42c65880711bd35c7e71b (patch)
tree48d76a9bfaaa7959de7a9689277b8e01e78286b1 /src/thue/rule.cr
parent95e20a4662c96372b62441a4c598df0f29851834 (diff)
Able to parse Thue code
Diffstat (limited to 'src/thue/rule.cr')
-rw-r--r--src/thue/rule.cr43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/thue/rule.cr b/src/thue/rule.cr
new file mode 100644
index 0000000..34c2396
--- /dev/null
+++ b/src/thue/rule.cr
@@ -0,0 +1,43 @@
+require "./thue.cr"
+
+abstract struct Thue::Rule
+ @pattern : Regex
+
+ def initialize(pattern : String)
+ @pattern = Regex.new(pattern)
+ end
+
+ def matches?(str : String) : Bool
+ str.matches?(@pattern)
+ end
+
+ abstract def replacement : String
+end
+
+struct Thue::NormalRule < Thue::Rule
+ def initialize(pattern : String, @replacement : String)
+ super(pattern)
+ end
+
+ def replacement : String
+ @replacement
+ end
+end
+
+struct Thue::InputRule < Thue::Rule
+ def replacement : String
+ gets
+ end
+end
+
+struct Thue::OutputRule < Thue::Rule
+ def initialize(pattern : String, @output : String)
+ super(pattern)
+ end
+
+ def replacement : String
+ print @output
+ return ""
+ end
+end
+