Skip to content

Commit

Permalink
implemented stdlib struct decls and fixed log operator
Browse files Browse the repository at this point in the history
  • Loading branch information
NotLe0n committed Jan 9, 2024
1 parent acddf92 commit 1cb5d26
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 15 deletions.
10 changes: 5 additions & 5 deletions assets/css/md-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,25 @@
vertical-align: inherit;
}

#artikel .duden-func {
#artikel .duden-obj {
border-bottom: 1px solid #aaa;
padding: 0.5em;
padding-right: 0;
margin-bottom: 1rem;
}

#artikel .duden-func[open] {
#artikel .duden-obj[open] {
border: none;
}

#artikel .duden-func-inner {
#artikel .duden-obj-inner {
margin-left: 5px;
border-left: #aaa solid 1px;
border-bottom: 1px solid #aaa;
border-bottom-left-radius: 1rem;
}

#artikel .duden-func blockquote {
#artikel .duden-obj blockquote {
white-space: pre;
margin: 0 0 0 -1px;
border-left: #aaa solid 1px;
Expand All @@ -104,7 +104,7 @@
text-wrap: wrap;
}

#artikel .duden-func-data {
#artikel .duden-obj-data {
overflow-x: auto;
margin: 0 0 1rem 1rem
}
Expand Down
2 changes: 1 addition & 1 deletion content/DE/Programmierung/Operatoren.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ in diesen und späteren Tabellen jeweils der C-Operator dabei.
| Rest | `a modulo b` | `a % b` | Zahl | Zahl | Zahl | `16 modulo 12` | 4 |
| Potenzieren | `a hoch b` | `pow(a, b)` | numerisch | numerisch | Kommazahl | `2 hoch 8` | 256,0 |
| Wurzelziehen | `die a. Wurzel von b` | `pow(a, 1/b)` | numerisch | numerisch | Kommazahl | `die 2. Wurzel von 9` | 3,0 |
| Logarithmus | `der Logarithmus mit der Basis a von b` | `log10(b) / log10(a)` | numerisch | numerisch | Kommazahl | `der Logarithmus von 100 zur Basis 10` | 2,0 |
| Logarithmus | `der Logarithmus von b zur Basis a` | `log10(b) / log10(a)` | numerisch | numerisch | Kommazahl | `der Logarithmus von 100 zur Basis 10` | 2,0 |
| Bit-Verschiebung nach links | `a um b Bit nach links verschoben` | `a << b` | Zahl | Zahl | Zahl | `7 um 3 Bit nach links verschoben` | 56 |
| Bit-Verschiebung nach rechts | `a um b Bit nach rechts verschoben` | `a >> b` | Zahl | Zahl | Zahl | `70 um 2 Bit nach rechts verschoben` | 17 |
| Logische UND verknüpfung | `a logisch und b` | `a&b` | Zahl | Zahl | Zahl | `5 logisch und 2` | 0 |
Expand Down
2 changes: 1 addition & 1 deletion content/EN/Programmierung/Operatoren.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ To make finding a specific operator easier for readers who already know a progra
| Remainder | `a modulo b` | `a % b` | Zahl | Zahl | Zahl | `16 modulo 12` | 4 |
| Exponentiation | `a hoch b` | `pow(a, b)` | numeric | numeric | Kommazahl | `2 hoch 8` | 256 |
| Root | `die a. Wurzel von b` | `pow(a, 1/b)` | numeric | numeric | Kommazahl | `die 2. Wurzel von 9` | 3 |
| Logarithm | `der Logarithmus mit der Basis a von b` | `log10(b) / log10(a)` | numeric | numeric | Kommazahl | `der Logarithmus von 100 zur Basis 10`| 2 |
| Logarithm | `der Logarithmus von b zur Basis a` | `log10(b) / log10(a)` | numeric | numeric | Kommazahl | `der Logarithmus von 100 zur Basis 10`| 2 |
| Left Bit-Shift | `a um b Bit nach links verschoben` | `a << b` | Zahl | Zahl | Zahl | `7 um 3 Bit nach links verschoben` | 56 |
| Right Bit-Shift | `a um b Bit nach rechts verschoben` | `a >> b` | Zahl | Zahl | Zahl | `70 um 2 Bit nach rechts verschoben` | 17 |
| AND gate | `a logisch und b` | `a&b` | Zahl | Zahl | Zahl | `5 logisch und 2` | 0 |
Expand Down
53 changes: 48 additions & 5 deletions gen/stdlib-generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ var nameMap = map[string]map[string]string{
"type": "Typ",
"var": "Variablen",
"func": "Funktionen",
"comb": "Kombinationen",
"moduleEmpty": "Dieses Modul ist Leer",
},
"EN": {
"type": "Type",
"var": "variables",
"func": "functions",
"comb": "combinations",
"moduleEmpty": "This module is empty",
},
}
Expand Down Expand Up @@ -62,7 +64,8 @@ func main() {
panicIfErr(clearDirectory(outputDirDe))

// get all files in directory
resp, err := http.Get("https://api.github.com/repos/DDP-Projekt/Kompilierer/contents/lib/stdlib/Duden/")
branch := "master"
resp, err := http.Get("https://api.github.com/repos/DDP-Projekt/Kompilierer/contents/lib/stdlib/Duden?ref=" + branch)
panicIfErr(err)
defer resp.Body.Close()

Expand All @@ -74,7 +77,7 @@ func main() {
outputPathDe := filepath.Join(outputDirDe, strings.Replace(entry.Name, "ddp", "md", 1))
outputPathEn := filepath.Join(outputDirEn, strings.Replace(entry.Name, "ddp", "md", 1))

resp, err := http.Get("https://raw.githubusercontent.com/DDP-Projekt/Kompilierer/master/" + entry.Path)
resp, err := http.Get("https://raw.githubusercontent.com/DDP-Projekt/Kompilierer/" + branch + "/" + entry.Path)
panicIfErr(err)
defer resp.Body.Close()
inputFile, err := io.ReadAll(resp.Body)
Expand Down Expand Up @@ -122,8 +125,9 @@ func MakeMdFiles(inputFile []byte, outputFilePath, lang string) {
func writeMD(inputFile string, outputFile *os.File, publicDecls []ast.Declaration, lang string) {
funcBldr := &bytes.Buffer{}
varBldr := &bytes.Buffer{}
structBldr := &bytes.Buffer{}

hasVars, hasFuncs := false, false
hasStructs, hasVars, hasFuncs := false, false, false

for _, decl := range publicDecls {
switch decl := decl.(type) {
Expand Down Expand Up @@ -183,15 +187,54 @@ func writeMD(inputFile string, outputFile *os.File, publicDecls []ast.Declaratio
hasVars = true

fmt.Fprintf(varBldr, "## %s\n", decl.Name())
fmt.Fprintf(varBldr, "* %s: `%s`\n", nameMap[lang]["type"], decl.Type)
fmt.Fprintf(varBldr, "* %s: <code>%s</code>\n", nameMap[lang]["type"], decl.Type)
fmt.Fprintln(varBldr, "")
case *ast.StructDecl:
panic("TODO: implement struct decl")
hasStructs = true

fields := ""
for _, field := range decl.Fields {
switch field := field.(type) {
case *ast.VarDecl:
if field.Public() {
inputStr := strings.Split(inputFile, "\n")
declRange := field.GetRange()
declCode := inputStr[declRange.Start.Line-1][declRange.Start.Column-1 : declRange.End.Column]
fields += html.EscapeString(declCode) + "|"
}
default:
}
}
fields = strings.TrimRight(fields, "|")

descr := ""
if decl.Comment() != nil {
descr = strings.Replace(strings.Trim(decl.Comment().String(), "[] \r\n"), "\t", "", -1)
descr = html.EscapeString(descr)
descr = strings.ReplaceAll(descr, "\r", "")
descr = strings.ReplaceAll(descr, "\n", "<br>")
descr = strings.ReplaceAll(descr, "\"", "\\\"")
}

aliases := ""
for i, alias := range decl.Aliases {
aliases += strings.Trim(alias.Original.Literal, "\"\n")
if i+1 < len(decl.Aliases) {
aliases += "\\\""
}
}

fmt.Fprintf(structBldr, "{{< duden-combination name=\"%s\" desc=\"%s\" fields=\"%s\" aliases=\"%s\" >}}\n\n", // }}"
decl.Name(), descr, fields, aliases)
}
}

fileName := strings.Replace(filepath.Base(outputFile.Name()), ".md", "", 1)
fmt.Fprintf(outputFile, "+++\ntitle = \"%s\"\nweight = 1\ntype = \"article\"\n+++\n", fileName)
if hasStructs {
fmt.Fprintf(outputFile, "# Duden/%s %s\n", fileName, nameMap[lang]["comb"])
fmt.Fprintln(outputFile, structBldr)
}
if hasVars {
fmt.Fprintf(outputFile, "# Duden/%s %s\n", fileName, nameMap[lang]["var"])
fmt.Fprintln(outputFile, varBldr)
Expand Down
31 changes: 31 additions & 0 deletions layouts/shortcodes/duden-combination.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<details class="duden-obj">
{{ $name := .Get "name" }}
<summary id="{{ $name }}"><h2>{{ .Get "name" }}</h2></summary>
<div class="duden-obj-inner">
{{ with .Get "desc" }}
<blockquote>{{ . | safeHTML }}</blockquote>
{{ end }}
<div class="duden-obj-data">
<ul>
{{ with .Get "fields" }}
{{ $fields := split . "|"}}
{{ range $fields }}
<li><code>{{ . | htmlUnescape }}</code></li>
{{ end }}
{{ end }}
</ul>

<h3>{{ i18n "aliases" }}</h3>
<ol>
{{ with .Get "aliases" }}
{{ $aliases := split . "\"" }} <!--"}}-->
{{ range $aliases}}
<li><code>{{ . }}</code></li>
{{ end }}
{{ else}}
<p>Keine Aliase definiert</p>
{{ end}}
</ol>
</div>
</div>
</details>
6 changes: 3 additions & 3 deletions layouts/shortcodes/duden-function.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<details class="duden-func">
<details class="duden-obj">
{{ $name := .Get "name" }}
<summary id="{{ $name }}"><h2>{{ .Get "name" }}</h2></summary>
<div class="duden-func-inner">
<div class="duden-obj-inner">
{{ with .Get "desc" }}
<blockquote>{{ . | safeHTML }}</blockquote>
{{ end }}
<div class="duden-func-data">
<div class="duden-obj-data">
<ul>
{{ with .Get "params" }}
<li>{{ i18n "params"}}: {{ . | safeHTML }}</li>
Expand Down

0 comments on commit 1cb5d26

Please sign in to comment.