Skip to content

Commit d96dad1

Browse files
committed
Include parser translation
1 parent c497724 commit d96dad1

File tree

11 files changed

+1620
-1
lines changed

11 files changed

+1620
-1
lines changed

.github/workflows/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
# TESTOPTS: --verbose
2424
steps:
2525
- uses: actions/checkout@master
26+
with:
27+
submodules: true
2628
- uses: ruby/setup-ruby@v1
2729
with:
2830
bundler-cache: true

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "test/ruby-syntax-fixtures"]
88
path = test/ruby-syntax-fixtures
99
url = https://github.com/ruby-syntax-tree/ruby-syntax-fixtures
10+
[submodule "test/suites/parser"]
11+
path = test/suites/parser
12+
url = https://github.com/whitequark/parser

.rubocop.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ AllCops:
99
Exclude:
1010
- '{.git,.github,bin,coverage,pkg,spec,test/fixtures,vendor,tmp}/**/*'
1111
- test/ruby-syntax-fixtures/**/*
12+
- test/suites/parser/**/*
1213
- test.rb
1314

1415
Gemspec/DevelopmentDependencies:

Rakefile

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ require "syntax_tree/rake_tasks"
66

77
Rake::TestTask.new(:test) do |t|
88
t.libs << "test"
9+
t.libs << "test/suites"
910
t.libs << "lib"
10-
t.test_files = FileList["test/**/*_test.rb"]
11+
12+
# These are our own tests.
13+
test_files = FileList["test/**/*_test.rb"]
14+
15+
# This is a big test file from the parser gem that tests its functionality.
16+
test_files << "test/suites/parser/test/test_parser.rb"
17+
18+
t.test_files = test_files
1119
end
1220

1321
task default: :test

lib/syntax_tree.rb

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
require_relative "syntax_tree/yarv/assembler"
4141
require_relative "syntax_tree/yarv/vm"
4242

43+
require_relative "syntax_tree/translation"
44+
4345
# Syntax Tree is a suite of tools built on top of the internal CRuby parser. It
4446
# provides the ability to generate a syntax tree from source, as well as the
4547
# tools necessary to inspect and manipulate that syntax tree. It can be used to

lib/syntax_tree/translation.rb

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
module SyntaxTree
4+
# This module is responsible for translating the Syntax Tree syntax tree into
5+
# other representations.
6+
module Translation
7+
# This method translates the given node into the representation defined by
8+
# the whitequark/parser gem. We don't explicitly list it as a dependency
9+
# because it's not required for the core functionality of Syntax Tree.
10+
def self.to_parser(node, source)
11+
require "parser"
12+
require_relative "translation/parser"
13+
14+
buffer = ::Parser::Source::Buffer.new("(string)")
15+
buffer.source = source
16+
17+
node.accept(Parser.new(buffer))
18+
end
19+
end
20+
end

0 commit comments

Comments
 (0)