rip-lang 2.9.0 → 2.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/README.md +32 -2
- package/docs/BROWSER.md +8 -8
- package/docs/GUIDE.md +13 -13
- package/docs/INTERNALS.md +11 -11
- package/docs/RATIONALE.md +180 -0
- package/docs/REACTIVITY.md +5 -5
- package/docs/TYPES.md +1132 -0
- package/docs/dist/rip.browser.js +12 -36
- package/docs/dist/rip.browser.min.js +87 -87
- package/docs/dist/rip.browser.min.js.br +0 -0
- package/docs/examples/README.md +21 -142
- package/docs/examples/arrows.rip +3 -13
- package/docs/examples/module.rip +41 -31
- package/docs/examples/reactivity.rip +48 -0
- package/package.json +1 -1
- package/src/compiler.js +13 -3
- package/src/grammar/grammar.rip +3 -3
- package/src/grammar/solar.rip +2 -2
- package/src/lexer.js +0 -59
- package/src/parser.js +1 -1
- package/docs/PHILOSOPHY.md +0 -569
- package/docs/WHY-NOT-COFFEESCRIPT.md +0 -186
- package/docs/WHY-YES-RIP.md +0 -757
- package/docs/examples/object-syntax.rip +0 -74
- package/docs/examples/prototype.rip +0 -30
- package/docs/examples/sexpr.rip +0 -128
- package/docs/examples/use-loader.js +0 -9
- package/docs/examples/utils.rip +0 -20
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
# Object Syntax Features Demo
|
|
2
|
-
|
|
3
|
-
# Feature 1: Property shorthand
|
|
4
|
-
def makePoint(x, y, z)
|
|
5
|
-
{x, y, z}
|
|
6
|
-
|
|
7
|
-
# Feature 2: Implicit braces (single line)
|
|
8
|
-
config = host: "localhost", port: 8080, debug: true
|
|
9
|
-
|
|
10
|
-
# Feature 3: Multiline objects (with braces)
|
|
11
|
-
person = {
|
|
12
|
-
name: "Alice"
|
|
13
|
-
age: 30
|
|
14
|
-
city: "NYC"
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
# Feature 4: Nested objects (arbitrary depth!)
|
|
18
|
-
data = {
|
|
19
|
-
user: {
|
|
20
|
-
profile: {
|
|
21
|
-
name: "Bob"
|
|
22
|
-
email: "bob@example.com"
|
|
23
|
-
}
|
|
24
|
-
settings: {
|
|
25
|
-
theme: "dark"
|
|
26
|
-
notifications: true
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
meta: {
|
|
30
|
-
version: "1.0"
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
# Feature 5: Arrays in objects
|
|
35
|
-
config = {
|
|
36
|
-
servers: ["prod", "dev", "staging"]
|
|
37
|
-
ports: [8080, 8081, 8082]
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
# Feature 6: Objects in arrays
|
|
41
|
-
users = [
|
|
42
|
-
{name: "Alice", age: 30}
|
|
43
|
-
{name: "Bob", age: 25}
|
|
44
|
-
]
|
|
45
|
-
|
|
46
|
-
# Feature 7: Complex nesting (arbitrary depth!)
|
|
47
|
-
appConfig = {
|
|
48
|
-
database: {
|
|
49
|
-
hosts: ["db1", "db2"]
|
|
50
|
-
options: {ssl: true, timeout: 5000}
|
|
51
|
-
}
|
|
52
|
-
cache: {
|
|
53
|
-
servers: ["cache1", "cache2"]
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
# Feature 8: Arrow functions in objects (methods!)
|
|
58
|
-
calculator = {
|
|
59
|
-
add: (a, b) => a + b
|
|
60
|
-
multiply: (a, b) => a * b
|
|
61
|
-
power: (a, b) => a ** b
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
# Feature 9: Combined - shorthand + methods + nested
|
|
65
|
-
def createUser(id, name, role)
|
|
66
|
-
{
|
|
67
|
-
id
|
|
68
|
-
name
|
|
69
|
-
role
|
|
70
|
-
active: true
|
|
71
|
-
created: Date.now()
|
|
72
|
-
greet: (msg) => "Hello, ${msg}!"
|
|
73
|
-
}
|
|
74
|
-
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Prototype Shortcuts - :: and ?::
|
|
2
|
-
|
|
3
|
-
# Access prototype directly
|
|
4
|
-
stringProto = String::
|
|
5
|
-
arrayProto = Array::
|
|
6
|
-
|
|
7
|
-
# Access prototype methods
|
|
8
|
-
toString = Boolean::toString
|
|
9
|
-
charAt = String::charAt
|
|
10
|
-
|
|
11
|
-
# Use prototype methods
|
|
12
|
-
result = toString.call(true)
|
|
13
|
-
console.log("Boolean true:", result)
|
|
14
|
-
|
|
15
|
-
# Add methods to prototypes
|
|
16
|
-
String::reverse = ->
|
|
17
|
-
@split('').reverse().join('')
|
|
18
|
-
|
|
19
|
-
console.log("hello".reverse())
|
|
20
|
-
|
|
21
|
-
# Optional prototype access (safe)
|
|
22
|
-
constructor = Array
|
|
23
|
-
method = constructor?::push
|
|
24
|
-
console.log("Has push:", method != undefined)
|
|
25
|
-
|
|
26
|
-
# Works with any object
|
|
27
|
-
MyClass = class MyClass
|
|
28
|
-
constructor: ->
|
|
29
|
-
MyClass::customMethod = ->
|
|
30
|
-
"Added via ::"
|
package/docs/examples/sexpr.rip
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env rip
|
|
2
|
-
|
|
3
|
-
# Compact S-Expression Formatter
|
|
4
|
-
# Optimized for Rip's s-expression structure
|
|
5
|
-
|
|
6
|
-
# Operators and forms that should ALWAYS be inline (using Set for faster lookup)
|
|
7
|
-
INLINE_FORMS = new Set([
|
|
8
|
-
'.', '?.', '::', '?::', '[]', '?[]', 'optindex', 'optcall' # Property access
|
|
9
|
-
'+', '-', '*', '/', '%', '**', '//', '%%' # Arithmetic
|
|
10
|
-
'==', '!=', '<', '>', '<=', '>=', '===', '!==' # Comparison
|
|
11
|
-
'&&', '||', '??', '&', '|', '^', '<<', '>>', '>>>' # Logical/bitwise
|
|
12
|
-
'rest', 'default', '...', 'expansion' # Params
|
|
13
|
-
])
|
|
14
|
-
|
|
15
|
-
# Check if array should be inline (parens) [shows use of def vs -> function]
|
|
16
|
-
def isInline(arr)
|
|
17
|
-
return false unless Array.isArray(arr)
|
|
18
|
-
return false if arr.length is 0
|
|
19
|
-
|
|
20
|
-
# Special forms always inline (handle String objects from parser)
|
|
21
|
-
head = arr[0]?.valueOf?() ?? arr[0]
|
|
22
|
-
return true if INLINE_FORMS.has(head)
|
|
23
|
-
|
|
24
|
-
# Small arrays with no nesting
|
|
25
|
-
arr.length <= 4 and not arr.some(Array.isArray)
|
|
26
|
-
|
|
27
|
-
# Format atom (non-array element)
|
|
28
|
-
# Pass indent for multi-line strings
|
|
29
|
-
formatAtom = (elem, indent = 0) ->
|
|
30
|
-
return '(???)' if Array.isArray(elem)
|
|
31
|
-
return String(elem) if typeof elem is 'number'
|
|
32
|
-
return '""' if elem is ''
|
|
33
|
-
|
|
34
|
-
str = String(elem)
|
|
35
|
-
|
|
36
|
-
# Handle multi-line regexes (heregex) - collapse to single line
|
|
37
|
-
if str[0] is '/' and str.indexOf('\n') >= 0
|
|
38
|
-
# Extract flags from end
|
|
39
|
-
match = str.match(/\/([gimsuvy]*)$/)
|
|
40
|
-
flags = if match then match[1] else ''
|
|
41
|
-
|
|
42
|
-
# Strip the regex delimiters and flags
|
|
43
|
-
content = str.slice(1) # Remove leading /
|
|
44
|
-
if flags
|
|
45
|
-
content = content.slice(0, -flags.length - 1) # Remove /flags
|
|
46
|
-
else
|
|
47
|
-
content = content.slice(0, -1) # Remove trailing /
|
|
48
|
-
|
|
49
|
-
# Remove whitespace and comments (heregex processing)
|
|
50
|
-
lines = content.split('\n')
|
|
51
|
-
cleaned = for line in lines
|
|
52
|
-
# Strip comments (# to end of line) and whitespace
|
|
53
|
-
line.replace(/#.*$/, '').trim()
|
|
54
|
-
|
|
55
|
-
# Join and rebuild regex with quotes (it's a string value)
|
|
56
|
-
processed = cleaned.join('')
|
|
57
|
-
return '"/' + processed + '/' + flags + '"'
|
|
58
|
-
|
|
59
|
-
str
|
|
60
|
-
|
|
61
|
-
# Main formatter
|
|
62
|
-
toSexpr = (arr, indent = 0, isTopLevel = false) ->
|
|
63
|
-
return formatAtom(arr) unless Array.isArray(arr)
|
|
64
|
-
|
|
65
|
-
# Inline: use parentheses
|
|
66
|
-
if isInline(arr)
|
|
67
|
-
parts = []
|
|
68
|
-
for elem in arr
|
|
69
|
-
if Array.isArray(elem)
|
|
70
|
-
parts.push(toSexpr(elem, 0, false))
|
|
71
|
-
else
|
|
72
|
-
parts.push(formatAtom(elem))
|
|
73
|
-
return '(' + parts.join(' ') + ')'
|
|
74
|
-
|
|
75
|
-
# Block: use indentation
|
|
76
|
-
lines = []
|
|
77
|
-
spaces = ' '.repeat(indent)
|
|
78
|
-
|
|
79
|
-
# Special handling for program node
|
|
80
|
-
if isTopLevel and arr[0] is 'program'
|
|
81
|
-
lines = ['(program ' + formatAtom(arr[1], 0)]
|
|
82
|
-
for elem, i in arr when i > 1
|
|
83
|
-
# Each child at indent 2
|
|
84
|
-
childFormatted = toSexpr(elem, 2, false)
|
|
85
|
-
# If child is inline, it has no indent - add it
|
|
86
|
-
if childFormatted[0] is '('
|
|
87
|
-
childFormatted = ' ' + childFormatted
|
|
88
|
-
lines.push(childFormatted)
|
|
89
|
-
lines.push(')') # Close the program on its own line
|
|
90
|
-
return lines.join('\n')
|
|
91
|
-
|
|
92
|
-
# Block: use indentation WITH parens
|
|
93
|
-
# All s-expressions use parens, just multi-line layout
|
|
94
|
-
|
|
95
|
-
# Build the opening with first element
|
|
96
|
-
if Array.isArray(arr[0])
|
|
97
|
-
head = toSexpr(arr[0], 0, false)
|
|
98
|
-
else
|
|
99
|
-
head = formatAtom(arr[0], indent)
|
|
100
|
-
|
|
101
|
-
lines.push(spaces + '(' + head)
|
|
102
|
-
|
|
103
|
-
# Add remaining elements
|
|
104
|
-
for elem, i in arr when i > 0
|
|
105
|
-
if Array.isArray(elem)
|
|
106
|
-
formatted = toSexpr(elem, indent + 2, false)
|
|
107
|
-
if isInline(elem)
|
|
108
|
-
# Inline - append to last line
|
|
109
|
-
lines[lines.length - 1] += ' ' + formatted
|
|
110
|
-
else
|
|
111
|
-
# Block - new line with indent
|
|
112
|
-
lines.push(formatted)
|
|
113
|
-
else
|
|
114
|
-
# Atom - append to last line
|
|
115
|
-
lines[lines.length - 1] += ' ' + formatAtom(elem, indent)
|
|
116
|
-
|
|
117
|
-
# Close the paren
|
|
118
|
-
lines[lines.length - 1] += ')'
|
|
119
|
-
|
|
120
|
-
lines.join('\n')
|
|
121
|
-
|
|
122
|
-
# Parse and format the s-expression from DATA
|
|
123
|
-
sexpr = JSON.parse(DATA.trim())
|
|
124
|
-
formatted = toSexpr(sexpr, 0, true)
|
|
125
|
-
console.log formatted
|
|
126
|
-
|
|
127
|
-
__DATA__
|
|
128
|
-
["program", "", ["def", "fibonacci", ["n"], ["block", ["if", ["<=", "n", "1"], ["block", "n"], ["block", ["+", ["fibonacci", ["-", "n", "1"]], ["fibonacci", ["-", "n", "2"]]]]]]], ["=", "pattern", "/\n ^ \\d+ # digits\n \\s* # space\n [a-z]+ # letters\n $\n/i"], ["=", "email", "\"user@example.com\""], ["=", "domain", ["regex-index", "email", "/@(.+)$/", "1"]], [[".","console","log"], "\"Fib(10):\"", ["fibonacci", "10"]], [[".","console","log"], "\"Domain:\"", "domain"]]
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Example of importing .rip files directly with Bun loader
|
|
2
|
-
// Run with: bun --preload ./bunloader.ts examples/use-loader.js
|
|
3
|
-
|
|
4
|
-
import * as math from './math.rip';
|
|
5
|
-
|
|
6
|
-
console.log('Testing Rip loader:');
|
|
7
|
-
console.log('add(5, 3) =', math.add(5, 3));
|
|
8
|
-
console.log('multiply(4, 7) =', math.multiply(4, 7));
|
|
9
|
-
console.log('factorial(5) =', math.factorial(5));
|
package/docs/examples/utils.rip
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# Utility functions in pure Rip
|
|
2
|
-
|
|
3
|
-
export def add(a, b)
|
|
4
|
-
a + b
|
|
5
|
-
|
|
6
|
-
export def multiply(a, b)
|
|
7
|
-
a * b
|
|
8
|
-
|
|
9
|
-
export def greet(name)
|
|
10
|
-
"Hello, ${name}!"
|
|
11
|
-
|
|
12
|
-
export calculate = (x, y) =>
|
|
13
|
-
sum: x + y
|
|
14
|
-
product: x * y
|
|
15
|
-
average: (x + y) / 2
|
|
16
|
-
|
|
17
|
-
export config = {
|
|
18
|
-
version: "1.0"
|
|
19
|
-
features: ["hoisting", "implicit-returns", "arrows"]
|
|
20
|
-
}
|