-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8acb131
commit 4b379c3
Showing
6 changed files
with
46 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package tofu.parser | ||
|
||
import tofu.reader.findLineStart | ||
import tofu.variables.{readVariable_str_safe, readVariable_int_safe} | ||
import tofu.{debugMessage, debug_printSeq, closeTofu} | ||
import tofu.runner.conditionElements | ||
import tofu.variables.getVariableProperties | ||
|
||
private def verifyCode(script: Seq[String], start_keyword: String, end_keyword: String, start_count: Int = 0, end_count: Int = 0, i: Int = 0): Boolean = | ||
if i >= script.length then start_count == end_count | ||
else | ||
val more_start = if startsWith_strict(script(i), start_keyword) then 1 else 0 | ||
val more_end = if startsWith_strict(script(i), end_keyword) then 1 else 0 | ||
verifyCode(script, start_keyword, end_keyword, start_count + more_start, end_count + more_end, i+1) | ||
|
||
def verifyFunctions(script: Seq[String]): Boolean = verifyCode(script, "function", "end") | ||
def verifyIfs(script: Seq[String]): Boolean = verifyCode(script, "if", "endif") | ||
def verifyWhile(script: Seq[String]): Boolean = verifyCode(script, "while", "endwhile") | ||
|
||
private def verifyCondition(line: String, isIF: Boolean): Boolean = | ||
val start = if isIF then findLineStart(line, 2) else findLineStart(line, 5) //for while loops | ||
if start == -1 || conditionElements(line, start).length == 0 then false | ||
else true | ||
|
||
def verifyConditions(script: Seq[String]) = | ||
for s <- script do | ||
if startsWith_strict(s, "if") && !verifyCondition(s, true) then | ||
closeTofu(s"Syntax error! If statement condition at line\n$s\nLacks elements and an operator to compare them to!") | ||
|
||
def verifyWhileCondition(script: Seq[String]) = | ||
for s <- script do | ||
if startsWith_strict(s, "while") && !verifyCondition(s, false) then | ||
closeTofu(s"Syntax error! While loop condition at line\n$s\nLacks elements and an operator to compare them to!") |
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
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
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