Skip to content

Commit

Permalink
Merge pull request #456 from refaktor/multiliner
Browse files Browse the repository at this point in the history
renamed spreadsheet to table, added many tests to base, made info/doc…
  • Loading branch information
refaktor authored Jan 3, 2025
2 parents 7cba276 + 4335308 commit eefafae
Show file tree
Hide file tree
Showing 58 changed files with 15,345 additions and 7,189 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ range 1 10 |map { .fac } |print\csv
kind: "admin"
open sqlite://data.db |query { select * from user where kind = ?kind }
; returns: Spreadsheet of admins
; returns: Table of admins
read %name.txt |fix { "Anonymous" } |post* https://example.com/postname 'text
; makes HTTP post of the name read from a file, or "Anonymous" if file failed to be read
Expand All @@ -117,7 +117,7 @@ These pages are littered with examples. You can find them on this **README** pag

Rye's focus is also interactive use. Check out these asciinema demos:

* **[Spreadsheet and CSV demo](https://asciinema.org/a/647708)** - new
* **[Table and CSV demo](https://asciinema.org/a/647708)** - new
* [Exploring JSON](https://asciinema.org/a/615327)
* [Testing vector functions](https://asciinema.org/a/575970)

Expand Down
4 changes: 2 additions & 2 deletions _sandbox/unorthodoxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ some general conventions everyone is already used to.
* **Adjectives** usually return boolean results (is-hot, is-cold, is-red) and start with "is-"
* **Nouns** starting with "is-" also return boolean result (is-integer, is-email, is-zero)
* **Nouns** ending with **?** stand for **get-**. Usually it's used when a **noun** is a property (length?, color?, age?)
* **Nouns** that are types or kinds in the language are constructors (fn, context, dict, list, spreadsheet)
* **Nouns** that are types or kinds in the language are constructors (fn, context, dict, list, table)

More conventions

Expand Down Expand Up @@ -123,7 +123,7 @@ Blocks are like lists or arrays, but also all Rye code lives in blocks and you s

Context is another datatypes of Rye that is heavily used by the language itself. All code is executed in a context.

## Spreadsheet datatype
## Table datatype

Some languages claim that they are high level languages. I claim for Rye, that it's even higher (than usual) level language. For one, if language want's to be higher level it should also have higher level structures. Higher
usually means more towards the human. So I believe structures should also be speaking more about human's view on information, than some computer science concept ...
Expand Down
101 changes: 77 additions & 24 deletions cmd/rbit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import (
"go/parser"
"go/token"
"os"
"regexp"
"strings"
)

// data that we want to optionally extract from builtins code and store as a general structure that
// * Rye runtime will be able to provide to the user
// * Test tool will run tests on
type builtinSection struct {
name string
docstring string
builtins []builtinInfo
}

type builtinInfo struct {
name string // from key value
gentype string // optional from key value
Expand Down Expand Up @@ -44,13 +51,14 @@ func getCommentsAboveKey(fset *token.FileSet, comments []*ast.CommentGroup, keyP
}

// Helper function to get comments above the map key
func parseCommentsAboveKey(input string, info *builtinInfo) builtinInfo {
func parseCommentsAboveKey(input string, info *builtinInfo) (builtinInfo, *builtinSection) {

const (
inDoc = iota
inTests
inExamples
inArgs
x
)
position := inDoc

Expand All @@ -59,16 +67,24 @@ func parseCommentsAboveKey(input string, info *builtinInfo) builtinInfo {
// Step 1: Split input into lines and trim whitespace
lines := strings.Split(strings.TrimSpace(input), "\n")

var section *builtinSection

// Step 2: Separate header and tests
var headerLines []string
// var testLines []string

// fmt.Println("!!!!!!!!!!!!!!!**************")

re := regexp.MustCompile(`^##### ([A-Za-z0-9 ]+)#####\s+"([^"]*)"`)

for _, line := range lines {
line = strings.TrimSpace(line) // Remove leading and trailing whitespace
// fmt.Println("LLLL:" + line)
// fmt.Println(line)
match := re.FindStringSubmatch(line)
if match != nil {
section = &builtinSection{match[1], match[2], make([]builtinInfo, 0)}
}
switch line {
case "Tests:":
position = inTests
Expand All @@ -94,27 +110,42 @@ func parseCommentsAboveKey(input string, info *builtinInfo) builtinInfo {
}
// Step 3: Combine the header lines into a single string
info.doc = strings.Join(headerLines, "\n")
return *info

return *info, section
}

func outputInfo(infos []builtinInfo) {
fmt.Println("section \"base\" \"base text\" {\n") // name
for _, info := range infos {
if len(info.tests) > 0 {
fmt.Printf("\tgroup %s \n", info.name) // name
fmt.Printf("\t\"%s\"\n", info.docstring) // docstring
func outputInfo(sections *[]builtinSection) {
for _, section := range *sections {
fmt.Printf("section \"%s\" \"%s\" {\n", section.name, section.docstring) // name
for _, info := range section.builtins {
if len(info.tests) > 0 {
fmt.Printf("\tgroup \"%s\" \n", strings.Replace(info.name, "\\\\", "\\", -1)) // name
fmt.Printf("\t\"%s\"\n", info.docstring) // docstring

fmt.Print("\t{\n") // args
for _, t := range info.args {
fmt.Println("\t\targ \"" + t + "\"")
}
fmt.Println("\t}\n")

fmt.Print("\t{\n") // args
for _, t := range info.args {
fmt.Println("\t\targ \"" + t + "\"")
fmt.Print("\t{\n")
for _, t := range info.tests {
fmt.Println("\t\t" + t)
}
fmt.Println("\t}\n")
}
fmt.Println("\t}\n")
}
fmt.Println("}\n")
}
}

fmt.Print("\t{\n")
for _, t := range info.tests {
fmt.Println("\t\t" + t)
func outputMissing(sections *[]builtinSection) {
fmt.Println("missing {") // name
for _, section := range *sections {
for _, info := range section.builtins {
if len(info.tests) == 0 {
fmt.Printf("\t %s %q\n", info.name, info.docstring) // docstring
}
fmt.Println("\t}\n")
}
}
fmt.Println("}\n")
Expand All @@ -134,9 +165,10 @@ func outputStats(cnt counters) {

var (
// fileName = flag.String("fiimle", "", "Path to the Rye file (default: none)")
stats = flag.Bool("stats", false, "Show stats about builtins file")
ls = flag.Bool("ls", false, "List builtins files")
help = flag.Bool("help", false, "Displays this help message.")
stats = flag.Bool("stats", false, "Show stats about builtins file")
ls = flag.Bool("ls", false, "List builtins files")
missing = flag.Bool("missing", false, "Lists functions missing the tests")
help = flag.Bool("help", false, "Displays this help message.")
)

func main() {
Expand All @@ -162,6 +194,9 @@ func main() {
if flag.NFlag() == 0 && flag.NArg() == 0 {
flag.Usage()
os.Exit(0)
} else if *help {
flag.Usage()
os.Exit(0)
} else if *ls {
fmt.Println("TODO 1")
} else {
Expand All @@ -173,7 +208,9 @@ func main() {
func doParsing(args []string) {
/// ###

infoList := make([]builtinInfo, 0)
stemp := make([]builtinSection, 0)
sectionList := &stemp
// infoList := make([]builtinInfo, 0)

if len(args) < 1 {
fmt.Println("File argument missing")
Expand All @@ -194,6 +231,10 @@ func doParsing(args []string) {

c := counters{0, 0, 0, 0}

var section *builtinSection

section = &builtinSection{"Default", "", make([]builtinInfo, 0)}

// Traverse the AST and find map literals
ast.Inspect(node, func(n ast.Node) bool {
switch x := n.(type) {
Expand All @@ -210,34 +251,46 @@ func doParsing(args []string) {
c.functions = c.functions + 1
/// fmt.Printf("Key: %s\n", key.Value)
// TODO NEXT - parse key into two values
info.name = key.Value
info.name = key.Value[1 : len(key.Value)-1]
// Get comments above the key
comment := getCommentsAboveKey(fset, node.Comments, key.Pos())
if comment != "" {
/// fmt.Printf("Comment above key: %s\n", strings.TrimSpace(comment))
info = parseCommentsAboveKey(comment, &info)
info, tempSection := parseCommentsAboveKey(comment, &info)
if tempSection != nil {
// fmt.Println(tempSection)
if len(section.builtins) > 0 {
*sectionList = append(*sectionList, *section)
}
section = tempSection
}
if len(info.tests) > 0 {
c.tested_functions = c.tested_functions + 1
c.tests = c.tests + len(info.tests)
}
}
}
}
infoList = append(infoList, info)
section.builtins = append(section.builtins, info)
}
}
}
return true
})

// fmt.Println(section)
*sectionList = append(*sectionList, *section)

// fmt.Println(infoList)

// fmt.Println("===================================================")

if *stats {
outputStats(c)
} else if *missing {
outputMissing(sectionList)
} else {
outputInfo(infoList)
outputInfo(sectionList)
}

// fmt.Println("===================================================")
Expand Down
4 changes: 2 additions & 2 deletions env/idxs.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ var NativeTypes = [...]string{ // Todo change to BuiltinTypes
"CPath",
"Xword",
"EXword",
"Spreadsheet",
"Table",
"Email",
"Kind",
"Kindword",
"Converter",
"Time",
"SpreadsheetRowType",
"TableRowType",
"Decimal",
"Vector",
"OpCPath",
Expand Down
4 changes: 2 additions & 2 deletions env/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ const (
CPathType Type = 24
XwordType Type = 25
EXwordType Type = 26
SpreadsheetType Type = 27
TableType Type = 27
EmailType Type = 28
KindType Type = 29
KindwordType Type = 30
ConverterType Type = 31
TimeType Type = 32
SpreadsheetRowType Type = 33
TableRowType Type = 33
DecimalType Type = 34
VectorType Type = 35
OpCPathType Type = 36
Expand Down
Loading

0 comments on commit eefafae

Please sign in to comment.