Skip to content

Commit b38f82d

Browse files
eregonandrykonchin
authored andcommitted
Update parser-related documentation
1 parent aa20f4d commit b38f82d

File tree

6 files changed

+60
-74
lines changed

6 files changed

+60
-74
lines changed

doc/contributor/parser.md

Lines changed: 0 additions & 39 deletions
This file was deleted.

doc/contributor/prism.md

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,67 @@
88

99
## Print Detailed Prism AST
1010

11+
### From the Prism repository
12+
1113
```bash
12-
cd prism
13-
bundle exec rake
14-
bin/parse -e '1&.itself'
14+
$ cd prism
15+
$ bundle exec rake compile
16+
$ bin/parse -e '1&.itself'
17+
@ ProgramNode (location: (1,0)-(1,9))
18+
├── locals: []
19+
└── statements:
20+
@ StatementsNode (location: (1,0)-(1,9))
21+
└── body: (length: 1)
22+
└── @ CallNode (location: (1,0)-(1,9))
23+
├── flags: safe_navigation
24+
├── receiver:
25+
│ @ IntegerNode (location: (1,0)-(1,1))
26+
│ └── flags: decimal
27+
├── call_operator_loc: (1,1)-(1,3) = "&."
28+
├── name: :itself
29+
├── message_loc: (1,3)-(1,9) = "itself"
30+
├── opening_loc: ∅
31+
├── arguments: ∅
32+
├── closing_loc: ∅
33+
└── block: ∅
1534
```
1635

36+
### From TruffleRuby
37+
1738
We can also see what the AST as Java nodes and without extra location fields looks like on TruffleRuby with:
1839
```bash
19-
cd truffleruby
20-
jt -q ruby -e 'puts Truffle::Debug.yarp_parse(ARGV[0])' -- '1&.itself'
40+
$ cd truffleruby
41+
$ t -q ruby tool/parse_ast.rb '1&.itself'
42+
Source:
43+
1&.itself
44+
45+
AST:
46+
ProgramNode
47+
locals:
48+
statements: StatementsNode
49+
body:
50+
CallNode[Li]
51+
flags: 1
52+
receiver: IntegerNode
53+
flags: 2
54+
name: "itself"
55+
arguments: null
56+
block: null
57+
```
58+
59+
```bash
60+
$ jt -q ruby tool/parse_ast.rb some_file.rb
61+
```
62+
63+
You can also compare to JRuby's AST with:
64+
```bash
65+
$ jruby tool/parse_ast.rb '1&.itself'
66+
Source:
67+
1&.itself
68+
69+
AST:
70+
RootNode line: 0
71+
CallNode*[lazy]:itself line: 0
72+
FixnumNode line: 0, long: 1
73+
, null, null
2174
```

doc/contributor/updating-jruby-parser.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

doc/contributor/workflow.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,3 @@ file to fix it.
321321

322322
You can also recompute the tags automatically for an entire test file with
323323
`jt retag test/mri/tests/file.rb`.
324-
325-
## Building the parser
326-
327-
TruffleRuby uses the Jay parser generator. A copy of this is located in
328-
`tool/jay`. The command `jt build parser` will build Jay, if needed, and then
329-
regenerate the parser. We check the generated parser into the source repository.

doc/legal/legal.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,6 @@ Engine Yard and are released under an MIT licence (see `mit.txt`).
208208
We do not distribute the FFI Specs, but they are copyright 2008-2014
209209
Ruby-FFI contributors and are released under an MIT licence (see `mit.txt`).
210210

211-
## Jay
212-
213-
TruffleRuby uses the Jay parser generator, modified from
214-
https://github.com/jruby/jay revision `9ffc59a`. Jay is copyright 1989 The
215-
Regents of the University of California, ported by Axel T. Schreiner, and is
216-
covered by the three-clause BSD licence (see `jay.txt`). We only distribute Jay
217-
in the source repository - it isn't part of releases.
218-
219211
## Written offer for source code
220212

221213
For any software that you receive from Oracle in binary form which is licensed

tool/parse_ast.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ def indent(string)
4444
puts code
4545
puts
4646

47-
print "AST:"
4847
if RUBY_ENGINE == "jruby"
48+
print "AST:"
4949
require 'jruby'
5050
ast_to_string = JRuby.parse(code).to_string
5151
else
52+
puts "AST:"
5253
ast_to_string = Truffle::Debug.parse_ast(code)
5354
end
5455
puts indent(ast_to_string)

0 commit comments

Comments
 (0)