🐐 NVMERVS
This commit is contained in:
@@ -1185,6 +1185,13 @@ class BuiltIn(Node):
|
||||
raise CentvrionError(f"Invalid numeral input: {raw!r}")
|
||||
case "AVDI":
|
||||
return vtable, ValStr(input())
|
||||
case "NVMERVS":
|
||||
if len(params) != 1:
|
||||
raise CentvrionError("NVMERVS takes exactly I argument")
|
||||
val = params[0]
|
||||
if not isinstance(val, ValStr):
|
||||
raise CentvrionError(f"NVMERVS expects a string, got {type(val).__name__}")
|
||||
return vtable, ValInt(num_to_int(val.value(), magnvm, svbnvlla))
|
||||
case "DIC":
|
||||
print_string = ' '.join(
|
||||
make_string(i, magnvm, svbnvlla) for i in params
|
||||
|
||||
@@ -297,6 +297,13 @@ def _emit_builtin(node, ctx):
|
||||
lines.append(f"cent_adivnge({param_vars[0]}, {param_vars[1]});")
|
||||
lines.append(f"CentValue {tmp} = cent_null();")
|
||||
|
||||
case "NVMERVS":
|
||||
if len(param_vars) != 1:
|
||||
lines.append(f'cent_runtime_error("NVMERVS takes exactly I argument");')
|
||||
lines.append(f"CentValue {tmp} = cent_null();")
|
||||
else:
|
||||
lines.append(f"CentValue {tmp} = cent_numerus({param_vars[0]});")
|
||||
|
||||
case "QVAERE":
|
||||
lines.append(f"CentValue {tmp} = cent_qvaere({param_vars[0]}, {param_vars[1]});")
|
||||
|
||||
|
||||
@@ -569,6 +569,12 @@ CentValue cent_avdi_numerus(void) {
|
||||
return cent_int(cent_roman_to_int(s.sval));
|
||||
}
|
||||
|
||||
CentValue cent_numerus(CentValue s) {
|
||||
if (s.type != CENT_STR)
|
||||
cent_type_error("'NVMERVS' expects a string");
|
||||
return cent_int(cent_roman_to_int(s.sval));
|
||||
}
|
||||
|
||||
CentValue cent_longitudo(CentValue v) {
|
||||
if (v.type == CENT_LIST) return cent_int(v.lval.len);
|
||||
if (v.type == CENT_STR) return cent_int((long)strlen(v.sval));
|
||||
|
||||
@@ -232,6 +232,7 @@ CentValue cent_ordina(CentValue lst); /* ORDINA */
|
||||
CentValue cent_lege(CentValue path); /* LEGE */
|
||||
void cent_scribe(CentValue path, CentValue content); /* SCRIBE */
|
||||
void cent_adivnge(CentValue path, CentValue content); /* ADIVNGE */
|
||||
CentValue cent_numerus(CentValue s); /* NVMERVS */
|
||||
CentValue cent_qvaere(CentValue pattern, CentValue text); /* QVAERE */
|
||||
CentValue cent_svbstitve(CentValue pattern, CentValue replacement, CentValue text); /* SVBSTITVE */
|
||||
CentValue cent_scinde(CentValue str, CentValue delim); /* SCINDE */
|
||||
|
||||
@@ -51,6 +51,7 @@ builtin_tokens = [("BUILTIN", i) for i in [
|
||||
"FORTVITVS_NVMERVS",
|
||||
"FORTVITA_ELECTIO",
|
||||
"LONGITVDO",
|
||||
"NVMERVS",
|
||||
"ORDINA",
|
||||
"SEMEN",
|
||||
"SENATVS",
|
||||
|
||||
@@ -346,20 +346,21 @@ class Parser():
|
||||
def parens(tokens):
|
||||
return tokens[1]
|
||||
|
||||
@self.pg.production('dict_items : ')
|
||||
@self.pg.production('dict_items : expression KEYWORD_VT expression')
|
||||
@self.pg.production('dict_items : expression KEYWORD_VT expression SYMBOL_COMMA dict_items')
|
||||
@self.pg.production('dict_items : expression KEYWORD_VT expression SYMBOL_COMMA opt_newline dict_items')
|
||||
def dict_items(calls):
|
||||
if len(calls) == 0:
|
||||
return []
|
||||
elif len(calls) == 3:
|
||||
if len(calls) == 3:
|
||||
return [(calls[0], calls[2])]
|
||||
else:
|
||||
return [(calls[0], calls[2])] + calls[4]
|
||||
return [(calls[0], calls[2])] + calls[5]
|
||||
|
||||
@self.pg.production('expression : KEYWORD_TABVLA SYMBOL_LCURL dict_items SYMBOL_RCURL')
|
||||
@self.pg.production('expression : KEYWORD_TABVLA SYMBOL_LCURL opt_newline SYMBOL_RCURL')
|
||||
def dict_literal_empty(tokens):
|
||||
return ast_nodes.DataDict([])
|
||||
|
||||
@self.pg.production('expression : KEYWORD_TABVLA SYMBOL_LCURL opt_newline dict_items opt_newline SYMBOL_RCURL')
|
||||
def dict_literal(tokens):
|
||||
return ast_nodes.DataDict(tokens[2])
|
||||
return ast_nodes.DataDict(tokens[3])
|
||||
|
||||
@self.pg.production('expression : SYMBOL_LBRACKET array_items SYMBOL_RBRACKET')
|
||||
def array(tokens):
|
||||
|
||||
Reference in New Issue
Block a user