Created
May 18, 2020 17:29
-
-
Save amazzalel-habib/1c71ed9631a3f83572d942017cecc4da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
format(code: string): string{ | |
// if the code contains errors, no need to format, because this way of formating the code, will remove some of the code | |
// to make things simple, we only allow formatting a valide code | |
if(this.validate(code).length > 0) | |
return code; | |
let formattedCode = ""; | |
const ast: TodoExpressionsContext = parseAndGetASTRoot(code); | |
ast.children.forEach(node => { | |
if (node instanceof AddExpressionContext) { | |
// if a Add expression : ADD TODO "STRING" | |
const todo = node.STRING().text; | |
formattedCode += `ADD TODO ${todo}\n`; | |
}else if(node instanceof CompleteExpressionContext) { | |
// If a Complete expression: COMPLETE TODO "STRING" | |
const todoToComplete = node.STRING().text; | |
formattedCode += `COMPLETE TODO ${todoToComplete}\n`; | |
} | |
}); | |
return formattedCode; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment