diff options
| author | Li Jin <dragon-fly@qq.com> | 2020-10-08 13:01:18 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2020-10-08 13:01:18 +0800 |
| commit | 97bbe98289fb74c7cf2d9793b80a1a27b4146045 (patch) | |
| tree | 4bee0dded55bad28f6822b6e2dd3ea5251c66ae2 /spec/inputs/with.mp | |
| parent | 5b656d2913e4f9f0017698ec835ce4ddda1dc81f (diff) | |
| download | yuescript-97bbe98289fb74c7cf2d9793b80a1a27b4146045.tar.gz yuescript-97bbe98289fb74c7cf2d9793b80a1a27b4146045.tar.bz2 yuescript-97bbe98289fb74c7cf2d9793b80a1a27b4146045.zip | |
change file extension moonp.
Diffstat (limited to 'spec/inputs/with.mp')
| -rw-r--r-- | spec/inputs/with.mp | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/spec/inputs/with.mp b/spec/inputs/with.mp new file mode 100644 index 0000000..704c494 --- /dev/null +++ b/spec/inputs/with.mp | |||
| @@ -0,0 +1,118 @@ | |||
| 1 | |||
| 2 | do | ||
| 3 | a = -> | ||
| 4 | with something | ||
| 5 | print .hello | ||
| 6 | print hi | ||
| 7 | print "world" | ||
| 8 | |||
| 9 | do | ||
| 10 | with leaf | ||
| 11 | .world! | ||
| 12 | .world 1,2,3 | ||
| 13 | |||
| 14 | g = .what.is.this | ||
| 15 | |||
| 16 | .hi 1,2,3 | ||
| 17 | |||
| 18 | \hi(1,2).world 2323 | ||
| 19 | |||
| 20 | \hi "yeah", "man" | ||
| 21 | .world = 200 | ||
| 22 | |||
| 23 | do | ||
| 24 | zyzyzy = with something | ||
| 25 | .set_state "hello world" | ||
| 26 | |||
| 27 | do | ||
| 28 | x = 5 + with Something! | ||
| 29 | \write "hello world" | ||
| 30 | |||
| 31 | |||
| 32 | do | ||
| 33 | x = { | ||
| 34 | hello: with yeah | ||
| 35 | \okay! | ||
| 36 | } | ||
| 37 | |||
| 38 | do | ||
| 39 | with foo | ||
| 40 | _ = \prop"something".hello | ||
| 41 | .prop\send(one) | ||
| 42 | .prop\send one | ||
| 43 | |||
| 44 | |||
| 45 | -- | ||
| 46 | |||
| 47 | do | ||
| 48 | with a, b -- b is lost | ||
| 49 | print .world | ||
| 50 | |||
| 51 | mod = with _M = {} | ||
| 52 | .Thing = "hi" | ||
| 53 | |||
| 54 | -- operate on a only | ||
| 55 | with a, b = something, pooh | ||
| 56 | print .world | ||
| 57 | |||
| 58 | x = with a, b = 1, 2 | ||
| 59 | print a + b | ||
| 60 | |||
| 61 | print with a, b = 1, 2 | ||
| 62 | print a + b | ||
| 63 | |||
| 64 | -- assignment lhs must be evaluated in the order they appear | ||
| 65 | p = with hello!.x, world!.y = 1, 2 | ||
| 66 | print a + b | ||
| 67 | |||
| 68 | -- | ||
| 69 | |||
| 70 | do | ||
| 71 | x = "hello" | ||
| 72 | with x | ||
| 73 | x\upper! | ||
| 74 | |||
| 75 | do | ||
| 76 | with k = "jo" | ||
| 77 | print \upper! | ||
| 78 | |||
| 79 | do | ||
| 80 | with a,b,c = "", "", "" | ||
| 81 | print \upper! | ||
| 82 | |||
| 83 | do | ||
| 84 | a = "bunk" | ||
| 85 | with a,b,c = "", "", "" | ||
| 86 | print \upper! | ||
| 87 | |||
| 88 | do | ||
| 89 | with j | ||
| 90 | print \upper! | ||
| 91 | |||
| 92 | do | ||
| 93 | with k.j = "jo" | ||
| 94 | print \upper! | ||
| 95 | |||
| 96 | do | ||
| 97 | with a | ||
| 98 | print .b | ||
| 99 | -- nested `with`s should change the scope correctly | ||
| 100 | with .c | ||
| 101 | print .d | ||
| 102 | |||
| 103 | do | ||
| 104 | with a | ||
| 105 | -- nested `with`s with assignments should change the scope correctly | ||
| 106 | with .b = 2 | ||
| 107 | print .c | ||
| 108 | |||
| 109 | do | ||
| 110 | _ = -> | ||
| 111 | with hi | ||
| 112 | return .a, .b | ||
| 113 | |||
| 114 | |||
| 115 | do | ||
| 116 | with dad | ||
| 117 | .if "yes" | ||
| 118 | y = .end.of.function | ||
