Compare commits

...

2 Commits

Author SHA1 Message Date
e2ce25aa24 🐐 snippets 2026-04-16 20:17:19 +02:00
b24134ae4e 🐐 LONGITVDO on strings 2026-04-16 18:26:17 +02:00
31 changed files with 22 additions and 99 deletions

View File

@@ -191,9 +191,9 @@ Skips the rest of the current loop body and continues to the next iteration (`DV
Breaks out of the current loop (`DVM` or `PER`). Has no meaningful return value.
### LONGITVDO
`LONGITVDO array`
`LONGITVDO array` or `LONGITVDO string`
Returns the length of `array` as an integer.
Returns the length of `array` (element count) or `string` (character count) as an integer.
## Modules
Modules are additions to the base `CENTVRION` syntax. They add or change certain features. Modules are included in your code by having

View File

@@ -909,9 +909,9 @@ class BuiltIn(Node):
raise CentvrionError("FORTIS_ELECTIONIS: cannot select from an empty array")
return vtable, lst[random.randint(0, len(lst) - 1)]
case "LONGITVDO":
if not isinstance(params[0], ValList):
raise CentvrionError("LONGITVDO requires an array")
return vtable, ValInt(len(params[0].value()))
if isinstance(params[0], (ValList, ValStr)):
return vtable, ValInt(len(params[0].value()))
raise CentvrionError("LONGITVDO requires an array or string")
case "EVERRO":
print("\033[2J\033[H", end="", flush=True)
return vtable, ValNul()

View File

@@ -481,9 +481,10 @@ CentValue cent_avdi_numerus(void) {
}
CentValue cent_longitudo(CentValue v) {
if (v.type != CENT_LIST)
cent_type_error("'LONGITVDO' requires a list");
return cent_int(v.lval.len);
if (v.type == CENT_LIST) return cent_int(v.lval.len);
if (v.type == CENT_STR) return cent_int((long)strlen(v.sval));
cent_type_error("'LONGITVDO' requires a list or string");
return cent_null(); /* unreachable; silences warning */
}
CentValue cent_fortis_numerus(CentValue lo, CentValue hi) {

View File

@@ -4,14 +4,12 @@ CVM FORS
DESIGNA correct VT FORTIS_NVMERVS(I,C)
DESIGNA gvess VT NVLLVS
DVM FALSITAS FACE {
DVM correct EST gvess FACE {
DESIGNA gvess VT AVDI_NVMERVS()
SI gvess MINVS correct TVNC {
DICE("Too low!")
} ALVID SI gvess PLVS correct TVNC {
DICE("Too high!")
} ALVID {
ERVMPE
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -3,15 +3,13 @@ CVM FORS
DESIGNA correct VT FORTIS_NVMERVS(I,C)
DESIGNA gvess VT NVLLVS
DVM FALSITAS FACE {
DESIGNA gvess VT AVDI_NVMERVS()
SI gvess MINVS correct TVNC {
DICE("Too low!")
} ALVID SI gvess PLVS correct TVNC {
DICE("Too high!")
} ALVID {
ERVMPE
}
DVM correct EST gvess FACE {
DESIGNA gvess VT AVDI_NVMERVS()
SI gvess MINVS correct TVNC {
DICE("Too low!")
} ALVID SI gvess PLVS correct TVNC {
DICE("Too high!")
}
}
DICE("You guessed correctly!")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

@@ -1,77 +0,0 @@
%YAML 1.2
---
name: Centvrion
file_extensions:
- cent
scope: source.centvrion
contexts:
main:
- include: comments
- include: strings
- include: fractions
- include: numerals
- include: constants
- include: builtins
- include: modules
- include: keywords
- include: operators
- include: identifiers
comments:
- match: '//[^\n]*'
scope: comment.line.centvrion
- match: '/\*'
scope: comment.block.centvrion
push:
- meta_scope: comment.block.centvrion
- match: '\*/'
pop: true
strings:
- match: '"'
scope: string.quoted.double.centvrion
push:
- meta_scope: string.quoted.double.centvrion
- match: '"'
pop: true
- match: "'"
scope: string.quoted.single.centvrion
push:
- meta_scope: string.quoted.single.centvrion
- match: "'"
pop: true
fractions:
- match: '\b[IVXLCDM][IVXLCDM_]*(?:S[S:.|]*|:[S:.|]+|\.[S:.|]*)'
scope: constant.numeric.fraction.centvrion
- match: '(?<![IVXLCDM_])(?:S[S:.|]+|:[S:.|]+)'
scope: constant.numeric.fraction.centvrion
numerals:
- match: '\b[IVXLCDM][IVXLCDM_]*\b'
scope: constant.numeric.centvrion
constants:
- match: '\b(VERITAS|FALSITAS|NVLLVS)\b'
scope: constant.language.centvrion
builtins:
- match: '\b(AVDI_NVMERVS|AVDI|DICE|FORTIS_NVMERVS|FORTIS_ELECTIONIS|LONGITVDO)\b'
scope: support.function.builtin.centvrion
modules:
- match: '\b(FORS|FRACTIO|MAGNVM|SVBNVLLA)\b'
scope: support.class.module.centvrion
keywords:
- match: '\b(ALVID|AVT|DEFINI|DESIGNA|DONICVM|DVM|ERVMPE|EST|ET|FACE|INVOCA|IN|MINVS|NON|PER|PLVS|REDI|SI|TVNC|VSQVE|VT|CVM)\b'
scope: keyword.control.centvrion
operators:
- match: '[+\-*/&]'
scope: keyword.operator.centvrion
identifiers:
- match: '[abcdefghiklmnopqrstvxyz_]+'
scope: variable.other.centvrion

View File

@@ -10,11 +10,11 @@ contexts:
- include: comments
- include: strings
- include: fractions
- include: keywords
- include: numerals
- include: constants
- include: builtins
- include: modules
- include: keywords
- include: operators
- include: identifiers

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@@ -388,6 +388,9 @@ builtin_tests = [
("CVM FORS\nFORTIS_NVMERVS(I, X)", Program([ModuleCall("FORS")], [ExpressionStatement(BuiltIn("FORTIS_NVMERVS", [Numeral("I"), Numeral("X")]))]), ValInt(3)),
("AVDI()", Program([], [ExpressionStatement(BuiltIn("AVDI", []))]), ValStr("hello"), "", ["hello"]),
("LONGITVDO([I, II, III])", Program([], [ExpressionStatement(BuiltIn("LONGITVDO", [DataArray([Numeral("I"), Numeral("II"), Numeral("III")])]))]), ValInt(3)),
("LONGITVDO([])", Program([], [ExpressionStatement(BuiltIn("LONGITVDO", [DataArray([])]))]), ValInt(0)),
('LONGITVDO("salve")', Program([], [ExpressionStatement(BuiltIn("LONGITVDO", [String("salve")]))]), ValInt(5)),
('LONGITVDO("")', Program([], [ExpressionStatement(BuiltIn("LONGITVDO", [String("")]))]), ValInt(0)),
("CVM FORS\nFORTIS_ELECTIONIS([I, II, III])", Program([ModuleCall("FORS")], [ExpressionStatement(BuiltIn("FORTIS_ELECTIONIS", [DataArray([Numeral("I"), Numeral("II"), Numeral("III")])]))]), ValInt(1)),
]