summaryrefslogtreecommitdiff
path: root/src/thue/rule.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2022-09-04 00:34:09 +1200
committerMatthew Hall <hallmatthew314@gmail.com>2022-09-04 00:34:09 +1200
commite449c3c866b0c91a0bc34d5cb462c47b5fa43ce1 (patch)
treebb4318c89ed75fefeeaeff7dcb4ae274c16772e6 /src/thue/rule.cr
parent00755963fe8d688733ae55a774d72e04de5981b4 (diff)
Able to interpret Thue
Diffstat (limited to 'src/thue/rule.cr')
-rw-r--r--src/thue/rule.cr12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/thue/rule.cr b/src/thue/rule.cr
index 34c2396..cd45adc 100644
--- a/src/thue/rule.cr
+++ b/src/thue/rule.cr
@@ -1,14 +1,16 @@
require "./thue.cr"
abstract struct Thue::Rule
- @pattern : Regex
+ @regex : Regex
- def initialize(pattern : String)
- @pattern = Regex.new(pattern)
+ getter pattern : String
+
+ def initialize(@pattern : String)
+ @regex = Regex.new(Regex.escape(@pattern))
end
def matches?(str : String) : Bool
- str.matches?(@pattern)
+ str.matches?(@regex)
end
abstract def replacement : String
@@ -26,7 +28,7 @@ end
struct Thue::InputRule < Thue::Rule
def replacement : String
- gets
+ gets || ""
end
end