Process processes the synopsis and returns the generated tokens.
()
| 106 | |
| 107 | // Process processes the synopsis and returns the generated tokens. |
| 108 | func (scanner *Scanner) Process() ([]utils.Token, error) { |
| 109 | if scanner.isFinished || scanner.savedErr != nil { |
| 110 | return scanner.tokens, scanner.savedErr |
| 111 | } |
| 112 | ScannerLoop: |
| 113 | for { |
| 114 | r, ok := scanner.Next() |
| 115 | if !ok { |
| 116 | break ScannerLoop |
| 117 | } |
| 118 | switch r { |
| 119 | case '$': |
| 120 | var name []rune |
| 121 | for r, ok = scanner.Peek(); ok && r != '$'; r, ok = scanner.Peek() { |
| 122 | scanner.Advance() |
| 123 | name = append(name, r) |
| 124 | } |
| 125 | if !ok { |
| 126 | scanner.savedErr = fmt.Errorf("unexpected EOF when reading variable name") |
| 127 | break ScannerLoop |
| 128 | } |
| 129 | scanner.Advance() |
| 130 | scanner.tokens = append(scanner.tokens, utils.Token{ |
| 131 | Type: utils.TokenType_Variable, |
| 132 | Literal: string(name), |
| 133 | }) |
| 134 | case '\t': |
| 135 | scanner.savedErr = fmt.Errorf("tab found, remove all tabs from the synopsis") |
| 136 | break ScannerLoop |
| 137 | case ' ', '\n': |
| 138 | spaceCount := 0 |
| 139 | lineCount := 0 |
| 140 | if r == ' ' { |
| 141 | spaceCount += 1 |
| 142 | } |
| 143 | if r == '\n' { |
| 144 | lineCount++ |
| 145 | } |
| 146 | commentMode := false |
| 147 | WhitespaceLoop: |
| 148 | for r, ok = scanner.Peek(); ok; r, ok = scanner.Peek() { |
| 149 | if commentMode { |
| 150 | scanner.Advance() |
| 151 | if r == '\n' { |
| 152 | commentMode = false |
| 153 | } |
| 154 | } else { |
| 155 | switch r { |
| 156 | case ' ': |
| 157 | scanner.Advance() |
| 158 | spaceCount += 1 |
| 159 | case '\n': |
| 160 | scanner.Advance() |
| 161 | lineCount++ |
| 162 | case '/': |
| 163 | if next, _ := scanner.PeekBy(2); next == '/' { |
| 164 | if last, _ := scanner.PeekBy(0); last == '\n' { |
| 165 | scanner.Advance() |
no test coverage detected