Skip to content

Commit

Permalink
Merge pull request #36 from JMU-CS/new-category
Browse files Browse the repository at this point in the history
New category
  • Loading branch information
ChrisMayfield authored Aug 6, 2024
2 parents f182edc + 2285467 commit 1b073bb
Show file tree
Hide file tree
Showing 9 changed files with 633 additions and 139 deletions.
1 change: 1 addition & 0 deletions archive/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ main {
display: flex; /* Add this */
flex-direction: row; /* Add this */
flex-basis: 25%;
user-select: all;
}

.output {
Expand Down
1 change: 1 addition & 0 deletions public/themes.css
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ body:not(.embed) #bottom-part {
flex-direction: row-reverse;
/* Add this */
flex-basis: 25%;
user-select: text;
}

.output {
Expand Down
8 changes: 4 additions & 4 deletions src/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -1692,12 +1692,12 @@ class Praxly_String_funccall {
case StringFuncs.CONTAINS:
var char = await this.args[0].evaluate(environment);
this.typecheckhelper(char, [TYPES.STRING, TYPES.CHAR]);
result = str.includes(char.value)
result = str.value.includes(char.value);
return new Praxly_boolean(result);
case StringFuncs.INDEXOF:
var index = await this.args[0].evaluate(environment);
this.typecheckhelper(char, [TYPES.CHAR]);
result = str.value.indexOf(index.value);
var substr = await this.args[0].evaluate(environment);
this.typecheckhelper(substr, [TYPES.STRING, TYPES.CHAR]);
result = str.value.indexOf(substr.value);
return new Praxly_int(result);
case StringFuncs.LENGTH:
return new Praxly_int(str.value.length);
Expand Down
134 changes: 124 additions & 10 deletions src/blocks2tree.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Blockly from 'blockly';
import { NODETYPES, TYPES } from './common';
import { NODETYPES, StringFuncs, TYPES } from './common';

function containsOnlyNumbers(str) {
return /^-?\d+$/.test(str);
Expand Down Expand Up @@ -637,25 +637,139 @@ export const makeGenerator = () => {
})
}

praxlyGenerator['praxly_StringFunc_block'] = (block) => {
// praxlyGenerator['praxly_StringFunc_block'] = (block) => {
// const expression = block.getInputTargetBlock('EXPRESSION');
// var procedureName = block.getFieldValue('FUNCTYPE');
// var args = block.getInputTargetBlock('PARAMS');
// var argschildren = args.getChildren(true);
// var argsList = [];
// argschildren.forEach(element => {
// argsList.push(praxlyGenerator[element.type](element));
// });
// return customizeMaybe(block, {
// blockID: block.id,
// type: NODETYPES.SPECIAL_STRING_FUNCCALL,
// left: praxlyGenerator[expression.type](expression),
// right: {
// name: procedureName,
// args: argsList,
// type: NODETYPES.FUNCCALL
// }
// });
// }

praxlyGenerator['praxly_charAt_block'] = (block) => {
const procedureName = StringFuncs.CHARAT;
const expression = block.getInputTargetBlock('EXPRESSION');
var procedureName = block.getFieldValue('FUNCTYPE');
var args = block.getInputTargetBlock('PARAMS');
var argschildren = args.getChildren(true);
var argsList = [];
argschildren.forEach(element => {
argsList.push(praxlyGenerator[element.type](element));
const index = block.getInputTargetBlock('INDEX');
return customizeMaybe(block, {
blockID: block.id,
name : procedureName,
type: NODETYPES.SPECIAL_STRING_FUNCCALL,
left: praxlyGenerator[expression.type](expression),
right: {
name: procedureName,
args: [praxlyGenerator[index.type](index)],
type: NODETYPES.FUNCCALL
}
});
}

praxlyGenerator['praxly_contains_block'] = (block) => {
const procedureName = StringFuncs.CONTAINS;
const expression = block.getInputTargetBlock('EXPRESSION');
const param = block.getInputTargetBlock('PARAM');
return customizeMaybe(block, {
blockID: block.id,
name: procedureName,
type: NODETYPES.SPECIAL_STRING_FUNCCALL,
left: praxlyGenerator[expression.type](expression),
right: {
name: procedureName,
args: argsList,
args: [praxlyGenerator[param.type](param)],
type: NODETYPES.FUNCCALL
}
})
});
}

praxlyGenerator['praxly_indexOf_block'] = (block) => {
const procedureName = StringFuncs.INDEXOF;
const expression = block.getInputTargetBlock('EXPRESSION');
const param = block.getInputTargetBlock('PARAM');
return customizeMaybe(block, {
blockID: block.id,
name: procedureName,
type: NODETYPES.SPECIAL_STRING_FUNCCALL,
left: praxlyGenerator[expression.type](expression),
right: {
name: procedureName,
args: [praxlyGenerator[param.type](param)],
type: NODETYPES.FUNCCALL
}
});
}

praxlyGenerator['praxly_length_block'] = (block) => {
const procedureName = StringFuncs.LENGTH;
const expression = block.getInputTargetBlock('EXPRESSION');
return customizeMaybe(block, {
blockID: block.id,
name: procedureName,
type: NODETYPES.SPECIAL_STRING_FUNCCALL,
left: praxlyGenerator[expression.type](expression),
right: {
name: procedureName,
args: []
}
});
}

praxlyGenerator['praxly_substring_block'] = (block) => {
const procedureName = StringFuncs.SUBSTRING;
const expression = block.getInputTargetBlock('EXPRESSION');
const param1 = block.getInputTargetBlock('PARAM1');
const param2 = block.getInputTargetBlock('PARAM2');
return customizeMaybe(block, {
blockID: block.id,
name: procedureName,
type: NODETYPES.SPECIAL_STRING_FUNCCALL,
left: praxlyGenerator[expression.type](expression),
right: {
name: procedureName,
args: [praxlyGenerator[param1.type](param1), praxlyGenerator[param2.type](param2)],
type: NODETYPES.FUNCCALL
}
});
}

praxlyGenerator['praxly_toLowerCase_block'] = (block) => {
const procedureName = StringFuncs.TOLOWERCSE;
const expression = block.getInputTargetBlock('EXPRESSION');
return customizeMaybe(block, {
blockID: block.id,
name: procedureName,
type: NODETYPES.SPECIAL_STRING_FUNCCALL,
left: praxlyGenerator[expression.type](expression),
right: {
name: procedureName,
args: []
}
});
}

praxlyGenerator['praxly_toUpperCase_block'] = (block) => {
const procedureName = StringFuncs.TOUPPERCASE;
const expression = block.getInputTargetBlock('EXPRESSION');
return customizeMaybe(block, {
blockID: block.id,
name: procedureName,
type: NODETYPES.SPECIAL_STRING_FUNCCALL,
left: praxlyGenerator[expression.type](expression),
right: {
name: procedureName,
args: []
}
});
}

return praxlyGenerator;
Expand Down
Loading

0 comments on commit 1b073bb

Please sign in to comment.