Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

chore: [#116]Validate the syntax in the Code Editor #141

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions src/components/editor/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,45 @@ registerElementSpecificationEntries(librarySpecification);
* @returns a `Promise` that returns whether the process was successful
*/
export function buildProgram(code: string): Promise<boolean> {
/**
* Validates the editor's code.
* @returns `true` if the editor's code is valid else `false`
*/
function checkValidity(): boolean {
/*
* dummy logic
*/
const lines = code.split('\n');
let previousIndentations = 0;
for (const line of lines) {
const units = line.split(' ');

let currentIndentations = 0;
for (let identationIndex = 0; identationIndex < units.length; identationIndex++) {
if (units[identationIndex] == '') {
currentIndentations++;
} else {
break;
}
}
if (
!(
units.length === 2 ||
units.length === 3 ||
(units.length === 4 && units[0] === '' && units[1] === '')
)
currentIndentations > previousIndentations &&
currentIndentations != previousIndentations + 2
) {
return false;
}
}
if (currentIndentations == units.length) {
return false;
}

previousIndentations = currentIndentations;
// const instructionName = units[currentIndentations];
for (let argIndex = currentIndentations + 1; argIndex < units.length; argIndex++) {
const argBreakingIndex = units[argIndex].indexOf(':');
if (argBreakingIndex == -1) {
return false;
}
// const argName = units[argIndex].slice(0, argBreakingIndex);
// const argValue = units[argIndex].slice(argBreakingIndex + 1);
}
}
return true;
}

Expand Down