| 224 | # When parts of the LOG_FUNCTION cannot be found |
| 225 | # |
| 226 | def parseLogStatement(lines, startPosition): |
| 227 | lineNum, offset = startPosition |
| 228 | assert lines[lineNum].find(LOG_FUNCTION, offset) == offset |
| 229 | |
| 230 | # Find the left parenthesis after the LOG_FUNCTION identifier |
| 231 | offset += len(LOG_FUNCTION) |
| 232 | char, openParenPos = peekNextMeaningfulChar(lines, FilePosition(lineNum, offset)) |
| 233 | lineNum, offset = openParenPos |
| 234 | |
| 235 | # This is an assert instead of a ValueError since the caller should ensure |
| 236 | # this is a valid start to a function invocation before calling us. |
| 237 | assert(char == "(") |
| 238 | |
| 239 | # Identify all the argument start and end positions |
| 240 | args = [] |
| 241 | while lines[lineNum][offset] != ")": |
| 242 | offset = offset + 1 |
| 243 | startPos = FilePosition(lineNum, offset) |
| 244 | arg = parseArgumentStartingAt(lines, startPos) |
| 245 | if not arg: |
| 246 | raise ValueError("Cannot find end of NANO_LOG invocation", |
| 247 | lines[startPosition[0]:startPosition[0]+5]) |
| 248 | args.append(arg) |
| 249 | lineNum, offset = arg.endPos |
| 250 | |
| 251 | closeParenPos = FilePosition(lineNum, offset) |
| 252 | |
| 253 | # To finish this off, find the closing semicolon |
| 254 | semiColonPeek = peekNextMeaningfulChar(lines, FilePosition(lineNum, offset + 1)) |
| 255 | if not semiColonPeek: |
| 256 | raise ValueError("Expected ';' after NANO_LOG statement", |
| 257 | lines[startPosition[0]:closeParenPos.lineNum]) |
| 258 | |
| 259 | char, pos = semiColonPeek |
| 260 | if (char != ";"): |
| 261 | raise ValueError("Expected ';' after NANO_LOG statement", |
| 262 | lines[startPosition[0]:pos[0]]) |
| 263 | |
| 264 | logStatement = { |
| 265 | 'startPos': startPosition, |
| 266 | 'openParenPos': openParenPos, |
| 267 | 'closeParenPos': closeParenPos, |
| 268 | 'semiColonPos': pos, |
| 269 | 'arguments': args, |
| 270 | } |
| 271 | |
| 272 | return logStatement |
| 273 | |
| 274 | # Helper function to peekNextMeaningfulCharacter that determines whether |
| 275 | # a character is a printable character (like a-z) vs. a control code |