Skip to content

Instantly share code, notes, and snippets.

@johnynek
Created December 3, 2019 02:03
Show Gist options
  • Save johnynek/5808af4d7c95b1448a838770e7a889fa to your computer and use it in GitHub Desktop.
Save johnynek/5808af4d7c95b1448a838770e7a889fa to your computer and use it in GitHub Desktop.
Example of complex string pattern matching with bosatsu
1 package PatternExamples
2
3 foo = "this is foo"
4 bar = "this is bar"
5
6 combine = "foo: ${foo} bar: ${bar}"
7
8 def operator ==(a, b):
9 match string_Order_fn(a, b):
10 EQ: True
11 _: False
12
13 def operator &&(a, b):
14 if a: b
15 else: False
16
17 fb = match combine:
18 "foo: ${f} bar: ${b}":
19 (f == foo) && (b == bar)
20 _: False
21
22 test = Assertion(fb, "foo-bar match")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment