Skip to content

Make the test suite pass on TruffleRuby and add it in CI #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Run bundle exec rake stree:write
  • Loading branch information
eregon committed Oct 28, 2022
commit 42bb2a44fc81a3e36c0506fc7d842258eae7a641
3 changes: 2 additions & 1 deletion lib/syntax_tree/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def run(item)
class Expr < Action
def run(item)
program = item.handler.parse(item.source)
if Program === program and expressions = program.statements.body and expressions.size == 1
if Program === program and expressions = program.statements.body and
expressions.size == 1
puts expressions.first.construct_keys
else
warn("The input to `stree expr` must be a single expression.")
Expand Down
17 changes: 12 additions & 5 deletions lib/syntax_tree/pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,16 @@ def compile_node(root)
clazz = Object.const_get(root.value)

->(node) { node.is_a?(clazz) }
elsif ConstPathRef === root and VarRef === root.parent and Const === root.parent.value and root.parent.value.value == "SyntaxTree"
elsif ConstPathRef === root and VarRef === root.parent and
Const === root.parent.value and
root.parent.value.value == "SyntaxTree"
compile_node(root.constant)
elsif DynaSymbol === root and root.parts.empty?
symbol = :""

->(node) { node == symbol }
elsif DynaSymbol === root and parts = root.parts and parts.size == 1 and TStringContent === parts[0]
elsif DynaSymbol === root and parts = root.parts and parts.size == 1 and
TStringContent === parts[0]
symbol = parts[0].value.to_sym

->(node) { node == symbol }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to add a test to validate this change but couldn't find a way to trigger this case.
I tried things like:

    def test_search_string_simple
      results = search(%{"#{'abc'}"}, "StringLiteral[parts: [TStringContent[value: 'abc']]]")

      assert_equal 1, results.length
    end

    def test_search_symbol_simple
      puts %s{:"#{'abc'}"}
      puts ':"#{\'abc\'}"'
      results = search(':"#{\'abc\'}"', ':abc')
      results = search(':"#{\'abc\'}"', ':"#{\'abc\'}"')
      results = search(%{"#{'abc'}"}, "DynaSymbol[parts: [TStringContent[value: 'abc']]]")

      assert_equal 1, results.length
    end

But none seem to match this specific condition.

Expand All @@ -129,7 +132,9 @@ def compile_node(root)

preprocessed =
root.keywords.to_h do |keyword, value|
raise CompilationError, PP.pp(root, +"").chomp unless keyword.is_a?(Label)
unless keyword.is_a?(Label)
raise CompilationError, PP.pp(root, +"").chomp
end
[keyword.value.chomp(":").to_sym, compile_node(value)]
end

Expand All @@ -146,13 +151,15 @@ def compile_node(root)
else
compiled_keywords
end
elsif RegexpLiteral === root and parts = root.parts and parts.size == 1 and TStringContent === parts[0]
elsif RegexpLiteral === root and parts = root.parts and
parts.size == 1 and TStringContent === parts[0]
regexp = /#{parts[0].value}/

->(attribute) { regexp.match?(attribute) }
elsif StringLiteral === root and root.parts.empty?
->(attribute) { attribute == "" }
elsif StringLiteral === root and parts = root.parts and parts.size == 1 and TStringContent === parts[0]
elsif StringLiteral === root and parts = root.parts and
parts.size == 1 and TStringContent === parts[0]
value = parts[0].value
->(attribute) { attribute == value }
elsif SymbolLiteral === root
Expand Down