rip-lang 3.7.3 → 3.8.8
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 +111 -0
- package/README.md +42 -34
- package/docs/RIP-INTERNALS.md +2 -4
- package/docs/RIP-LANG.md +150 -3
- package/docs/RIP-TYPES.md +1 -2
- package/docs/demo.html +342 -0
- package/docs/dist/rip-ui.min.js +516 -0
- package/docs/dist/rip-ui.min.js.br +0 -0
- package/docs/dist/rip.browser.js +379 -461
- package/docs/dist/rip.browser.min.js +204 -220
- package/docs/dist/rip.browser.min.js.br +0 -0
- package/docs/dist/ui.js +956 -0
- package/docs/dist/ui.min.js +2 -0
- package/docs/dist/ui.min.js.br +0 -0
- package/docs/dist/ui.rip +957 -0
- package/docs/dist/ui.rip.br +0 -0
- package/docs/examples.rip +180 -0
- package/docs/index.html +3 -1599
- package/docs/playground-app.html +1022 -0
- package/docs/playground-js.html +1645 -0
- package/docs/playground-rip-ui.html +1419 -0
- package/docs/playground-rip.html +1450 -0
- package/docs/rip-fav.svg +5 -0
- package/package.json +3 -3
- package/scripts/serve.js +3 -2
- package/src/browser.js +38 -16
- package/src/compiler.js +165 -226
- package/src/components.js +153 -140
- package/src/grammar/README.md +234 -0
- package/src/grammar/lunar.rip +2412 -0
- package/src/grammar/solar.rip +18 -4
- package/src/lexer.js +82 -30
- package/src/parser-rd.js +3242 -0
- package/src/parser.js +6 -5
- package/src/repl.js +24 -5
- package/docs/NOTES.md +0 -93
- package/docs/RIP-GUIDE.md +0 -698
- package/docs/RIP-REACTIVITY.md +0 -311
|
Binary file
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# Shared playground examples
|
|
2
|
+
# Loaded by all playground variants via <script type="text/rip" src="examples.rip">
|
|
3
|
+
|
|
4
|
+
globalThis.ripExamples =
|
|
5
|
+
demo: '''
|
|
6
|
+
# Rip code - edit me!
|
|
7
|
+
def fibonacci(n)
|
|
8
|
+
if n <= 1 then n
|
|
9
|
+
else fibonacci(n - 1) + fibonacci(n - 2)
|
|
10
|
+
|
|
11
|
+
# Regex features
|
|
12
|
+
email = "user@example.com"
|
|
13
|
+
domain = email[/@(.+)$/, 1]
|
|
14
|
+
|
|
15
|
+
# Reactive state
|
|
16
|
+
count := 0
|
|
17
|
+
doubled ~= count * 2
|
|
18
|
+
~> console.log "Count: #{count}, Doubled: #{doubled}"
|
|
19
|
+
|
|
20
|
+
# Classes
|
|
21
|
+
class Animal
|
|
22
|
+
constructor: (@name, @sound) ->
|
|
23
|
+
speak: -> "#{@name} says #{@sound}!"
|
|
24
|
+
|
|
25
|
+
dog = Animal.new "Rex", "woof"
|
|
26
|
+
console.log "Fib(10):", fibonacci(10)
|
|
27
|
+
console.log "Domain:", domain
|
|
28
|
+
console.log dog.speak()
|
|
29
|
+
'''
|
|
30
|
+
|
|
31
|
+
basics: '''
|
|
32
|
+
# Variables and expressions
|
|
33
|
+
name = "World"
|
|
34
|
+
greeting = "Hello, #{name}!"
|
|
35
|
+
console.log greeting
|
|
36
|
+
|
|
37
|
+
# Functions
|
|
38
|
+
def fibonacci(n)
|
|
39
|
+
if n <= 1 then n
|
|
40
|
+
else fibonacci(n - 1) + fibonacci(n - 2)
|
|
41
|
+
|
|
42
|
+
# Control flow
|
|
43
|
+
for i in [1..10]
|
|
44
|
+
if i %% 2 is 0
|
|
45
|
+
console.log "#{i} is even"
|
|
46
|
+
|
|
47
|
+
# Array comprehensions
|
|
48
|
+
squares = (x * x for x in [1..5])
|
|
49
|
+
console.log "Squares:", squares
|
|
50
|
+
|
|
51
|
+
# Destructuring
|
|
52
|
+
[first, ...rest] = [1, 2, 3, 4, 5]
|
|
53
|
+
console.log "First:", first, "Rest:", rest
|
|
54
|
+
|
|
55
|
+
console.log "Fib(10):", fibonacci(10)
|
|
56
|
+
'''
|
|
57
|
+
|
|
58
|
+
reactive: '''
|
|
59
|
+
# Reactive state (:=) creates a signal
|
|
60
|
+
count := 0
|
|
61
|
+
name := "Rip"
|
|
62
|
+
|
|
63
|
+
# Computed values (~=) auto-update when dependencies change
|
|
64
|
+
doubled ~= count * 2
|
|
65
|
+
greeting ~= "Hello, #{name}! Count is #{count}"
|
|
66
|
+
|
|
67
|
+
# Effects (~>) run when dependencies change
|
|
68
|
+
~> console.log "Effect:", greeting
|
|
69
|
+
|
|
70
|
+
# Modify state — effects and computed values update automatically
|
|
71
|
+
count = 5
|
|
72
|
+
name = "World"
|
|
73
|
+
console.log "Doubled:", doubled
|
|
74
|
+
|
|
75
|
+
# Readonly constants
|
|
76
|
+
MAX =! 100
|
|
77
|
+
console.log "Max:", MAX
|
|
78
|
+
'''
|
|
79
|
+
|
|
80
|
+
classes: '''
|
|
81
|
+
class Animal
|
|
82
|
+
constructor: (@name, @sound) ->
|
|
83
|
+
speak: -> "#{@name} says #{@sound}!"
|
|
84
|
+
|
|
85
|
+
class Dog extends Animal
|
|
86
|
+
constructor: (@name) -> super @name, "woof"
|
|
87
|
+
fetch: (item) -> "#{@name} fetches the #{item}!"
|
|
88
|
+
|
|
89
|
+
# Ruby-style .new() constructor
|
|
90
|
+
rex = Dog.new "Rex"
|
|
91
|
+
console.log rex.speak()
|
|
92
|
+
console.log rex.fetch("ball")
|
|
93
|
+
|
|
94
|
+
# Class with methods
|
|
95
|
+
class Counter
|
|
96
|
+
constructor: (@count = 0) ->
|
|
97
|
+
increment: -> @count++
|
|
98
|
+
decrement: -> @count--
|
|
99
|
+
toString: -> "Counter(#{@count})"
|
|
100
|
+
|
|
101
|
+
c = Counter.new 10
|
|
102
|
+
c.increment()
|
|
103
|
+
c.increment()
|
|
104
|
+
console.log "#{c}"
|
|
105
|
+
|
|
106
|
+
# Chained comparisons
|
|
107
|
+
x = 5
|
|
108
|
+
console.log "1 < x < 10:", 1 < x < 10
|
|
109
|
+
'''
|
|
110
|
+
|
|
111
|
+
regex: '''
|
|
112
|
+
# String interpolation
|
|
113
|
+
name = "Rip"
|
|
114
|
+
console.log "Hello, #{name}!"
|
|
115
|
+
|
|
116
|
+
# Regex match with capture groups
|
|
117
|
+
email = "user@example.com"
|
|
118
|
+
domain = email[/@(.+)$/, 1]
|
|
119
|
+
console.log "Domain:", domain
|
|
120
|
+
|
|
121
|
+
# Ruby-style =~ match operator
|
|
122
|
+
if "hello world" =~ /world/
|
|
123
|
+
console.log "Match found!"
|
|
124
|
+
|
|
125
|
+
# Heregex (multiline regex with comments)
|
|
126
|
+
urlPattern = ///
|
|
127
|
+
^(https?://) # protocol
|
|
128
|
+
([^/]+) # hostname
|
|
129
|
+
(/.*)?$ # path
|
|
130
|
+
///
|
|
131
|
+
|
|
132
|
+
url = "https://rip-lang.org/docs"
|
|
133
|
+
[_, protocol, host, path] = url.match(urlPattern)
|
|
134
|
+
console.log "Host:", host
|
|
135
|
+
|
|
136
|
+
# Heredocs (triple-quoted strings)
|
|
137
|
+
html = """
|
|
138
|
+
<div class="greeting">
|
|
139
|
+
<h1>Hello!</h1>
|
|
140
|
+
</div>
|
|
141
|
+
"""
|
|
142
|
+
console.log html
|
|
143
|
+
|
|
144
|
+
# String repetition
|
|
145
|
+
console.log "-" * 40
|
|
146
|
+
'''
|
|
147
|
+
|
|
148
|
+
async: '''
|
|
149
|
+
# The ! (dammit) operator calls AND awaits
|
|
150
|
+
# fetchData! is equivalent to: await fetchData()
|
|
151
|
+
|
|
152
|
+
def fetchJSON(url)
|
|
153
|
+
response = fetch!(url)
|
|
154
|
+
response.json!
|
|
155
|
+
|
|
156
|
+
# Fetch data with !
|
|
157
|
+
data = fetchJSON!("https://jsonplaceholder.typicode.com/todos/1")
|
|
158
|
+
console.log "Todo:", data.title
|
|
159
|
+
|
|
160
|
+
# Error handling
|
|
161
|
+
def safeFetch(url)
|
|
162
|
+
try
|
|
163
|
+
response = fetch!(url)
|
|
164
|
+
unless response.ok
|
|
165
|
+
throw new Error "HTTP #{response.status}"
|
|
166
|
+
response.json!
|
|
167
|
+
catch err
|
|
168
|
+
console.error "Failed:", err.message
|
|
169
|
+
null
|
|
170
|
+
|
|
171
|
+
# Multiple async operations
|
|
172
|
+
urls = [
|
|
173
|
+
"https://jsonplaceholder.typicode.com/todos/1"
|
|
174
|
+
"https://jsonplaceholder.typicode.com/todos/2"
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
results = Promise.all!(urls.map (url) -> fetch!(url).json!)
|
|
178
|
+
for item in results
|
|
179
|
+
console.log "- #{item.title}"
|
|
180
|
+
'''
|