basic integration of qt app and compiler though the api module

This commit is contained in:
jorenchik
2024-09-07 17:30:43 +03:00
parent 4028211a31
commit f2e3055bcd
5 changed files with 78 additions and 31 deletions

20
src/compiler/api/api.go Normal file
View File

@@ -0,0 +1,20 @@
package api
import (
"github.com/jorenchik/mdemory/src/compiler/lexer"
"github.com/jorenchik/mdemory/src/compiler/parser"
)
func Compile(fileContents string) ([]parser.Question, error) {
tokens, err := lexer.TokenizeMdem([]rune(fileContents))
if err != nil {
return nil, err
}
questions, err := parser.ParseQuestions(tokens)
if (err != nil) {
return nil, err
}
return questions, err
}

View File

@@ -3,13 +3,11 @@ package main
import (
"fmt"
"os"
"github.com/jorenchik/mdemory/src/compiler/parser"
"github.com/jorenchik/mdemory/src/compiler/lexer"
"github.com/jorenchik/mdemory/src/compiler/api"
)
func main() {
fmt.Println("Compilation started...")
file, err := os.ReadFile(
"/home/jorenchik/Code/mdemory/src/compiler/input.mdem",
)
@@ -22,17 +20,11 @@ func main() {
}
fileContents := string(file)
tokens, err := lexer.TokenizeMdem([]rune(fileContents))
fmt.Println("Compilation started...")
_, err = api.Compile(fileContents)
if err != nil {
fmt.Println(err.Error())
return
}
_, err = parser.ParseQuestions(tokens)
if (err != nil) {
fmt.Println(err.Error())
return
}
fmt.Println("Compilation completed")
}

View File

@@ -6,11 +6,11 @@ import (
)
var buffer []rune
var row int32 = 1
var column int32 = 1
var previousRow int32 = -1
var previousColumn int32 = -1
var textStarted bool = false
var row int32
var column int32
var previousRow int32
var previousColumn int32
var textStarted bool
type TokenType int
const (
@@ -94,6 +94,16 @@ func makeTokenWithTokenBuffer(
func TokenizeMdem(fileRunes []rune) ( []Token, error ) {
tokens = []Token{}
buffer = []rune{}
row = 1
column = 1
previousRow = -1
previousColumn = -1
textStarted = false
if (len(strings.Trim(string(fileRunes), " \n\t")) <= 0) {
return []Token{}, nil
}
for i := 0; i < len(fileRunes); i++ {
c := fileRunes[i]

View File

@@ -2,6 +2,11 @@ module github.com/jorenchik/mdemory/src/mdemory-app-qt
go 1.23.0
require github.com/therecipe/qt v0.0.0-20200904063919-c0c124a5770d
require (
github.com/jorenchik/mdemory/src/compiler v0.0.0-00010101000000-000000000000
github.com/therecipe/qt v0.0.0-20200904063919-c0c124a5770d
)
require github.com/gopherjs/gopherjs v0.0.0-20190411002643-bd77b112433e // indirect
replace github.com/jorenchik/mdemory/src/compiler => ../compiler

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"github.com/jorenchik/mdemory/src/compiler/api"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/widgets"
)
@@ -36,13 +37,32 @@ func main() {
mdemList.HideColumn(2)
mdemList.HideColumn(3)
mdemList.ConnectDoubleClicked(func(index *core.QModelIndex) {
item := model.FilePath(index)
widgets.QMessageBox_Information(
if model.IsDir(index) {
return
}
filePath := model.FilePath(index)
fileContents, err := os.ReadFile(filePath)
if (err != nil) {
widgets.QMessageBox_Critical(
nil,
"Item Clicked",
"You clicked: " + item,
widgets.QMessageBox__Ok, widgets.QMessageBox__Ok,
"Compilation error",
err.Error(),
widgets.QMessageBox__Ok,
widgets.QMessageBox__Ok,
)
return
}
_, err = api.Compile(string(fileContents))
if (err != nil) {
widgets.QMessageBox_Critical(
nil,
"Compilation error",
err.Error(),
widgets.QMessageBox__Ok,
widgets.QMessageBox__Ok,
)
}
})
deckLabel := widgets.NewQLabel2("Decks", nil, 0)