Skip to content

Commit

Permalink
patch the repaet highight
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrBarghouthi committed Nov 16, 2018
1 parent 0df9ad4 commit 154e637
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
13 changes: 5 additions & 8 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,10 @@ class CommandArg {
}
break;
case ARGUMENT_TYPES.COMMANDS:
this.validator = (str)=>{
let p = new Parser(str);
try{
p.parse()
}catch{
return false;
}
this.validator = (str,offset)=>{
let p = new Parser(str,null,offset);

p.parse()
return true;
}
break;
Expand Down Expand Up @@ -147,7 +144,7 @@ class CommandExecutor {
}
}
parseExpression(ExpressionString) {
let p = new Parser(ExpressionString);
let p = new Parser(ExpressionString,null);
let token = p.nextToken();
let next = p.nextToken();
let e;
Expand Down
23 changes: 16 additions & 7 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ class Parser {
* @param {Function} afterCmdCallback Function to execute after the commands are executed
* @memberof Parser
*/
constructor(text, afterCmdCallback) {
constructor(text, afterCmdCallback,offset = 0) {
if (!text) text = '';

this.text = text.trimRight();
this.index = 0;
this.afterCmdCallback = afterCmdCallback
this.offset = offset;
}

/**
Expand Down Expand Up @@ -102,11 +103,19 @@ class Parser {
let theArgToken = this.getArgs();
let endIndex = this.index + 1;
if (arg.validator !== undefined) {
if (!arg.validator(theArgToken)) {
console.error(`Argument number ${i} (${theArgToken}) is invalid for command ${token}`);
let valid;
if(arg.type == ARGUMENT_TYPES.COMMANDS)
{
while(this.text.length>startIndex & this.text[startIndex++]!='[');
console.log({arg:theArgToken,offset:startIndex});
valid = arg.validator(theArgToken,startIndex+this.offset)
}else
valid = arg.validator(theArgToken);
if (!valid) {
console.error(`Argument number ${i} (${theArgToken}) is invalid for command ${token} parser offset ${this.offset}`);
throw {
startIndex: startIndex,
endIndex: endIndex
startIndex: startIndex+this.offset,
endIndex: endIndex+this.offset
}
}
args.push(theArgToken);
Expand All @@ -120,8 +129,8 @@ class Parser {
}else {
let endIndex = this.index + 1;
throw {
startIndex: cmdStrat,
endIndex: endIndex
startIndex: cmdStrat+this.offset,
endIndex: endIndex+this.offset
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ function goTurtle() {
}
} catch (err) {
showError(err.startIndex,err.endIndex);
console.log(err);

}

pop();
Expand Down

0 comments on commit 154e637

Please sign in to comment.