Class: Yoda::Parsing::Parser
- Inherits:
-
Object
- Object
- Yoda::Parsing::Parser
- Defined in:
- lib/yoda/parsing/parser.rb
Instance Method Summary collapse
- #parse(string) ⇒ AST::Vnode
- #parse_with_comments(string) ⇒ (AST::Vnode, Array<::Parser::Source::Comment>)
- #parse_with_comments_if_valid(string) ⇒ (::Parser::AST::Node, Array<::Parser::Source::Comment>)?
-
#tokenize(source, recover: false) ⇒ Array
See Parser::Base.tokenize.
Instance Method Details
#parse(string) ⇒ AST::Vnode
8 9 10 |
# File 'lib/yoda/parsing/parser.rb', line 8 def parse(string) parse_with_comments(string).first end |
#parse_with_comments(string) ⇒ (AST::Vnode, Array<::Parser::Source::Comment>)
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/yoda/parsing/parser.rb', line 14 def parse_with_comments(string) source_buffer = create_source_buffer(source: string) node, comments = parser.parse_with_comments(source_buffer) comments_by_node = begin if ::Parser::Source::Comment.respond_to?(:associate_by_identity) ::Parser::Source::Comment.associate_by_identity(node, comments) else ::Parser::Source::Comment.associate(node, comments) end end [AST.wrap(node, comments_by_node: comments_by_node), comments] end |
#parse_with_comments_if_valid(string) ⇒ (::Parser::AST::Node, Array<::Parser::Source::Comment>)?
29 30 31 32 33 |
# File 'lib/yoda/parsing/parser.rb', line 29 def parse_with_comments_if_valid(string) parse_with_comments(string) rescue ::Parser::SyntaxError nil end |
#tokenize(source, recover: false) ⇒ Array
38 39 40 |
# File 'lib/yoda/parsing/parser.rb', line 38 def tokenize(source, recover: false) parser.tokenize(create_source_buffer(source: source), recover) end |