Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
D
Donut
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohamad.alturky
Donut
Commits
5a2e85ad
Commit
5a2e85ad
authored
Feb 29, 2024
by
mohamad.alturky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing input output
parent
f8c48d4b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
253 deletions
+73
-253
input.json
Transpiler/out/input.json
+4
-0
result.go
Transpiler/out/result.go
+31
-0
main.go
Transpiler/src/main.go
+11
-180
rs.go
Transpiler/src/rs.go
+0
-55
transpiler.go
Transpiler/src/transpilation/transpiler.go
+6
-4
data.donut
Transpiler/templates/data.donut
+21
-14
No files found.
Transpiler/out/input.json
0 → 100644
View file @
5a2e85ad
{
"Name"
:
"mohamad"
,
"Value"
:
342
}
\ No newline at end of file
Transpiler/out/result.go
0 → 100644
View file @
5a2e85ad
package
main
import
(
"encoding/json"
"fmt"
"log"
"os"
)
type
MyStruct
struct
{
Name
string
Value
int
}
func
main
()
{
filename
:=
"./input.json"
// Read the JSON file
fileContent
,
err
:=
os
.
ReadFile
(
filename
)
if
err
!=
nil
{
log
.
Fatal
(
"Error reading the file:"
,
err
)
}
var
data
MyStruct
err
=
json
.
Unmarshal
(
fileContent
,
&
data
)
if
err
!=
nil
{
log
.
Fatal
(
"Error unmarshaling JSON:"
,
err
)
}
fmt
.
Printf
(
"Name: %s, Value: %d
\n
"
,
data
.
Name
,
data
.
Value
)
}
Transpiler/src/main.go
View file @
5a2e85ad
...
@@ -3,190 +3,21 @@ package main
...
@@ -3,190 +3,21 @@ package main
import
(
import
(
FileManagement
"donut/fileManagement"
FileManagement
"donut/fileManagement"
Transpilation
"donut/transpilation"
Transpilation
"donut/transpilation"
"github.com/TwiN/go-color"
)
)
func
main
()
{
func
main
()
{
template
:=
`
println
(
color
.
Colorize
(
color
.
Blue
,
`
@template
{{
text
@exec
{{
code
@template
{{
text
}}
code
|‾‾‾‾‾‾‾‾\ |‾‾‾‾‾‾‾‾‾| |‾‾‾‾‾\ |‾‾| |‾‾| |‾‾| |‾‾‾‾‾‾‾‾‾‾‾‾|
}}
| |‾‾‾\ \ | |‾‾‾| | | |\ \ | | | | | | ‾‾‾‾| |‾‾‾‾
| | | | | | | | | | \ \| | | | | | | |
text
| |___/ / | |___| | | | \ | | |___| | | |
@exec
|________/ |_________| |__| \____| |_________| |__|
{{ 11111111
code
@template
{{
text
}}
code
}}
}}
`
))
template
:=
FileManagement
.
ReadData
(
"../templates/data.donut"
)
@define {{
f()===>
}}
@import {{
"fmt"
}}
`
result
:=
Transpilation
.
BuildTranspiler
(
template
)
.
GetExecutable
()
result
:=
Transpilation
.
BuildTranspiler
(
template
)
.
GetExecutable
()
FileManagement
.
WriteFile
(
".
/rs
.go"
,
result
)
FileManagement
.
WriteFile
(
".
./out/result
.go"
,
result
)
}
}
// package main
// import (
// Tokenizer "donut/tokenization"
// "github.com/TwiN/go-color"
// )
// func main() {
// template := `
// @template
// {{
// text
// @exec
// {{
// code
// @template
// {{
// text
// }}
// code
// }}
// text
// @exec
// {{ 11111111
// code
// @template
// {{
// text
// }}
// code
// }}
// }}
// `
// new := ""
// startingIdx := 0
// for {
// if startingIdx == len(template) {
// break
// }
// res := Tokenizer.ConvertNestingToConcatenation(startingIdx, template, "exec", "template")
// startingIdx = res.TerminatedAt
// new = new + res.Template
// }
// // println("------------------")
// // println(template2.Template)
// // println("------------------")
// // println(template2.TerminatedAt)
// // println("------------------")
// // println(len(template))
// println(color.Colorize(color.Blue, `
// |‾‾‾‾‾‾‾‾\ |‾‾‾‾‾‾‾‾‾| |‾‾‾‾‾\ |‾‾| |‾‾| |‾‾| |‾‾‾‾‾‾‾‾‾‾‾‾|
// | |‾‾‾\ \ | |‾‾‾| | | |\ \ | | | | | | ‾‾‾‾| |‾‾‾‾
// | | | | | | | | | | \ \| | | | | | | |
// | |___/ / | |___| | | | \ | | |___| | | |
// |________/ |_________| |__| \____| |_________| |__|
// `))
// println(new)
// // println(color.Colorize(color.Red, "This is also red"))
// }
// // package main
// // // A simple program demonstrating the paginator component from the Bubbles
// // // component library.
// // import (
// // "fmt"
// // "log"
// // "strings"
// // "github.com/charmbracelet/bubbles/paginator"
// // "github.com/charmbracelet/lipgloss"
// // tea "github.com/charmbracelet/bubbletea"
// // )
// // func newModel() model {
// // var items []string
// // for i := 1; i < 101; i++ {
// // text := fmt.Sprintf("Item %d", i)
// // items = append(items, text)
// // }
// // p := paginator.New()
// // p.Type = paginator.Dots
// // p.PerPage = 10
// // p.ActiveDot = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "235", Dark: "252"}).Render("•")
// // p.InactiveDot = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "250", Dark: "238"}).Render("•")
// // p.SetTotalPages(len(items))
// // return model{
// // paginator: p,
// // items: items,
// // }
// // }
// // type model struct {
// // items []string
// // paginator paginator.Model
// // }
// // func (m model) Init() tea.Cmd {
// // return nil
// // }
// // func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// // var cmd tea.Cmd
// // switch msg := msg.(type) {
// // case tea.KeyMsg:
// // switch msg.String() {
// // case "q", "esc", "ctrl+c":
// // return m, tea.Quit
// // }
// // }
// // m.paginator, cmd = m.paginator.Update(msg)
// // return m, cmd
// // }
// // func (m model) View() string {
// // var b strings.Builder
// // b.WriteString("\n Paginator Example\n\n")
// // start, end := m.paginator.GetSliceBounds(len(m.items))
// // for _, item := range m.items[start:end] {
// // b.WriteString(" • " + item + "\n\n")
// // }
// // b.WriteString(" " + m.paginator.View())
// // b.WriteString("\n\n h/l ←/→ page • q: quit\n")
// // return b.String()
// // }
// // func main() {
// // p := tea.NewProgram(newModel())
// // if _, err := p.Run(); err != nil {
// // log.Fatal(err)
// // }
// // }
Transpiler/src/rs.go
deleted
100644 → 0
View file @
f8c48d4b
package
main
import
(
"fmt"
)
func
main
()
{
Code
:=
""
Code
=
Code
+
string
(
`
text
`
)
code
Code
=
Code
+
string
(
`
text
`
)
code
Code
=
Code
+
string
(
`
text
`
)
11111111
code
Code
=
Code
+
string
(
`
text
`
)
code
Code
=
Code
+
string
(
`
`
)
}
f
()
===>
Transpiler/src/transpilation/transpiler.go
View file @
5a2e85ad
...
@@ -24,9 +24,11 @@ func (transpiler Transpiler) GetExecutable() string {
...
@@ -24,9 +24,11 @@ func (transpiler Transpiler) GetExecutable() string {
println
(
defineContent
)
println
(
defineContent
)
templateAfterAdjustingInjectables
:=
Tokenizer
.
ReplaceDirectiveContent
(
transpiler
.
template
,
"@inject"
,
returnInjectedString
)
templateAfterAdjustingInjectables
:=
Tokenizer
.
ReplaceDirectiveContent
(
transpiler
.
template
,
"@inject"
,
returnInjectedString
)
transpiler
.
template
=
templateAfterAdjustingInjectables
transpiler
.
template
=
templateAfterAdjustingInjectables
println
(
"templateAfterAdjustingInjectables"
)
// println("templateAfterAdjustingInjectables")
println
(
templateAfterAdjustingInjectables
)
// println(templateAfterAdjustingInjectables)
println
(
"templateAfterAdjustingInjectables"
)
// println("templateAfterAdjustingInjectables")
transpiler
.
template
=
"@template"
+
"{"
+
"{"
+
transpiler
.
template
+
"}}"
resultAfterReplacingNesting
:=
""
resultAfterReplacingNesting
:=
""
startingIdx
:=
0
startingIdx
:=
0
for
{
for
{
...
@@ -51,7 +53,7 @@ func (transpiler Transpiler) GetExecutable() string {
...
@@ -51,7 +53,7 @@ func (transpiler Transpiler) GetExecutable() string {
}
}
func
returnInjectedString
(
text
string
)
string
{
func
returnInjectedString
(
text
string
)
string
{
return
"
\n
Code = Code + string( "
+
text
+
" )
\n
"
return
"
@exec {"
+
"{
\n
Code = Code + string( "
+
text
+
" ) }}
\n
"
}
}
func
returnInjectedtemplate
(
text
string
)
string
{
func
returnInjectedtemplate
(
text
string
)
string
{
...
...
Transpiler/templates/data.donut
View file @
5a2e85ad
@import {{
using System;
"fmt"
}}
namespace Good;
using Go;
@template {{
@exec {{
file := "{get; set}"
}}
}}
public class Main
public class Transpiler
{
{
@exec {{
public int Id @inject {{ file }}
for i:= 0; i < 10; i++ {
@inject {{ "Go" }}
}
}}
}
}
@define {{
@define {{
func printCode(code string) {
println(code)
}
}}
@import {{
}}
@exec {{
printCode(Code)
}}
}}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment