| 1 | # This syntax is available with OSH too |
| 2 | |
| 3 | #### ... with simple command |
| 4 | ... echo # comment |
| 5 | hi # comment |
| 6 | there |
| 7 | ; |
| 8 | echo --- |
| 9 | ## STDOUT: |
| 10 | hi there |
| 11 | --- |
| 12 | ## END |
| 13 | |
| 14 | #### ... with pipeline |
| 15 | ... { echo one; echo two; } |
| 16 | | sort |
| 17 | | wc -l |
| 18 | ; |
| 19 | ## STDOUT: |
| 20 | 2 |
| 21 | ## END |
| 22 | |
| 23 | #### ... with multiline $() |
| 24 | |
| 25 | # newlines mean the normal thing |
| 26 | echo $(echo one |
| 27 | echo two) |
| 28 | |
| 29 | ... echo |
| 30 | $(echo 3 |
| 31 | echo 4) # is this right? |
| 32 | | wc -l |
| 33 | ; |
| 34 | ## STDOUT: |
| 35 | one two |
| 36 | 1 |
| 37 | ## END |
| 38 | |
| 39 | #### ... with && and [[ |
| 40 | echo one && false || echo two |
| 41 | |
| 42 | ... echo three |
| 43 | && [[ 0 -eq 0 ]] |
| 44 | && echo four |
| 45 | && false |
| 46 | || echo five |
| 47 | ; |
| 48 | |
| 49 | echo --- |
| 50 | |
| 51 | ## STDOUT: |
| 52 | one |
| 53 | two |
| 54 | three |
| 55 | four |
| 56 | five |
| 57 | --- |
| 58 | ## END |
| 59 | |
| 60 | #### '... for' is allowed, but NOT recommended |
| 61 | ... for x in foo bar; do echo $x; done |
| 62 | ; |
| 63 | |
| 64 | ... for x in foo bar; do |
| 65 | echo $x; |
| 66 | done |
| 67 | ; |
| 68 | |
| 69 | return |
| 70 | |
| 71 | # This style gets messed up because of translation, but that is EXPECTED. |
| 72 | ... for x in foo bar |
| 73 | do |
| 74 | echo $x; |
| 75 | done |
| 76 | ; |
| 77 | |
| 78 | ## STDOUT: |
| 79 | foo |
| 80 | bar |
| 81 | foo |
| 82 | bar |
| 83 | ## END |
| 84 | |
| 85 | #### Blank line in multiline command is syntax error |
| 86 | ... echo comment |
| 87 | # comment |
| 88 | is OK |
| 89 | ; |
| 90 | |
| 91 | ... echo blank line |
| 92 | |
| 93 | is not OK |
| 94 | ; |
| 95 | |
| 96 | ## status: 2 |
| 97 | ## STDOUT: |
| 98 | comment is OK |
| 99 | ## END |
| 100 | |
| 101 | #### Blank line with spaces and tabs isn't OK either |
| 102 | ... echo comment |
| 103 | # comment |
| 104 | is OK |
| 105 | ; |
| 106 | |
| 107 | # NOTE: invisible spaces and tabs below (:set list in vim) |
| 108 | ... echo blank line |
| 109 | |
| 110 | is not OK |
| 111 | ; |
| 112 | ## status: 2 |
| 113 | ## STDOUT: |
| 114 | comment is OK |
| 115 | ## END |
| 116 | |
| 117 | |
| 118 | |
| 119 | # Notes: |
| 120 | # - MakeParserForCommandSub() instantiates a new WordParser, so we can safetly |
| 121 | # change state in the top-level one only |
| 122 | # - BoolParser is called for [[ ]] and uses the same self.w_parser. I think |
| 123 | # that's OK? |
| 124 | |
| 125 | # So I think we can change state in WordParser. (Also possible in |
| 126 | # CommandParser but meh). |
| 127 | # |
| 128 | # self.is_multiline = False |
| 129 | # |
| 130 | # When this is flag is on, then we |
| 131 | # |
| 132 | # Id.Op_Newline -> Id.WS_Space or Id.Ignored_LineCont |
| 133 | # - and then that is NOT passed to the command parser? |
| 134 | # - Or you can make it Id.Ignored_Newline |
| 135 | # |
| 136 | # BUT if you get 2 of them in a row without a comment, you can change it to: |
| 137 | # - Id.Op_Newline? |
| 138 | # |
| 139 | # Actually this is very simple rule and maybe can be done without much |
| 140 | # disturbance to the code. |
| 141 | # |
| 142 | # cursor_was_newline might need more state? |
| 143 |