mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
basic integration of qt app and compiler though the api module
This commit is contained in:
20
src/compiler/api/api.go
Normal file
20
src/compiler/api/api.go
Normal 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
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"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))
|
||||
if err != nil {
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
@@ -92,8 +92,18 @@ func makeTokenWithTokenBuffer(
|
||||
}
|
||||
|
||||
func TokenizeMdem(fileRunes []rune) ( []Token, error ) {
|
||||
tokens = []Token{}
|
||||
buffer = []rune{}
|
||||
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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
nil,
|
||||
"Item Clicked",
|
||||
"You clicked: " + item,
|
||||
widgets.QMessageBox__Ok, widgets.QMessageBox__Ok,
|
||||
)
|
||||
if model.IsDir(index) {
|
||||
return
|
||||
}
|
||||
filePath := model.FilePath(index)
|
||||
fileContents, err := os.ReadFile(filePath)
|
||||
if (err != nil) {
|
||||
widgets.QMessageBox_Critical(
|
||||
nil,
|
||||
"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)
|
||||
|
||||
Reference in New Issue
Block a user