Avoid using this instance until migration is complete. For updates and information contact insert#0751

Commit 1f019062 authored by insert's avatar insert 🎺

Add a few string operations

parent 9341d979
......@@ -4,7 +4,7 @@ func square a {
return a * a;
}
n = 4;
n = 2;
r = square(n) 2 * n;
print 'n squared + 2n is' r;
......@@ -36,4 +36,13 @@ print '## WHILE';
while n != 2 {
print 'is not 2, removing 1, currently at:' n;
n = n - 1;
}
\ No newline at end of file
} else {
print 'already 2!';
}
print '## STRING OPERATIONS';
print('length of "aaa" is', str.len 'aaa';)
alpha = 'abcdefghijklmnopqrstuvwxyz';
print(str.sub alpha 18 1;, str.sub alpha 7 1;, str.sub alpha 20 1;, str.sub alpha 19 1;);
\ No newline at end of file
......@@ -66,6 +66,8 @@ export function Stack(tokens: Token[], override?: Store, assign: boolean = false
let token = getToken();
switch (token.lexicon) {
case Lexicon.TERMINATOR:
break;
case Lexicon.ALPHANUMERIC:
switch (token.body) {
case 'func':
......
......@@ -85,9 +85,10 @@ export function Lexicate(source: string): Token[] {
}
if (t === "'" || t === '"') {
if (state === State.SQ_STRING ||
state === State.DQ_STRING) {
state = State.NORMAL;
if (state === State.SQ_STRING || state === State.DQ_STRING) {
if ((state === State.SQ_STRING && t === "'")
|| (state === State.DQ_STRING && t === '"'))
state = State.NORMAL;
} else {
state = (t === "'" ? State.SQ_STRING : State.DQ_STRING);
tokens.push({
......
......@@ -58,6 +58,26 @@ const DEFAULT: Store = {
}
}
}
},
str: {
type: Type.FUNCTION,
native: (obj: any) => {
return '' + obj;
},
children: {
len: {
type: Type.FUNCTION,
native: (str: string) => {
return str.length;
}
},
sub: {
type: Type.FUNCTION,
native: (str: string, start: number, count: number) => {
return str.substr(start, count);
}
}
}
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment