You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[glsl-tokenizer](http://github.com/stackgl/glsl-tokenizer) and turns them into
5
10
an AST.
6
11
7
-
```javascript
12
+
May either be used as a stream
13
+
14
+
## API
8
15
9
-
var tokenizer =require('glsl-tokenizer')()
10
-
, fs =require('fs')
11
-
, parser =require('./index')
16
+
### `stream = require('glsl-parser/stream')`
12
17
13
-
var num =0
18
+
Creates a GLSL parser stream, which emits nodes as they're parsed.
19
+
20
+
```javascript
21
+
var TokenStream =require('glsl-tokenizer/stream')
22
+
var ParseStream =require('glsl-parser/stream')
23
+
var fs =require('fs')
14
24
15
25
fs.createReadStream('test.glsl')
16
-
.pipe(tokenizer)
17
-
.pipe(parser())
26
+
.pipe(TokenStream())
27
+
.pipe(ParseStream())
18
28
.on('data', function(x) {
19
29
console.log('ast of', x.type)
20
30
})
21
-
22
31
```
23
32
24
-
similar to [JSONStream](https://github.com/dominictarr/JSONStream), you may pass selectors
25
-
into the constructor to match only AST elements at that level. viable selectors are strings
26
-
and regexen, and they'll be matched against the emitted node's `type`.
33
+
### `ast = stream.program`
27
34
28
-
nodes
29
-
-----
35
+
The full program's AST, which will be updated with each incoming token.
30
36
31
-
```
37
+
### `ast = require('glsl-parser/direct')(tokens)`
32
38
33
-
stmtlist
34
-
stmt
35
-
struct
36
-
function
37
-
functionargs
38
-
decl
39
-
decllist
40
-
forloop
41
-
whileloop
42
-
if
43
-
expr
44
-
precision
45
-
comment
46
-
preprocessor
47
-
keyword
48
-
ident
49
-
return
50
-
continue
51
-
break
52
-
discard
53
-
do-while
54
-
binary
55
-
ternary
56
-
unary
39
+
Synchronously parses an array of tokens from `glsl-tokenizer`.
57
40
58
-
```
41
+
```javascript
42
+
var TokenString =require('glsl-tokenizer/string')
43
+
var ParseTokens =require('glsl-parser/direct')
44
+
var fs =require('fs')
59
45
60
-
legal & caveats
61
-
===============
46
+
var src =fs.readFileSync('test.glsl', 'utf8')
47
+
var tokens =TokenString(src)
48
+
var ast =ParseTokens(tokens)
49
+
50
+
console.log(ast)
51
+
```
62
52
63
-
known bugs
64
-
----------
53
+
## Nodes
54
+
55
+
*`stmtlist`
56
+
*`stmt`
57
+
*`struct`
58
+
*`function`
59
+
*`functionargs`
60
+
*`decl`
61
+
*`decllist`
62
+
*`forloop`
63
+
*`whileloop`
64
+
*`if`
65
+
*`expr`
66
+
*`precision`
67
+
*`comment`
68
+
*`preprocessor`
69
+
*`keyword`
70
+
*`ident`
71
+
*`return`
72
+
*`continue`
73
+
*`break`
74
+
*`discard`
75
+
*`do-while`
76
+
*`binary`
77
+
*`ternary`
78
+
*`unary`
79
+
80
+
## Known Issues
65
81
66
82
* because i am not smart enough to write a fully streaming parser, the current parser "cheats" a bit when it encounters a `expr` node! it actually waits until it has all the tokens it needs to build a tree for a given expression, then builds it and emits the constituent child nodes in the expected order. the `expr` parsing is heavily influenced by [crockford's tdop article](http://javascript.crockford.com/tdop/tdop.html). the rest of the parser is heavily influenced by fever dreams.
67
83
@@ -73,7 +89,6 @@ might not be the case -- it might be a user-defined constructor starting a state
73
89
if you've got unhygenic macros in your code, move the #if / #endifs to statement level, and have them surround
74
90
wholly parseable code. this sucks, and i am sorry.
75
91
76
-
license
77
-
-------
92
+
## License
78
93
79
-
MIT
94
+
MIT, see [LICENSE.md](LICENSE.md) for more details.
0 commit comments