ply_scan_token_t *peektoken = ply_scan_peek_next_token (scan);
for (entry_index = 0; table[entry_index].symbol; entry_index++)
{
- if (curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL) continue;
+ if (!ply_scan_token_is_symbol (curtoken)) continue;
if (curtoken->data.symbol != table[entry_index].symbol[0]) continue;
if (table[entry_index].symbol[1])
{
- if (peektoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL) continue;
+ if (!ply_scan_token_is_symbol (peektoken)) continue;
if (peektoken->data.symbol != table[entry_index].symbol[1]) continue;
if (peektoken->whitespace) continue;
}
ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
ply_list_t *parameter_list;
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != '('))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, '('))
{
script_parse_error (curtoken,
"Function declaration requires parameters to be declared within '(' brackets");
while (true)
{
- if ((curtoken->type == PLY_SCAN_TOKEN_TYPE_SYMBOL)
- && (curtoken->data.symbol == ')')) break;
- if (curtoken->type != PLY_SCAN_TOKEN_TYPE_IDENTIFIER)
+ if (ply_scan_token_is_symbol_of_value (curtoken, ')')) break;
+ if (!ply_scan_token_is_identifier (curtoken))
{
script_parse_error (curtoken,
"Function declaration parameters must be valid identifiers");
curtoken = ply_scan_get_next_token (scan);
- if (curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- {
- script_parse_error (curtoken,
- "Function declaration parameters must separated with ',' and terminated with a ')'");
- return NULL;
- }
- if (curtoken->data.symbol == ')') break;
- if (curtoken->data.symbol != ',')
+ if (ply_scan_token_is_symbol_of_value (curtoken, ')')) break;
+ if (!ply_scan_token_is_symbol_of_value (curtoken, ','))
{
script_parse_error (curtoken,
"Function declaration parameters must separated with ',' and terminated with a ')'");
ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
script_exp_t *exp = NULL;
- if (curtoken->type == PLY_SCAN_TOKEN_TYPE_INTEGER)
+ if (ply_scan_token_is_integer (curtoken))
{
exp = malloc (sizeof (script_exp_t));
exp->type = SCRIPT_EXP_TYPE_TERM_INT;
ply_scan_get_next_token (scan);
return exp;
}
- if (curtoken->type == PLY_SCAN_TOKEN_TYPE_FLOAT)
+ if (ply_scan_token_is_float (curtoken))
{
exp = malloc (sizeof (script_exp_t));
exp->type = SCRIPT_EXP_TYPE_TERM_FLOAT;
ply_scan_get_next_token (scan);
return exp;
}
- if (curtoken->type == PLY_SCAN_TOKEN_TYPE_IDENTIFIER)
+ if (ply_scan_token_is_identifier (curtoken))
{
exp = malloc (sizeof (script_exp_t));
- if (!strcmp (curtoken->data.string, "NULL"))
+ if (ply_scan_token_is_identifier_of_value (curtoken, "NULL"))
exp->type = SCRIPT_EXP_TYPE_TERM_NULL;
- else if (!strcmp (curtoken->data.string, "global"))
+ else if (ply_scan_token_is_identifier_of_value (curtoken, "global"))
exp->type = SCRIPT_EXP_TYPE_TERM_GLOBAL;
- else if (!strcmp (curtoken->data.string, "local"))
+ else if (ply_scan_token_is_identifier_of_value (curtoken, "local"))
exp->type = SCRIPT_EXP_TYPE_TERM_LOCAL;
- else if (!strcmp (curtoken->data.string, "fun"))
+ else if (ply_scan_token_is_identifier_of_value (curtoken, "fun"))
{
exp->type = SCRIPT_EXP_TYPE_FUNCTION_DEF;
ply_scan_get_next_token (scan);
curtoken = ply_scan_get_next_token (scan);
return exp;
}
- if (curtoken->type == PLY_SCAN_TOKEN_TYPE_STRING)
+ if (ply_scan_token_is_string (curtoken))
{
exp = malloc (sizeof (script_exp_t));
exp->type = SCRIPT_EXP_TYPE_TERM_STRING;
ply_scan_get_next_token (scan);
return exp;
}
- if ((curtoken->type == PLY_SCAN_TOKEN_TYPE_SYMBOL)
- && (curtoken->data.symbol == '('))
+ if (ply_scan_token_is_symbol_of_value (curtoken, '('))
{
ply_scan_get_next_token (scan);
exp = script_parse_exp (scan);
"Expected valid contents of bracketed expression");
return NULL;
}
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != ')'))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, ')'))
{
script_parse_error (curtoken,
"Expected bracketed block to be terminated with a ')'");
while (true)
{
- if (curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL) break;
- if (curtoken->data.symbol == '(')
+ if (!ply_scan_token_is_symbol (curtoken)) break;
+ if (ply_scan_token_is_symbol_of_value (curtoken, '('))
{
script_exp_t *func = malloc (sizeof (script_exp_t));
ply_list_t *parameters = ply_list_new ();
ply_scan_get_next_token (scan);
while (true)
{
- if ((curtoken->type == PLY_SCAN_TOKEN_TYPE_SYMBOL)
- && (curtoken->data.symbol == ')')) break;
+ if (ply_scan_token_is_symbol_of_value (curtoken, ')')) break;
script_exp_t *parameter = script_parse_exp (scan);
ply_list_append_data (parameters, parameter);
curtoken = ply_scan_get_current_token (scan);
- if (curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
+ if (!ply_scan_token_is_symbol (curtoken))
{
script_parse_error (curtoken,
"Function parameters should be separated with a ',' and terminated with a ')'");
return NULL;
}
- if (curtoken->data.symbol == ')') break;
- if (curtoken->data.symbol != ',')
+ if (ply_scan_token_is_symbol_of_value (curtoken, ')')) break;
+ if (!ply_scan_token_is_symbol_of_value (curtoken, ','))
{
script_parse_error (curtoken,
"Function parameters should be separated with a ',' and terminated with a ')'");
}
script_exp_t *key;
- if (curtoken->data.symbol == '.')
+ if (ply_scan_token_is_symbol_of_value (curtoken, '.'))
{
ply_scan_get_next_token (scan);
- if (curtoken->type == PLY_SCAN_TOKEN_TYPE_IDENTIFIER)
+ if (ply_scan_token_is_identifier (curtoken))
{
key = malloc (sizeof (script_exp_t));
key->type = SCRIPT_EXP_TYPE_TERM_STRING;
key->data.string = strdup (curtoken->data.string);
}
- else if (curtoken->type == PLY_SCAN_TOKEN_TYPE_INTEGER) /* errrr, integer keys without being [] bracketed */
+ else if (ply_scan_token_is_integer (curtoken)) /* errrr, integer keys without being [] bracketed */
{
key = malloc (sizeof (script_exp_t)); /* This is broken with floats as obj.10.6 is obj[10.6] and not obj[10][6] */
key->type = SCRIPT_EXP_TYPE_TERM_INT;
}
curtoken = ply_scan_get_next_token (scan);
}
- else if (curtoken->data.symbol == '[')
+ else if (ply_scan_token_is_symbol_of_value (curtoken, '['))
{
ply_scan_get_next_token (scan);
key = script_parse_exp (scan);
curtoken = ply_scan_get_current_token (scan);
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != ']'))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, ']'))
{
script_parse_error (curtoken,
"Expected a ']' to terminate the index expression");
script_exp_t *exp = script_parse_exp_ltr (scan, presedence + 1);
if (!exp) return NULL;
- while (1)
+ while (true)
{
const script_parse_operator_table_entry_t* entry;
entry = script_parse_operator_table_entry_lookup(scan, operator_table);
{
ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != '{'))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, '{'))
return NULL;
ply_scan_get_next_token (scan);
ply_list_t *sublist = script_parse_op_list (scan);
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != '}'))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, '}'))
{
script_parse_error (ply_scan_get_current_token (scan),
"Expected a '}' to terminate the operation block");
ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
script_op_type_t type;
- if (curtoken->type != PLY_SCAN_TOKEN_TYPE_IDENTIFIER)
- return NULL;
- if (!strcmp (curtoken->data.string, "if")) type = SCRIPT_OP_TYPE_IF;
- else if (!strcmp (curtoken->data.string,
- "while")) type = SCRIPT_OP_TYPE_WHILE;
+ if (ply_scan_token_is_identifier_of_value (curtoken, "if"))
+ type = SCRIPT_OP_TYPE_IF;
+ else if (ply_scan_token_is_identifier_of_value (curtoken, "while"))
+ type = SCRIPT_OP_TYPE_WHILE;
else return NULL;
curtoken = ply_scan_get_next_token (scan);
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != '('))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, '('))
{
script_parse_error (curtoken,
"Expected a '(' at the start of a condition block");
script_parse_error (curtoken, "Expected a valid condition expression");
return NULL;
}
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != ')'))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, ')'))
{
script_parse_error (curtoken,
"Expected a ')' at the end of a condition block");
curtoken = ply_scan_get_current_token (scan);
if ((type == SCRIPT_OP_TYPE_IF)
- && (curtoken->type == PLY_SCAN_TOKEN_TYPE_IDENTIFIER)
- && !strcmp (curtoken->data.string, "else"))
+ && (ply_scan_token_is_identifier_of_value (curtoken, "else")))
{
ply_scan_get_next_token (scan);
else_op = script_parse_op (scan);
{
ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
- if (curtoken->type != PLY_SCAN_TOKEN_TYPE_IDENTIFIER)
- return NULL;
- if (strcmp (curtoken->data.string, "for")) return NULL;
+ if (!ply_scan_token_is_identifier_of_value (curtoken, "for")) return NULL;
curtoken = ply_scan_get_next_token (scan);
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != '('))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, '('))
{
script_parse_error (curtoken,
"Expected a '(' at the start of a condition block");
return NULL;
}
curtoken = ply_scan_get_current_token (scan);
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != ';'))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, ';'))
{
script_parse_error (curtoken,
"Expected a ';' after the first 'for' expression");
return NULL;
}
curtoken = ply_scan_get_current_token (scan);
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != ';'))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, ';'))
{
script_parse_error (curtoken, "Expected a ';' after the 'for' condition");
return NULL;
return NULL;
}
curtoken = ply_scan_get_current_token (scan);
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != ')'))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, ')'))
{
script_parse_error (curtoken, "Expected a ')' at the end of a for block");
return NULL;
{
ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
- if (curtoken->type != PLY_SCAN_TOKEN_TYPE_IDENTIFIER)
- return NULL;
- if (strcmp (curtoken->data.string, "fun")) return NULL;
+ if (!ply_scan_token_is_identifier_of_value (curtoken, "fun")) return NULL;
curtoken = ply_scan_get_next_token (scan);
- if (curtoken->type != PLY_SCAN_TOKEN_TYPE_IDENTIFIER)
+ if (!ply_scan_token_is_identifier (curtoken))
{
script_parse_error (curtoken,
"A function declaration requires a valid name");
static script_op_t *script_parse_return (ply_scan_t *scan)
{
ply_scan_token_t *curtoken = ply_scan_get_current_token (scan);
-
- if (curtoken->type != PLY_SCAN_TOKEN_TYPE_IDENTIFIER)
- return NULL;
script_op_type_t type;
- if (!strcmp (curtoken->data.string, "return")) type = SCRIPT_OP_TYPE_RETURN;
- else if (!strcmp (curtoken->data.string, "break")) type = SCRIPT_OP_TYPE_BREAK;
- else if (!strcmp (curtoken->data.string, "continue")) type = SCRIPT_OP_TYPE_CONTINUE;
+ if (ply_scan_token_is_identifier_of_value (curtoken, "return"))
+ type = SCRIPT_OP_TYPE_RETURN;
+ else if (ply_scan_token_is_identifier_of_value (curtoken, "break"))
+ type = SCRIPT_OP_TYPE_BREAK;
+ else if (ply_scan_token_is_identifier_of_value (curtoken, "continue"))
+ type = SCRIPT_OP_TYPE_CONTINUE;
else return NULL;
curtoken = ply_scan_get_next_token (scan);
curtoken = ply_scan_get_current_token (scan);
}
#ifdef WITH_SEMIES
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != ';'))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, ';'))
{
script_parse_error (curtoken, "Expected ';' after an expression");
return NULL;
if (!exp) return NULL;
curtoken = ply_scan_get_current_token (scan);
#ifdef WITH_SEMIES
- if ((curtoken->type != PLY_SCAN_TOKEN_TYPE_SYMBOL)
- || (curtoken->data.symbol != ';'))
+ if (!ply_scan_token_is_symbol_of_value (curtoken, ';'))
{
script_parse_error (curtoken, "Expected ';' after an expression");
return NULL;
{
ply_list_t *op_list = ply_list_new ();
- while (1)
+ while (true)
{
script_op_t *op = script_parse_op (scan);
if (!op) break;