-
-
Notifications
You must be signed in to change notification settings - Fork 151
/
ysh-multiline.test.sh
179 lines (148 loc) · 2.75 KB
/
ysh-multiline.test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# This syntax is available with OSH too
#### ... with simple command
... echo # comment
hi # comment
there
;
echo ---
## STDOUT:
hi there
---
## END
#### ... with pipeline
... { echo one; echo two; }
| sort
| wc -l
;
## STDOUT:
2
## END
#### ... with multiline $()
# newlines mean the normal thing
echo $(echo one
echo two)
... echo
$(echo 3
echo 4) # is this right?
| wc -l
;
## STDOUT:
one two
1
## END
#### ... inside command sub $()
echo one $(... echo
two
three) four
echo five
## STDOUT:
one two three four
five
## END
#### ... with && and [[
echo one && false || echo two
... echo three
&& [[ 0 -eq 0 ]]
&& echo four
&& false
|| echo five
;
echo ---
## STDOUT:
one
two
three
four
five
---
## END
#### '... for' is allowed, but NOT recommended
... for x in foo bar; do echo $x; done
;
... for x in foo bar; do
echo $x;
done
;
return
# This style gets messed up because of translation, but that is EXPECTED.
... for x in foo bar
do
echo $x;
done
;
## STDOUT:
foo
bar
foo
bar
## END
#### Blank line in multiline command is syntax error
... echo comment
# comment
is OK
;
... echo blank line
is not OK
;
## status: 2
## STDOUT:
comment is OK
## END
#### Blank line with spaces and tabs isn't OK either
... echo comment
# comment
is OK
;
# NOTE: invisible spaces and tabs below (:set list in vim)
... echo blank line
is not OK
;
## status: 2
## STDOUT:
comment is OK
## END
# Notes:
# - MakeParserForCommandSub() instantiates a new WordParser, so we can safely
# change state in the top-level one only
# - BoolParser is called for [[ ]] and uses the same self.w_parser. I think
# that's OK?
# So I think we can change state in WordParser. (Also possible in
# CommandParser but meh).
#
# self.is_multiline = False
#
# When this is flag is on, then we
#
# Id.Op_Newline -> Id.WS_Space or Id.Ignored_LineCont
# - and then that is NOT passed to the command parser?
# - Or you can make it Id.Ignored_Newline
#
# BUT if you get 2 of them in a row without a comment, you can change it to:
# - Id.Op_Newline?
#
# Actually this is very simple rule and maybe can be done without much
# disturbance to the code.
#
# cursor_was_newline might need more state?
#### Combine multi-line command and strings
shopt -s oil:all
var x = 'one'
# Print 3 args without separators
... write --sep '' --end '' --
"""
$x
""" # 1. Double quoted
'''
two
three
''' # 2. Single quoted
$'four\n' # 3. C-style with explicit newline
| tac # Reverse
| tr a-z A-Z # Uppercase
;
## STDOUT:
FOUR
THREE
TWO
ONE
## END