natalie_parser 1.2.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88d3e8539a0c9f60203b9d0c914091e0ea4f436629b26b1dca6926edf0488e0a
4
- data.tar.gz: 0d165c15a569ec4c76c8cb8de2b2aae13fa502956ff1a38adafd358b7cdecea0
3
+ metadata.gz: b35f9b98f6bbe4ec3bf8d5d9bce2c7e082504db23f442964f2a58e1ac9e11dc7
4
+ data.tar.gz: 1fbf06aa6fae8400855ea0d363d77a1b27d78869266bfb17b0f45cf9b8a30d41
5
5
  SHA512:
6
- metadata.gz: 9f7f6fad13b1c17cf5efde219fc13ce4dd70e47448f65ea13b0e92f98587acec95355bea454c37de60b5bf9a367862cb8611f6a2fa60a3adb7d4fc9e31e62d2c
7
- data.tar.gz: 682ad83ec17e2e1077e4ec826aed547a781a89a4fadccd00c34613e20d945b0795396cb7efbd356430002792e1fea0099dcf3ec72a2cb174a3a5e28adb4290d0
6
+ metadata.gz: 936ec0ef70541afd5839dbe4450401d7e8713499c3536d9ac7e53eb5617671dd308eee8e4f458188a9b0890f5a7ed5d855b3011c5539b64eb31639b4140e07fc
7
+ data.tar.gz: f6deb35c75e17e5c9fb49c6092e48453e904e7c7d4b515e2c7b5fe7fe69dc656da2faa6096b665b6021557ae8c47844ec65a9e8aca1933712f35d72f4db47c50
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.0 (2022-06-24)
4
+
5
+ - FEAT: Differentiate between bare/implicit hash and explicit one
6
+ - FIX: Fix calling colon2
7
+ - FIX: Parse implicit method calls with nth ref argument
8
+
3
9
  ## 1.2.1 (2022-06-16)
4
10
 
5
11
  - FIX: Fix regression with unary/infix operators (+/-)
@@ -23,6 +23,7 @@ public:
23
23
  virtual Type type() const override { return Type::Colon2; }
24
24
 
25
25
  virtual bool is_assignable() const override { return true; }
26
+ virtual bool is_callable() const override { return true; }
26
27
 
27
28
  const SharedPtr<Node> left() const { return m_left; }
28
29
  SharedPtr<String> name() const { return m_name; }
@@ -11,8 +11,9 @@ using namespace TM;
11
11
 
12
12
  class HashNode : public Node {
13
13
  public:
14
- HashNode(const Token &token)
15
- : Node { token } { }
14
+ HashNode(const Token &token, bool bare)
15
+ : Node { token }
16
+ , m_bare { bare } { }
16
17
 
17
18
  virtual Type type() const override { return Type::Hash; }
18
19
 
@@ -23,12 +24,16 @@ public:
23
24
  const Vector<SharedPtr<Node>> &nodes() const { return m_nodes; }
24
25
 
25
26
  virtual void transform(Creator *creator) const override {
26
- creator->set_type("hash");
27
+ if (m_bare)
28
+ creator->set_type("bare_hash");
29
+ else
30
+ creator->set_type("hash");
27
31
  for (auto node : m_nodes)
28
32
  creator->append(node);
29
33
  }
30
34
 
31
35
  protected:
32
36
  Vector<SharedPtr<Node>> m_nodes {};
37
+ bool m_bare { false };
33
38
  };
34
39
  }
@@ -14,7 +14,7 @@ using namespace TM;
14
14
  class HashPatternNode : public HashNode {
15
15
  public:
16
16
  HashPatternNode(const Token &token)
17
- : HashNode { token } { }
17
+ : HashNode { token, true } { }
18
18
 
19
19
  virtual Type type() const override { return Type::HashPattern; }
20
20
 
@@ -104,7 +104,7 @@ private:
104
104
  SharedPtr<Node> parse_forward_args(LocalsHashmap &);
105
105
  SharedPtr<Node> parse_group(LocalsHashmap &);
106
106
  SharedPtr<Node> parse_hash(LocalsHashmap &);
107
- SharedPtr<Node> parse_hash_inner(LocalsHashmap &, Precedence, Token::Type, SharedPtr<Node> = {});
107
+ SharedPtr<Node> parse_hash_inner(LocalsHashmap &, Precedence, Token::Type, bool, SharedPtr<Node> = {});
108
108
  SharedPtr<Node> parse_identifier(LocalsHashmap &);
109
109
  SharedPtr<Node> parse_if(LocalsHashmap &);
110
110
  void parse_interpolated_body(LocalsHashmap &, InterpolatedNode &, Token::Type);
@@ -775,6 +775,7 @@ public:
775
775
  case Token::Type::NilKeyword:
776
776
  case Token::Type::Not:
777
777
  case Token::Type::NotKeyword:
778
+ case Token::Type::NthRef:
778
779
  case Token::Type::PercentLowerI:
779
780
  case Token::Type::PercentLowerW:
780
781
  case Token::Type::PercentUpperI:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class NatalieParser
4
- VERSION = '1.2.1'
4
+ VERSION = '2.0.0'
5
5
  end
data/src/parser.cpp CHANGED
@@ -337,7 +337,7 @@ SharedPtr<Node> Parser::parse_array(LocalsHashmap &locals) {
337
337
  return array.static_cast_as<Node>();
338
338
  }
339
339
  if (token.type() == Token::Type::SymbolKey) {
340
- array->add_node(parse_hash_inner(locals, Precedence::HASH, Token::Type::RBracket));
340
+ array->add_node(parse_hash_inner(locals, Precedence::HASH, Token::Type::RBracket, true));
341
341
  expect(Token::Type::RBracket, "array closing bracket");
342
342
  advance();
343
343
  return array.static_cast_as<Node>();
@@ -345,7 +345,7 @@ SharedPtr<Node> Parser::parse_array(LocalsHashmap &locals) {
345
345
  auto value = parse_expression(Precedence::ARRAY, locals);
346
346
  token = current_token();
347
347
  if (token.is_hash_rocket()) {
348
- array->add_node(parse_hash_inner(locals, Precedence::HASH, Token::Type::RBracket, value));
348
+ array->add_node(parse_hash_inner(locals, Precedence::HASH, Token::Type::RBracket, true, value));
349
349
  expect(Token::Type::RBracket, "array closing bracket");
350
350
  advance();
351
351
  return array.static_cast_as<Node>();
@@ -1299,17 +1299,17 @@ SharedPtr<Node> Parser::parse_hash(LocalsHashmap &locals) {
1299
1299
  advance();
1300
1300
  SharedPtr<Node> hash;
1301
1301
  if (current_token().type() == Token::Type::RCurlyBrace)
1302
- hash = new HashNode { token };
1302
+ hash = new HashNode { token, false };
1303
1303
  else
1304
- hash = parse_hash_inner(locals, Precedence::HASH, Token::Type::RCurlyBrace);
1304
+ hash = parse_hash_inner(locals, Precedence::HASH, Token::Type::RCurlyBrace, false);
1305
1305
  expect(Token::Type::RCurlyBrace, "hash closing curly brace");
1306
1306
  advance();
1307
1307
  return hash;
1308
1308
  }
1309
1309
 
1310
- SharedPtr<Node> Parser::parse_hash_inner(LocalsHashmap &locals, Precedence precedence, Token::Type closing_token_type, SharedPtr<Node> first_key) {
1310
+ SharedPtr<Node> Parser::parse_hash_inner(LocalsHashmap &locals, Precedence precedence, Token::Type closing_token_type, bool bare, SharedPtr<Node> first_key) {
1311
1311
  auto token = current_token();
1312
- SharedPtr<HashNode> hash = new HashNode { token };
1312
+ SharedPtr<HashNode> hash = new HashNode { token, bare };
1313
1313
  if (!first_key)
1314
1314
  first_key = parse_expression(precedence, locals);
1315
1315
  hash->add_node(first_key);
@@ -1640,7 +1640,7 @@ SharedPtr<Node> Parser::parse_keyword_splat(LocalsHashmap &locals) {
1640
1640
  }
1641
1641
 
1642
1642
  SharedPtr<Node> Parser::parse_keyword_splat_wrapped_in_hash(LocalsHashmap &locals) {
1643
- SharedPtr<HashNode> hash = new HashNode { current_token() };
1643
+ SharedPtr<HashNode> hash = new HashNode { current_token(), true };
1644
1644
  hash->add_node(parse_keyword_splat(locals));
1645
1645
  return hash.static_cast_as<Node>();
1646
1646
  }
@@ -2337,12 +2337,13 @@ void Parser::parse_call_args(NodeWithArgs &node, LocalsHashmap &locals, bool bar
2337
2337
  m_call_depth.last()--;
2338
2338
  }
2339
2339
 
2340
- SharedPtr<Node> Parser::parse_call_hash_args(LocalsHashmap &locals, bool bare, Token::Type closing_token_type, SharedPtr<Node> first_arg) {
2340
+ SharedPtr<Node> Parser::parse_call_hash_args(LocalsHashmap &locals, bool bare_call, Token::Type closing_token_type, SharedPtr<Node> first_arg) {
2341
+ bool bare_hash = true; // we got here via foo(1, a: 'b') so it's always a "bare" hash
2341
2342
  SharedPtr<Node> hash;
2342
- if (bare)
2343
- hash = parse_hash_inner(locals, Precedence::BARE_CALL_ARG, closing_token_type, first_arg);
2343
+ if (bare_call)
2344
+ hash = parse_hash_inner(locals, Precedence::BARE_CALL_ARG, closing_token_type, bare_hash, first_arg);
2344
2345
  else
2345
- hash = parse_hash_inner(locals, Precedence::CALL_ARG, closing_token_type, first_arg);
2346
+ hash = parse_hash_inner(locals, Precedence::CALL_ARG, closing_token_type, bare_hash, first_arg);
2346
2347
  if (current_token().type() == Token::Type::StarStar)
2347
2348
  hash.static_cast_as<HashNode>()->add_node(parse_keyword_splat(locals));
2348
2349
  return hash;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: natalie_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-17 00:00:00.000000000 Z
11
+ date: 2022-06-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: NatalieParser is a zero-dependency, from-scratch, hand-written recursive
14
14
  descent parser for the Ruby Programming Language.