Skip to content

Commit 4187145

Browse files
committed
Add examples to docs
1 parent 2db7d1a commit 4187145

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

lib/syntax_suggest/visitor.rb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
module SyntaxSuggest
2-
# A visitor that walks the AST and pulls out information
3-
# that is too dificult to discern by just looking at tokens
2+
# Walks the Prism AST to extract structural info that cannot be reliably determined from tokens
3+
# alone.
4+
#
5+
# Such as the location of lines that must be logically joined so the search algorithm will
6+
# treat them as one. Example:
7+
#
8+
# source = <<~RUBY
9+
# User # 1
10+
# .where(name: "Earlopain") # 2
11+
# .first # 3
12+
# RUBY
13+
# ast, _tokens = Prism.parse_lex(source).value
14+
# visitor = Visitor.new
15+
# visitor.visit(ast)
16+
# visitor.consecutive_lines_hash # => [1, 2]
17+
#
18+
# This output means that line 1 and line 2 needs to be joined with it's next line.
19+
#
20+
# And determing the location of "endless" method defintition. For example:
21+
#
22+
# source = <<~RUBY
23+
# def square(x) = x * x # 1
24+
# RUBY
25+
#
26+
# ast, _tokens = Prism.parse_lex(source).value
27+
# visitor = Visitor.new
28+
# visitor.endless_def_keyword_locs.first.start_line # => 1
429
class Visitor < Prism::Visitor
530
attr_reader :endless_def_keyword_locs
631

0 commit comments

Comments
 (0)