Implement rest of parser.

This commit is contained in:
Michael Jumper 2013-10-01 20:57:54 -07:00
parent 4485771df9
commit 1128038d0f
2 changed files with 38 additions and 7 deletions

View File

@ -117,9 +117,9 @@ typedef struct guac_instruction {
guac_instruction_parse_state state; guac_instruction_parse_state state;
/** /**
* The remaining length of the current element, if known. * The length of the current element, if known.
*/ */
int __element_remaining_length; int __element_length;
/** /**
* The number of elements currently parsed. * The number of elements currently parsed.

View File

@ -91,8 +91,7 @@ int guac_instruction_append(guac_instruction* instr,
/* If period, switch to parsing content */ /* If period, switch to parsing content */
else if (c == '.') { else if (c == '.') {
instr->__elementv[instr->__elementc++] = char_buffer; instr->__element_length = parsed_length;
instr->__element_remaining_length = parsed_length;
instr->state = GUAC_INSTRUCTION_PARSE_CONTENT; instr->state = GUAC_INSTRUCTION_PARSE_CONTENT;
break; break;
} }
@ -111,12 +110,44 @@ int guac_instruction_append(guac_instruction* instr,
return 0; return 0;
} }
} } /* end parse length */
/* Parse element content */ /* Parse element content */
if (instr->state == GUAC_INSTRUCTION_PARSE_CONTENT) { if (instr->state == GUAC_INSTRUCTION_PARSE_CONTENT) {
/* STUB */
} /* If enough data given, finish element */
if (length - bytes_parsed > instr->__element_length) {
/* Pull terminator */
char terminator = char_buffer[instr->__element_length];
/* Store reference to string within elementv */
instr->__elementv[instr->__elementc++] = char_buffer;
char_buffer[instr->__element_length] = '\0';
bytes_parsed += instr->__element_length+1;
/* If semicolon, store end-of-instruction */
if (terminator == ';') {
instr->state = GUAC_INSTRUCTION_PARSE_COMPLETE;
instr->opcode = instr->__elementv[0];
instr->argv = &(instr->__elementv[1]);
instr->argc = instr->__elementc - 1;
}
/* If comma, move on to next element */
else if (terminator == ',')
instr->state = GUAC_INSTRUCTION_PARSE_LENGTH;
/* Otherwise, parse error */
else {
instr->state = GUAC_INSTRUCTION_PARSE_ERROR;
return 0;
}
}
} /* end parse content */
return bytes_parsed; return bytes_parsed;