Overview of DQL (DOM Query Language)
mainNodeSet, which is lazily evaluated to ensure low memory usage and efficient composition.repository·main·Indexed 27 days ago
https://github.com/goplus/xgoA programming language built on a Go foundation designed to bridge the gap between engineering and natural language. XGo provides a unified ecosystem to integrate C/C++, Python, and JavaScript/TypeScript, allowing developers to mix standard Go (.go) and XGo (.xgo) source files in the same package. It includes DQL (DOM Query Language) for querying structured data like JSON, HTML, and ASTs, and supports specialized classfiles such as yap for HTTP web frameworks, spx for 2D game engines, and gsh for DevOps shell scripting.
NodeSet, which is lazily evaluated to ensure low memory usage and efficient composition.In XGo, commands, function calls, and operators are all conceptually function invocations. You can express intent using three different syntactic styles:
+, *, ==) which are actually function calls in disguise.Example of the three styles:
echo "Hello" // Command style
echo("Hello") // Function call style
3 + 4 // Operator styleA slice (also referred to as a list) is a dynamically-sized, flexible view into the elements of an array. Slices are composed of three parts:
Unlike arrays, slices can grow and shrink dynamically.
XGo applies a specific code style transformation to Go code. The formatter converts standard Go syntax into a specialized XGo syntax characterized by the removal of boilerplate, the use of built-in primitives instead of the fmt package, and a command-style execution pattern.
Key transformations include:
package main and func main are stripped.fmt package calls are replaced with built-in functions like echo, print, printf, and errorf.gox.mod is a module configuration file used exclusively by class framework packages to define how their class system is structured. It is not used in ordinary XGo application projects.
Key functions of gox.mod:
main.spx $\rightarrow$ Game).xgo/parser.Note: For backward compatibility, the legacy name gop.mod and the gop directive are still supported.
XGo is a programming language designed for engineering, STEM education, and data science. It is built on a Go foundation but features a syntax that approaches natural language expression. Key capabilities include:
echo "text" instead of fmt.Println("text")) and reduces boilerplate like package main and func main.XGo and Go serve different primary purposes and target different user groups:
XGo := C * Go * Python * JavaScript + Scratch.XGo supports several common patterns for manipulating slices using traditional loops and the <- operator:
if to append to a new slice.i, v in nums to find a target value and its index.len(nums) - 1 to 0.seen := {}) to track encountered values.... to append multiple slices: merged <- a....<- for push/enqueue and slicing/indexing for pop/dequeue.nums[i:i + windowSize] within a loop.// Merging multiple slices
a := [1, 2, 3]
b := [4, 5, 6]
merged := []
merged <- a...
merged <- b...
// Using a slice as a stack (Push/Pop)
stack := []
stack <- 1 // Push
if len(stack) > 0 {
top := stack[len(stack) - 1]
stack = stack[:len(stack) - 1] // Pop
}
// Sliding Window
windowSize := 3
for i := 0; i <= len(nums) - windowSize; i++ {
window := nums[i:i + windowSize]
}import keyword. You can also alias imported modules to avoid naming conflicts or for brevity.The XGo MiniSpec recommends a streamlined approach to data and behavior by avoiding struct in favor of a combination of tuple and classfile:
This approach aims to reduce conceptual overhead by providing a cleaner model than the overlapping constructs found in standard Go.
To run an example using the llgo command instead of the standard go command, you must first set the XGO_GOCMD environment variable. After setting the variable, use xgo run . to execute the project.
export XGO_GOCMD=llgo
xgo run .XGo supports two styles of function and method calls. While traditional parentheses are supported, XGo recommends command-style syntax for a cleaner, shell-like appearance.
echo("Hello world")
fmt.Println("Hello, world")Omit parentheses and use a space between the identifier and arguments:
echo "Hello world"
fmt.Println "Hello, world"
os.Exit 1Use the ... operator to pass variadic arguments:
echo elements...echo "Hello world"
fmt.Println "Hello, world"
os.Exit 1