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
032cfacc
Commit
032cfacc
authored
Feb 26, 2024
by
mohamad.alturky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding transpiler functionality
parent
ecfe9d6e
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
296 additions
and
113 deletions
+296
-113
bridge.go
src/languages/bridge.go
+0
-12
main.go
src/main.go
+146
-98
rs.go
src/rs.go
+55
-0
analysis.go
src/tokenization/analysis.go
+1
-1
parsing.go
src/tokenization/parsing.go
+1
-1
abstractions.go
src/transpilation/abstractions.go
+5
-0
transpiler.go
src/transpilation/transpiler.go
+85
-0
data.donut
templates/data.donut
+3
-1
No files found.
src/languages/bridge.go
deleted
100644 → 0
View file @
ecfe9d6e
package
Languages
import
(
Types
"donut/types"
)
type
Bridge
struct
{
TemplateCodeHandler
Types
.
TextToTextConverter
InjectCodeHandler
Types
.
TextToTextConverter
MainFunctionHandler
Types
.
TextAppendUtil
ImportsHandler
Types
.
TextAppendUtil
}
src/main.go
View file @
032cfacc
package
main
import
(
Tokenizer
"donut/tokenization"
"github.com/TwiN/go-color"
FileManagement
"donut/fileManagement"
Transpilation
"donut/transpilation"
)
func
main
()
{
...
...
@@ -22,6 +21,7 @@ func main() {
code
}}
text
@exec
{{ 11111111
...
...
@@ -32,113 +32,161 @@ func main() {
}}
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"))
@define {{
f()===>
}}
@import {{
"fmt"
}}
`
result
:=
Transpilation
.
BuildTranspiler
(
template
)
.
GetExecutable
()
FileManagement
.
WriteFile
(
"./rs.go"
,
result
)
}
// package main
// // A simple program demonstrating the paginator component from the Bubbles
// // component library.
// import (
// "fmt"
// "log"
// "strings"
// Tokenizer "donut/tokenization"
// "github.com/charmbracelet/bubbles/paginator"
// "github.com/charmbracelet/lipgloss"
// tea "github.com/charmbracelet/bubbletea"
// "github.com/TwiN/go-color"
// )
// 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 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
// }
// 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")
// res := Tokenizer.ConvertNestingToConcatenation(startingIdx, template, "exec", "template")
// startingIdx = res.TerminatedAt
// new = new + res.Template
// }
// b.WriteString(" " + m.paginator.View())
// b.WriteString("\n\n h/l ←/→ page • q: quit\n")
// return b.String()
// // 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"))
// }
// func main() {
// p := tea.NewProgram(newModel())
// if _, err := p.Run(); err != nil {
// log.Fatal(err)
// }
// }
// // 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)
// // }
// // }
src/rs.go
0 → 100644
View file @
032cfacc
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
()
===>
src/tokenization/analysis.go
View file @
032cfacc
...
...
@@ -139,7 +139,7 @@ func GetDirectiveContentWithTerminationIndex(template string, directiveName stri
*/
directiveFinishedFrom
:=
loopIndex
+
2
return
Types
.
DirectiveContentSpecification
{
directiveContent
,
directiveFinishedFrom
}
return
Types
.
DirectiveContentSpecification
{
Content
:
directiveContent
,
TerminationIndex
:
directiveFinishedFrom
}
}
func
FindTerminationIndex
(
template
string
,
startingIndex
int
)
int
{
...
...
src/tokenization/parsing.go
View file @
032cfacc
...
...
@@ -172,5 +172,5 @@ func ConvertNestingToConcatenation(startAt int, template string, executeToken st
}
}
return
Types
.
RecursionResult
{
answer
,
terminationIndex
}
return
Types
.
RecursionResult
{
Template
:
answer
,
TerminatedAt
:
terminationIndex
}
}
src/transpilation/abstractions.go
0 → 100644
View file @
032cfacc
package
Transpilation
type
ITranspiler
interface
{
GetExecutable
()
func
()
}
src/transpilation/transpiler.go
0 → 100644
View file @
032cfacc
package
Transpilation
import
Tokenizer
"donut/tokenization"
type
Transpiler
struct
{
template
string
}
func
BuildTranspiler
(
template
string
)
Transpiler
{
return
Transpiler
{
template
:
template
}
}
func
(
transpiler
Transpiler
)
GetExecutable
()
string
{
importsParsingResult
:=
Tokenizer
.
ExtractDirectiveContent
(
transpiler
.
template
,
"@import"
)
transpiler
.
template
=
importsParsingResult
[
1
]
println
(
"transpiler.template"
)
println
(
transpiler
.
template
)
println
(
"transpiler.template"
)
importsContent
:=
importsParsingResult
[
0
]
println
(
importsContent
)
defineParsingResult
:=
Tokenizer
.
ExtractDirectiveContent
(
transpiler
.
template
,
"@define"
)
transpiler
.
template
=
defineParsingResult
[
1
]
defineContent
:=
defineParsingResult
[
0
]
println
(
defineContent
)
templateAfterAdjustingInjectables
:=
Tokenizer
.
ReplaceDirectiveContent
(
transpiler
.
template
,
"@inject"
,
returnInjectedString
)
transpiler
.
template
=
templateAfterAdjustingInjectables
println
(
"templateAfterAdjustingInjectables"
)
println
(
templateAfterAdjustingInjectables
)
println
(
"templateAfterAdjustingInjectables"
)
resultAfterReplacingNesting
:=
""
startingIdx
:=
0
for
{
println
(
startingIdx
)
if
startingIdx
==
len
(
transpiler
.
template
)
{
break
}
res
:=
Tokenizer
.
ConvertNestingToConcatenation
(
startingIdx
,
transpiler
.
template
,
"exec"
,
"template"
)
startingIdx
=
res
.
TerminatedAt
resultAfterReplacingNesting
=
resultAfterReplacingNesting
+
res
.
Template
}
transpiler
.
template
=
resultAfterReplacingNesting
templateSectionsParsed
:=
Tokenizer
.
ReplaceDirectiveContent
(
transpiler
.
template
,
"@template"
,
returnInjectedtemplate
)
transpiler
.
template
=
templateSectionsParsed
execSectionsParsed
:=
Tokenizer
.
ReplaceDirectiveContent
(
transpiler
.
template
,
"@exec"
,
returnCode
)
transpiler
.
template
=
execSectionsParsed
finalCode
:=
injectImports
(
importsContent
)
+
injectMain
(
transpiler
.
template
)
+
defineContent
return
finalCode
}
func
returnInjectedString
(
text
string
)
string
{
return
"
\n
Code = Code + string( "
+
text
+
" )
\n
"
}
func
returnInjectedtemplate
(
text
string
)
string
{
return
"
\n
Code = Code + string( `"
+
text
+
"`)
\n
"
}
func
returnCode
(
text
string
)
string
{
return
text
}
func
injectImports
(
imports
string
)
string
{
return
`
package main
import(
`
+
imports
+
`
)
`
}
func
injectMain
(
main
string
)
string
{
return
`
func main() {
Code := ""
`
+
main
+
`
}
`
}
templates/data.donut
View file @
032cfacc
...
...
@@ -2,7 +2,9 @@
"fmt"
}}
using Go;
@template {{
}}
public class Main
{
@exec {{
...
...
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