-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move to Standard Go Project Layout
- Loading branch information
Houcine EL ADDALI
committed
Dec 18, 2023
1 parent
fad3808
commit 7d7b92d
Showing
15 changed files
with
78 additions
and
62 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,60 @@ | ||
package repl | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/houcine7/JIPL/internal/lexer" | ||
"github.com/houcine7/JIPL/internal/parser" | ||
) | ||
|
||
// REPL :Read --> Evaluate --> Print --> loop | ||
// the repl used to interact with users to read from console | ||
// and send to interpreter to evaluate then prints back the result | ||
|
||
/* | ||
* Function as the start method of the repl | ||
* To interact with the user via terminal | ||
*/ | ||
|
||
const PROMPT = ">" | ||
|
||
func Start(in io.Reader, out io.Writer) { | ||
scanner := bufio.NewScanner(in) | ||
|
||
fmt.Println(" ********** ") | ||
fmt.Println("------------- Welcome to JIPL REPL ------------") | ||
fmt.Println(" ********** ") | ||
|
||
for { | ||
fmt.Print(PROMPT) | ||
scanned := scanner.Scan() | ||
if !scanned { | ||
return | ||
} | ||
line := scanner.Text() | ||
|
||
if line == "exit" || line == "exit;" { | ||
break | ||
} | ||
|
||
replLexer := lexer.InitLexer(line) | ||
repParser := parser.InitParser(replLexer) | ||
|
||
pr := repParser.Parse() | ||
errs := repParser.Errors() | ||
|
||
if len(errs) != 0 { | ||
io.WriteString(out, fmt.Sprintf("%d errors ❌❌ occurred while parsing your input \n", len(errs))) | ||
for idx, e := range errs { | ||
io.WriteString(out, fmt.Sprintf("error number:%d with message: %s \n", idx, e)) | ||
} | ||
continue | ||
} | ||
|
||
io.WriteString(out, pr.ToString()) | ||
io.WriteString(out, "\n") | ||
|
||
} | ||
} |
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.