syntax_tree 2.4.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/Gemfile.lock +1 -1
- data/README.md +15 -7
- data/lib/syntax_tree/formatter/single_quotes.rb +13 -0
- data/lib/syntax_tree/node.rb +6 -3
- data/lib/syntax_tree/parser.rb +8 -2
- data/lib/syntax_tree/plugin/single_quotes.rb +4 -0
- data/lib/syntax_tree/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e69df6c9df69726ed7040c1b47584e8f17d9f3cc45a7a72de308aa9db39b4b66
|
4
|
+
data.tar.gz: 9dddf054616a7ca765dc7ebb7bbe98dbdaee8114a34043dd66390d9a6d576ea2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf759fc42716b42988156d84333ebe66baa87ad881b85e062e0942d285c8be25f074a894b329c6a69758c68655667c1972291f68339141592f4e01ce089a9a6c
|
7
|
+
data.tar.gz: e5b5e3a6645fa340959458be14670784cba49f0d6436a518429ef8926581dea2169b03400f14916c8c9bbb66388d1116b8cdedac811e371a1ea37368bd5f3b42
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [2.4.1] - 2022-05-10
|
10
|
+
|
11
|
+
- [#73](https://github.com/ruby-syntax-tree/syntax_tree/pull/73) - Fix nested hash patterns from accidentally adding a `then` to their output.
|
12
|
+
|
9
13
|
## [2.4.0] - 2022-05-07
|
10
14
|
|
11
15
|
### Added
|
@@ -209,7 +213,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
209
213
|
|
210
214
|
- 🎉 Initial release! 🎉
|
211
215
|
|
212
|
-
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.4.
|
216
|
+
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.4.1...HEAD
|
217
|
+
[2.4.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.4.0...v2.4.1
|
213
218
|
[2.4.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.3.1...v2.4.0
|
214
219
|
[2.3.1]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.3.0...v2.3.1
|
215
220
|
[2.3.0]: https://github.com/ruby-syntax-tree/syntax_tree/compare/v2.2.0...v2.3.0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -404,7 +404,17 @@ The language server additionally includes this custom request to return a textua
|
|
404
404
|
|
405
405
|
## Plugins
|
406
406
|
|
407
|
-
You can register additional languages that can flow through the same CLI with Syntax Tree's plugin system.
|
407
|
+
You can register additional configuration and additional languages that can flow through the same CLI with Syntax Tree's plugin system. When invoking the CLI, you pass through the list of plugins with the `--plugins` options to the commands that accept them. They should be a comma-delimited list. When the CLI first starts, it will require the files corresponding to those names.
|
408
|
+
|
409
|
+
### Configuration
|
410
|
+
|
411
|
+
To register additional configuration, define a file somewhere in your load path named `syntax_tree/my_plugin` directory. Then when invoking the CLI, you will pass `--plugins=my_plugin`. That will get required. In this way, you can modify Syntax Tree however you would like. Some plugins ship with Syntax Tree itself. They are:
|
412
|
+
|
413
|
+
* `plugin/single_quotes` - This will change all of your string literals to use single quotes instead of the default double quotes.
|
414
|
+
|
415
|
+
### Languages
|
416
|
+
|
417
|
+
To register a new language, call:
|
408
418
|
|
409
419
|
```ruby
|
410
420
|
SyntaxTree.register_handler(".mylang", MyLanguage)
|
@@ -416,13 +426,11 @@ In this case, whenever the CLI encounters a filepath that ends with the given ex
|
|
416
426
|
* `MyLanguage.parse(source)` - this should return the syntax tree corresponding to the given source. Those objects should implement the `pretty_print` interface.
|
417
427
|
* `MyLanguage.format(source)` - this should return the formatted version of the given source.
|
418
428
|
|
419
|
-
Below are listed all of the "official" plugins hosted under the same GitHub organization, which can be used as references for how to implement other plugins.
|
420
|
-
|
421
|
-
* [SyntaxTree::Haml](https://github.com/ruby-syntax-tree/syntax_tree-haml) for the [Haml template language](https://haml.info/).
|
422
|
-
* [SyntaxTree::JSON](https://github.com/ruby-syntax-tree/syntax_tree-json) for JSON.
|
423
|
-
* [SyntaxTree::RBS](https://github.com/ruby-syntax-tree/syntax_tree-rbs) for the [RBS type language](https://github.com/ruby/rbs).
|
429
|
+
Below are listed all of the "official" language plugins hosted under the same GitHub organization, which can be used as references for how to implement other plugins.
|
424
430
|
|
425
|
-
|
431
|
+
* [haml](https://github.com/ruby-syntax-tree/syntax_tree-haml) for the [Haml template language](https://haml.info/).
|
432
|
+
* [json](https://github.com/ruby-syntax-tree/syntax_tree-json) for JSON.
|
433
|
+
* [rbs](https://github.com/ruby-syntax-tree/syntax_tree-rbs) for the [RBS type language](https://github.com/ruby/rbs).
|
426
434
|
|
427
435
|
## Integration
|
428
436
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SyntaxTree
|
4
|
+
class Formatter
|
5
|
+
# This module overrides the quote method on the formatter to use single
|
6
|
+
# quotes for everything instead of double quotes.
|
7
|
+
module SingleQuotes
|
8
|
+
def quote
|
9
|
+
"'"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/syntax_tree/node.rb
CHANGED
@@ -3904,7 +3904,7 @@ module SyntaxTree
|
|
3904
3904
|
# quotes, then single quotes would deactivate it.)
|
3905
3905
|
def self.locked?(node)
|
3906
3906
|
node.parts.any? do |part|
|
3907
|
-
part.is_a?(TStringContent)
|
3907
|
+
!part.is_a?(TStringContent) || part.value.match?(/\\|#[@${]/)
|
3908
3908
|
end
|
3909
3909
|
end
|
3910
3910
|
|
@@ -5064,13 +5064,16 @@ module SyntaxTree
|
|
5064
5064
|
parts = keywords.map { |(key, value)| KeywordFormatter.new(key, value) }
|
5065
5065
|
parts << KeywordRestFormatter.new(keyword_rest) if keyword_rest
|
5066
5066
|
|
5067
|
+
nested = PATTERNS.include?(q.parent.class)
|
5067
5068
|
contents = -> do
|
5068
5069
|
q.group { q.seplist(parts) { |part| q.format(part, stackable: false) } }
|
5069
5070
|
|
5070
5071
|
# If there isn't a constant, and there's a blank keyword_rest, then we
|
5071
5072
|
# have an plain ** that needs to have a `then` after it in order to
|
5072
5073
|
# parse correctly on the next parse.
|
5073
|
-
|
5074
|
+
if !constant && keyword_rest && keyword_rest.value.nil? && !nested
|
5075
|
+
q.text(" then")
|
5076
|
+
end
|
5074
5077
|
end
|
5075
5078
|
|
5076
5079
|
# If there is a constant, we're going to format to have the constant name
|
@@ -5097,7 +5100,7 @@ module SyntaxTree
|
|
5097
5100
|
|
5098
5101
|
# If there's only one pair, then we'll just print the contents provided
|
5099
5102
|
# we're not inside another pattern.
|
5100
|
-
if !
|
5103
|
+
if !nested && parts.size == 1
|
5101
5104
|
contents.call
|
5102
5105
|
return
|
5103
5106
|
end
|
data/lib/syntax_tree/parser.rb
CHANGED
@@ -1671,9 +1671,15 @@ module SyntaxTree
|
|
1671
1671
|
# (nil | VarField) keyword_rest
|
1672
1672
|
# ) -> HshPtn
|
1673
1673
|
def on_hshptn(constant, keywords, keyword_rest)
|
1674
|
-
|
1675
|
-
|
1674
|
+
if keyword_rest
|
1675
|
+
# We're doing this to delete the token from the list so that it doesn't
|
1676
|
+
# confuse future patterns by thinking they have an extra ** on the end.
|
1677
|
+
find_token(Op, "**")
|
1678
|
+
elsif (token = find_token(Op, "**", consume: false))
|
1676
1679
|
tokens.delete(token)
|
1680
|
+
|
1681
|
+
# Create an artificial VarField if we find an extra ** on the end. This
|
1682
|
+
# means the formatting will be a little more consistent.
|
1677
1683
|
keyword_rest = VarField.new(value: nil, location: token.location)
|
1678
1684
|
end
|
1679
1685
|
|
data/lib/syntax_tree/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syntax_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Newton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,10 +95,12 @@ files:
|
|
95
95
|
- lib/syntax_tree.rb
|
96
96
|
- lib/syntax_tree/cli.rb
|
97
97
|
- lib/syntax_tree/formatter.rb
|
98
|
+
- lib/syntax_tree/formatter/single_quotes.rb
|
98
99
|
- lib/syntax_tree/language_server.rb
|
99
100
|
- lib/syntax_tree/language_server/inlay_hints.rb
|
100
101
|
- lib/syntax_tree/node.rb
|
101
102
|
- lib/syntax_tree/parser.rb
|
103
|
+
- lib/syntax_tree/plugin/single_quotes.rb
|
102
104
|
- lib/syntax_tree/prettyprint.rb
|
103
105
|
- lib/syntax_tree/version.rb
|
104
106
|
- lib/syntax_tree/visitor.rb
|