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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"github.com/jorenchik/mdemory/src/compiler/parser"
|
|
||||||
"github.com/jorenchik/mdemory/src/compiler/lexer"
|
"github.com/jorenchik/mdemory/src/compiler/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Compilation started...")
|
|
||||||
|
|
||||||
file, err := os.ReadFile(
|
file, err := os.ReadFile(
|
||||||
"/home/jorenchik/Code/mdemory/src/compiler/input.mdem",
|
"/home/jorenchik/Code/mdemory/src/compiler/input.mdem",
|
||||||
)
|
)
|
||||||
@@ -22,17 +20,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
fileContents := string(file)
|
fileContents := string(file)
|
||||||
|
|
||||||
tokens, err := lexer.TokenizeMdem([]rune(fileContents))
|
fmt.Println("Compilation started...")
|
||||||
if err != nil {
|
_, err = api.Compile(fileContents)
|
||||||
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = parser.ParseQuestions(tokens)
|
|
||||||
if (err != nil) {
|
|
||||||
fmt.Println(err.Error())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Compilation completed")
|
fmt.Println("Compilation completed")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package lexer
|
package lexer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -6,11 +6,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var buffer []rune
|
var buffer []rune
|
||||||
var row int32 = 1
|
var row int32
|
||||||
var column int32 = 1
|
var column int32
|
||||||
var previousRow int32 = -1
|
var previousRow int32
|
||||||
var previousColumn int32 = -1
|
var previousColumn int32
|
||||||
var textStarted bool = false
|
var textStarted bool
|
||||||
|
|
||||||
type TokenType int
|
type TokenType int
|
||||||
const (
|
const (
|
||||||
@@ -92,8 +92,18 @@ func makeTokenWithTokenBuffer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TokenizeMdem(fileRunes []rune) ( []Token, error ) {
|
func TokenizeMdem(fileRunes []rune) ( []Token, error ) {
|
||||||
tokens = []Token{}
|
tokens = []Token{}
|
||||||
buffer = []rune{}
|
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++ {
|
for i := 0; i < len(fileRunes); i++ {
|
||||||
c := fileRunes[i]
|
c := fileRunes[i]
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ module github.com/jorenchik/mdemory/src/mdemory-app-qt
|
|||||||
|
|
||||||
go 1.23.0
|
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
|
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"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/jorenchik/mdemory/src/compiler/api"
|
||||||
"github.com/therecipe/qt/core"
|
"github.com/therecipe/qt/core"
|
||||||
"github.com/therecipe/qt/widgets"
|
"github.com/therecipe/qt/widgets"
|
||||||
)
|
)
|
||||||
@@ -36,13 +37,32 @@ func main() {
|
|||||||
mdemList.HideColumn(2)
|
mdemList.HideColumn(2)
|
||||||
mdemList.HideColumn(3)
|
mdemList.HideColumn(3)
|
||||||
mdemList.ConnectDoubleClicked(func(index *core.QModelIndex) {
|
mdemList.ConnectDoubleClicked(func(index *core.QModelIndex) {
|
||||||
item := model.FilePath(index)
|
if model.IsDir(index) {
|
||||||
widgets.QMessageBox_Information(
|
return
|
||||||
nil,
|
}
|
||||||
"Item Clicked",
|
filePath := model.FilePath(index)
|
||||||
"You clicked: " + item,
|
fileContents, err := os.ReadFile(filePath)
|
||||||
widgets.QMessageBox__Ok, widgets.QMessageBox__Ok,
|
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)
|
deckLabel := widgets.NewQLabel2("Decks", nil, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user