summaryrefslogtreecommitdiff
path: root/prism
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2023-12-16 11:05:46 +0800
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-12-16 11:08:51 +0800
commitd242e8416e99eaee4465e2681210ae8b7ecd6d34 (patch)
treea1a7de4a143879aa16b6c751826dd1ee2a15c7e0 /prism
parent122341305ff859bf30b99175bfb9db4b8f6467f5 (diff)
Revert all of commits after Prism 0.19.0 release
We should bundle released version of Prism for Ruby 3.3.0
Diffstat (limited to 'prism')
-rw-r--r--prism/config.yml4
-rw-r--r--prism/diagnostic.c2
-rw-r--r--prism/diagnostic.h2
-rw-r--r--prism/parser.h6
-rw-r--r--prism/prism.c26
-rw-r--r--prism/templates/lib/prism/node.rb.erb10
6 files changed, 16 insertions, 34 deletions
diff --git a/prism/config.yml b/prism/config.yml
index 7bbe88e6b4..d3b6b08709 100644
--- a/prism/config.yml
+++ b/prism/config.yml
@@ -368,8 +368,8 @@ flags:
comment: Flags for integer nodes that correspond to the base of the integer.
- name: KeywordHashNodeFlags
values:
- - name: SYMBOL_KEYS
- comment: "a keyword hash which only has `AssocNode` elements all with symbol keys, which means the elements can be treated as keyword arguments"
+ - name: STATIC_KEYS
+ comment: "a keyword hash which only has `AssocNode` elements all with static literal keys, which means the elements can be treated as keyword arguments"
comment: Flags for keyword hash nodes.
- name: LoopFlags
values:
diff --git a/prism/diagnostic.c b/prism/diagnostic.c
index fd5dce5a04..1fc8c50cb5 100644
--- a/prism/diagnostic.c
+++ b/prism/diagnostic.c
@@ -62,7 +62,6 @@ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = {
[PM_ERR_ARGUMENT_FORMAL_GLOBAL] = "invalid formal argument; formal argument cannot be a global variable",
[PM_ERR_ARGUMENT_FORMAL_IVAR] = "invalid formal argument; formal argument cannot be an instance variable",
[PM_ERR_ARGUMENT_FORWARDING_UNBOUND] = "unexpected `...` in an non-parenthesized call",
- [PM_ERR_ARGUMENT_IN] = "unexpected `in` keyword in arguments",
[PM_ERR_ARGUMENT_NO_FORWARDING_AMP] = "unexpected `&` when the parent method is not forwarding",
[PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES] = "unexpected `...` when the parent method is not forwarding",
[PM_ERR_ARGUMENT_NO_FORWARDING_STAR] = "unexpected `*` when the parent method is not forwarding",
@@ -192,7 +191,6 @@ static const char* const diagnostic_messages[PM_DIAGNOSTIC_ID_LEN] = {
[PM_ERR_MODULE_TERM] = "expected an `end` to close the `module` statement",
[PM_ERR_MULTI_ASSIGN_MULTI_SPLATS] = "multiple splats in multiple assignment",
[PM_ERR_NOT_EXPRESSION] = "expected an expression after `not`",
- [PM_ERR_NO_LOCAL_VARIABLE] = "%.*s: no such local variable",
[PM_ERR_NUMBER_LITERAL_UNDERSCORE] = "number literal ending with a `_`",
[PM_ERR_NUMBERED_PARAMETER_NOT_ALLOWED] = "numbered parameters are not allowed when an ordinary parameter is defined",
[PM_ERR_NUMBERED_PARAMETER_OUTER_SCOPE] = "numbered parameter is already used in outer scope",
diff --git a/prism/diagnostic.h b/prism/diagnostic.h
index 08a3284abf..fc1f0c2b4b 100644
--- a/prism/diagnostic.h
+++ b/prism/diagnostic.h
@@ -53,7 +53,6 @@ typedef enum {
PM_ERR_ARGUMENT_FORMAL_GLOBAL,
PM_ERR_ARGUMENT_FORMAL_IVAR,
PM_ERR_ARGUMENT_FORWARDING_UNBOUND,
- PM_ERR_ARGUMENT_IN,
PM_ERR_ARGUMENT_NO_FORWARDING_AMP,
PM_ERR_ARGUMENT_NO_FORWARDING_ELLIPSES,
PM_ERR_ARGUMENT_NO_FORWARDING_STAR,
@@ -184,7 +183,6 @@ typedef enum {
PM_ERR_MODULE_TERM,
PM_ERR_MULTI_ASSIGN_MULTI_SPLATS,
PM_ERR_NOT_EXPRESSION,
- PM_ERR_NO_LOCAL_VARIABLE,
PM_ERR_NUMBER_LITERAL_UNDERSCORE,
PM_ERR_NUMBERED_PARAMETER_NOT_ALLOWED,
PM_ERR_NUMBERED_PARAMETER_OUTER_SCOPE,
diff --git a/prism/parser.h b/prism/parser.h
index 2c58131b19..7f26054f09 100644
--- a/prism/parser.h
+++ b/prism/parser.h
@@ -17,6 +17,12 @@
#include <stdbool.h>
+// TODO: remove this by renaming the original flag
+/**
+ * Temporary alias for the PM_NODE_FLAG_STATIC_KEYS flag.
+ */
+#define PM_KEYWORD_HASH_NODE_FLAGS_SYMBOL_KEYS PM_KEYWORD_HASH_NODE_FLAGS_STATIC_KEYS
+
/**
* This enum provides various bits that represent different kinds of states that
* the lexer can track. This is used to determine which kind of token to return
diff --git a/prism/prism.c b/prism/prism.c
index ec319f2cac..79258386d6 100644
--- a/prism/prism.c
+++ b/prism/prism.c
@@ -1340,11 +1340,6 @@ pm_assoc_node_create(pm_parser_t *parser, pm_node_t *key, const pm_token_t *oper
flags = key->flags & value->flags & PM_NODE_FLAG_STATIC_LITERAL;
}
- // Hash string keys should be frozen
- if (PM_NODE_TYPE_P(key, PM_STRING_NODE)) {
- key->flags |= PM_STRING_FLAGS_FROZEN;
- }
-
*node = (pm_assoc_node_t) {
{
.type = PM_ASSOC_NODE,
@@ -11343,9 +11338,6 @@ parse_arguments(pm_parser_t *parser, pm_arguments_t *arguments, bool accepts_for
}
parsed_bare_hash = true;
- } else if (accept1(parser, PM_TOKEN_KEYWORD_IN)) {
- // TODO: Could we solve this with binding powers instead?
- pm_parser_err_current(parser, PM_ERR_ARGUMENT_IN);
}
parse_arguments_append(parser, arguments, argument);
@@ -13357,15 +13349,8 @@ parse_pattern_primitive(pm_parser_t *parser, pm_diagnostic_id_t diag_id) {
// expression to determine if it's a variable or an expression.
switch (parser->current.type) {
case PM_TOKEN_IDENTIFIER: {
- int depth = pm_parser_local_depth(parser, &parser->current);
-
- if (depth == -1) {
- depth = 0;
- PM_PARSER_ERR_TOKEN_FORMAT(parser, parser->current, PM_ERR_NO_LOCAL_VARIABLE, (int) (parser->current.end - parser->current.start), parser->current.start);
- }
-
- pm_node_t *variable = (pm_node_t *) pm_local_variable_read_node_create(parser, &parser->current, (uint32_t) depth);
parser_lex(parser);
+ pm_node_t *variable = (pm_node_t *) pm_local_variable_read_node_create(parser, &parser->previous, 0);
return (pm_node_t *) pm_pinned_variable_node_create(parser, &operator, variable);
}
@@ -17190,14 +17175,9 @@ parse_expression(pm_parser_t *parser, pm_binding_power_t binding_power, bool acc
static pm_node_t *
parse_program(pm_parser_t *parser) {
- // If the current scope is NULL, then we want to push a new top level scope.
- // The current scope could exist in the event that we are parsing an eval
- // and the user has passed into scopes that already exist.
- if (parser->current_scope == NULL) {
- pm_parser_scope_push(parser, true);
- }
-
+ pm_parser_scope_push(parser, !parser->current_scope);
parser_lex(parser);
+
pm_statements_node_t *statements = parse_statements(parser, PM_CONTEXT_MAIN);
if (!statements) {
statements = pm_statements_node_create(parser);
diff --git a/prism/templates/lib/prism/node.rb.erb b/prism/templates/lib/prism/node.rb.erb
index 65a4f0fb70..87a94a0338 100644
--- a/prism/templates/lib/prism/node.rb.erb
+++ b/prism/templates/lib/prism/node.rb.erb
@@ -44,11 +44,11 @@ module Prism
<%- end -%>
class <%= node.name -%> < Node
<%- node.fields.each do |field| -%>
- # <%= "private " if field.is_a?(Prism::FlagsField) %>attr_reader <%= field.name %>: <%= field.rbs_class %>
+ # attr_reader <%= field.name %>: <%= field.rbs_class %>
<%= "private " if field.is_a?(Prism::FlagsField) %>attr_reader :<%= field.name %>
<%- end -%>
- # def initialize: (<%= (node.fields.map { |field| "#{field.rbs_class} #{field.name}" } + ["Location location"]).join(", ") %>) -> void
+ # def initialize: (<%= (node.fields.map { |field| "#{field.name}: #{field.rbs_class}" } + ["location: Location"]).join(", ") %>) -> void
def initialize(<%= (node.fields.map(&:name) + ["location"]).join(", ") %>)
<%- node.fields.each do |field| -%>
@<%= field.name %> = <%= field.name %>
@@ -56,7 +56,7 @@ module Prism
@location = location
end
- # def accept: (Visitor visitor) -> void
+ # def accept: (visitor: Visitor) -> void
def accept(visitor)
visitor.visit_<%= node.human %>(self)
end
@@ -137,7 +137,7 @@ module Prism
# def deconstruct: () -> Array[nil | Node]
alias deconstruct child_nodes
- # def deconstruct_keys: (Array[Symbol] keys) -> { <%= (node.fields.map { |field| "#{field.name}: #{field.rbs_class}" } + ["location: Location"]).join(", ") %> }
+ # def deconstruct_keys: (keys: Array[Symbol]) -> Hash[Symbol, nil | Node | Array[Node] | String | Token | Array[Token] | Location]
def deconstruct_keys(keys)
{ <%= (node.fields.map { |field| "#{field.name}: #{field.name}" } + ["location: location"]).join(", ") %> }
end
@@ -170,7 +170,7 @@ module Prism
<%- end -%>
<%- end -%>
- # def inspect(NodeInspector inspector) -> String
+ # def inspect(inspector: NodeInspector) -> String
def inspect(inspector = NodeInspector.new)
inspector << inspector.header(self)
<%- node.fields.each_with_index do |field, index| -%>