-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3178 from ruby/string-query
Prism::StringQuery
- Loading branch information
Showing
11 changed files
with
444 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Prism | ||
# Query methods that allow categorizing strings based on their context for | ||
# where they could be valid in a Ruby syntax tree. | ||
class StringQuery | ||
# The string that this query is wrapping. | ||
attr_reader :string | ||
|
||
# Initialize a new query with the given string. | ||
def initialize(string) | ||
@string = string | ||
end | ||
|
||
# Whether or not this string is a valid local variable name. | ||
def local? | ||
StringQuery.local?(string) | ||
end | ||
|
||
# Whether or not this string is a valid constant name. | ||
def constant? | ||
StringQuery.constant?(string) | ||
end | ||
|
||
# Whether or not this string is a valid method name. | ||
def method_name? | ||
StringQuery.method_name?(string) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# typed: strict | ||
|
||
class Prism::StringQuery | ||
sig { params(string: String).returns(T::Boolean) } | ||
def self.local?(string); end | ||
|
||
sig { params(string: String).returns(T::Boolean) } | ||
def self.constant?(string); end | ||
|
||
sig { params(string: String).returns(T::Boolean) } | ||
def self.method_name?(string); end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Prism | ||
class StringQuery | ||
def self.local?: (String string) -> bool | ||
def self.constant?: (String string) -> bool | ||
def self.method_name?: (String string) -> bool | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Prism | ||
class StringQuery | ||
attr_reader string: String | ||
|
||
def initialize: (String string) -> void | ||
|
||
def local?: () -> bool | ||
def constant?: () -> bool | ||
def method_name?: () -> bool | ||
end | ||
end |
Oops, something went wrong.