Skip to content

Add ./bin/dump tool - #764

Closed
HParker wants to merge 1 commit into
ruby:mainfrom
HParker:add-dump-tool
Closed

HParker wants to merge 1 commit into
ruby:mainfrom
HParker:add-dump-tool

Conversation

@HParker

@HParker HParker commented Apr 4, 2023

Copy link
Copy Markdown
Collaborator

This tool allows you to see what serialize output is to assist in debugging serialize output.

source files like,

def hi_there
  puts 1 + 1
end

emits,

node ProgramNode(0...29)
  node ScopeNode(0...0)
  node StatementsNode(0...29)
    node DefNode(0...29)
      token IDENTIFIER 4...12 'hi_there'
      node StatementsNode(15...19)
        node CallNode(15...19)
          token IDENTIFIER 15...19 'puts'
          node ArgumentsNode(20...25)
            node CallNode(20...25)
              node IntegerNode(20...21)
              token PLUS 22...23 '+'
              node ArgumentsNode(24...25)
                node IntegerNode(24...25)
            str: 210 1"+"
        str: 217 4"puts"
      node ScopeNode(0...3)
    location(0...3)
    location(26...29)

@HParker
HParker force-pushed the add-dump-tool branch 2 times, most recently from 397c4ec to fc4c03d Compare April 4, 2023 06:04
This tool allows you to see what serialize output is to assist in debugging serialize output
@HParker

HParker commented Apr 4, 2023

Copy link
Copy Markdown
Collaborator Author

@enebo I opened this hoping it would help me understand the serialized output.

Using the format that PR adds, what serialized output would you want for an example like,

1 +
  2 +
  3
node ProgramNode(0...13)
  node ScopeNode(0...0)
  node StatementsNode(0...13)
    node CallNode(0...13)
      node CallNode(0...7)
        node IntegerNode(0...1)
        token PLUS(2...3) '+'
        node ArgumentsNode(6...7)
          node IntegerNode(6...7)
      str: "+"
      token PLUS(8...9) '+'
      node ArgumentsNode(12...13)
        node IntegerNode(12...13)
    str: "+"

I don't think I am understanding the location in the serialized output where the newline nodes would go.

related to: #757

@eregon

eregon commented Apr 4, 2023

Copy link
Copy Markdown
Member

Why not simply use pp YARP.load YARP.dump code for this? It doesn't seem great to manually write deserailization when it's already generated.

@jemmaissroff

Copy link
Copy Markdown
Collaborator

Agreed with @eregon here, although I do think it's helpful to move node_types out of bin/template.rb. But maybe in a separate PR?

@HParker

HParker commented Apr 4, 2023

Copy link
Copy Markdown
Collaborator Author

Yeah, my mistake! I have spent all my time in the parser and I clearly don't understand the serialize parts yet. Happy to have learned the format by duplicating and just close this PR.

@HParker HParker closed this Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants