Skip to content

Commit fbc69c8

Browse files
committed
wip parser
1 parent a636ba0 commit fbc69c8

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ async.each([1,2,3],function(i,cb){
152152
callbacks trigger at end of scope unless you take control of the callback object using @
153153

154154
```
155-
[1,2,3] *each
155+
[1,2,3] async.each
156156
'blah' @another_function
157157
```
158158
Using '@' either prefixed or before a function call adds the current callback to the params

iox.ls

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
readline = require('readline')
2+
async = require('async')
3+
4+
rl = readline.createInterface do
5+
input: process.stdin
6+
output: process.stdout
7+
8+
isDigit = (n)->
9+
return n >= '0' && n <= '9'
10+
11+
put = (needle,haystack,ins)->
12+
13+
14+
class State
15+
chunk: ''
16+
ins: 0
17+
depth: 0
18+
code: ''
19+
wrap: false
20+
chain: ''
21+
putraw: (tk)->
22+
#if @wrap
23+
# @chunk = tk + '(' + @chunk + ')'
24+
# @wrap = false
25+
#else
26+
@chunk = @chunk.substr(0,@ins) + tk + @chunk.substr(@ins)
27+
@ins += tk.length
28+
@depth++
29+
put: (tk)->
30+
if @wrap
31+
@chunk = tk + '(' + @chunk + ')'
32+
@wrap = false
33+
else
34+
if @chain
35+
@chunk = @chunk.substr(0,@ins) + @chain + @chunk.substr(@ins)
36+
@ins += @chain.length
37+
@chain = ''
38+
@chunk = @chunk.substr(0,@ins) + tk + "()" + @chunk.substr(@ins)
39+
@ins += tk.length + 1
40+
@depth++
41+
push: ->
42+
if @chunk
43+
console.log @chunk+';'
44+
@code += @chunk + ';\n';
45+
@chunk = ''
46+
@ins = 0
47+
@depth = 0
48+
49+
code = ''
50+
iter = (cb)->
51+
line <- rl.question 'iox> '
52+
tokens = line.split(' ')
53+
54+
#if token[0] == 'def'
55+
# # function
56+
57+
rtokens = tokens.reverse()
58+
state = new State()
59+
60+
i = rtokens.length-1
61+
for tk in rtokens
62+
63+
try
64+
left = rtokens[i-1]
65+
if left[left.length-1]==','
66+
# combine
67+
void
68+
69+
console.log state.chunk
70+
tk0 = tk[0]
71+
if tk0 == '$'
72+
if state.depth
73+
state.putraw(tk.substr(1))
74+
state.chain = ' = '
75+
else
76+
state.putraw(tk.substr(1))
77+
else if isDigit(tk0)
78+
state.put(tk)
79+
else if tk0 == '['
80+
# parse array/range
81+
state.put(tk)
82+
else if tk0 == '('
83+
# parse range
84+
void
85+
else if tk0 == '{'
86+
# parse dict
87+
state.put(tk)
88+
else if tk0 == '-'
89+
# flag
90+
void
91+
else if tk0 == '+'
92+
# flag
93+
void
94+
else # function?
95+
state.put(tk)
96+
97+
i--
98+
99+
state.push()
100+
return cb!
101+
102+
async.whilst (->true), iter
103+

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"main": "run.js",
77
"author": "Grady O'Connell",
88
"dependencies": {
9-
"livescript": "^1.5.0"
9+
"livescript": "^1.5.0",
10+
"async": "*"
1011
}
1112
}

run.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/node
2+
require('livescript')
3+
module.exports = require('./iox')

0 commit comments

Comments
 (0)