Skip to content

Commit

Permalink
Remaining naming cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Sep 26, 2023
1 parent 9bc3be7 commit 9ea8d27
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 63 deletions.
14 changes: 7 additions & 7 deletions rust/prism-sys/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions rust/prism/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions rust/prism/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn struct_name(name: &str) -> String {
/// Returns the name of the C type from the given node name.
fn type_name(name: &str) -> String {
let mut result = String::with_capacity(8 + name.len());
result.push_str("YP");
result.push_str("PM");

for char in name.chars() {
if char.is_uppercase() {
Expand Down Expand Up @@ -155,10 +155,10 @@ fn write_node(file: &mut File, node: &Node) -> Result<(), Box<dyn std::error::Er
writeln!(file, " parser: NonNull<pm_parser_t>,")?;
writeln!(file)?;
writeln!(file, " /// The raw pointer to the node allocated by prism.")?;
writeln!(file, " pointer: *mut yp{}_t,", struct_name(&node.name))?;
writeln!(file, " pointer: *mut pm{}_t,", struct_name(&node.name))?;
writeln!(file)?;
writeln!(file, " /// The marker to indicate the lifetime of the pointer.")?;
writeln!(file, " marker: PhantomData<&'pr mut yp{}_t>", struct_name(&node.name))?;
writeln!(file, " marker: PhantomData<&'pr mut pm{}_t>", struct_name(&node.name))?;
writeln!(file, "}}")?;
writeln!(file)?;
writeln!(file, "impl<'pr> {}<'pr> {{", node.name)?;
Expand All @@ -184,7 +184,7 @@ fn write_node(file: &mut File, node: &Node) -> Result<(), Box<dyn std::error::Er
NodeFieldType::Node => {
if let Some(kind) = &field.kind {
writeln!(file, " pub fn {}(&self) -> {}<'pr> {{", field.name, kind)?;
writeln!(file, " let node: *mut yp{}_t = unsafe {{ (*self.pointer).{} }};", struct_name(kind), field.name)?;
writeln!(file, " let node: *mut pm{}_t = unsafe {{ (*self.pointer).{} }};", struct_name(kind), field.name)?;
writeln!(file, " {} {{ parser: self.parser, pointer: node, marker: PhantomData }}", kind)?;
writeln!(file, " }}")?;
} else {
Expand All @@ -197,7 +197,7 @@ fn write_node(file: &mut File, node: &Node) -> Result<(), Box<dyn std::error::Er
NodeFieldType::OptionalNode => {
if let Some(kind) = &field.kind {
writeln!(file, " pub fn {}(&self) -> Option<{}<'pr>> {{", field.name, kind)?;
writeln!(file, " let node: *mut yp{}_t = unsafe {{ (*self.pointer).{} }};", struct_name(kind), field.name)?;
writeln!(file, " let node: *mut pm{}_t = unsafe {{ (*self.pointer).{} }};", struct_name(kind), field.name)?;
writeln!(file, " if node.is_null() {{")?;
writeln!(file, " None")?;
writeln!(file, " }} else {{")?;
Expand Down Expand Up @@ -637,10 +637,10 @@ impl std::fmt::Debug for ConstantList<'_> {{
writeln!(file, " parser: NonNull<pm_parser_t>,")?;
writeln!(file)?;
writeln!(file, " /// The raw pointer to the node allocated by prism.")?;
writeln!(file, " pointer: *mut yp{}_t,", struct_name(&node.name))?;
writeln!(file, " pointer: *mut pm{}_t,", struct_name(&node.name))?;
writeln!(file)?;
writeln!(file, " /// The marker to indicate the lifetime of the pointer.")?;
writeln!(file, " marker: PhantomData<&'pr mut yp{}_t>", struct_name(&node.name))?;
writeln!(file, " marker: PhantomData<&'pr mut pm{}_t>", struct_name(&node.name))?;
writeln!(file, " }},")?;
}

Expand All @@ -661,7 +661,7 @@ impl<'pr> Node<'pr> {{
"#)?;

for node in &config.nodes {
writeln!(file, " {} => Self::{} {{ parser, pointer: node.cast::<yp{}_t>(), marker: PhantomData }},", type_name(&node.name), node.name, struct_name(&node.name))?;
writeln!(file, " {} => Self::{} {{ parser, pointer: node.cast::<pm{}_t>(), marker: PhantomData }},", type_name(&node.name), node.name, struct_name(&node.name))?;
}

writeln!(file, " _ => panic!(\"Unknown node type: {{}}\", unsafe {{ (*node).type_ }})")?;
Expand Down
30 changes: 15 additions & 15 deletions src/regexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,33 +281,33 @@ typedef enum {

// These are the options that are configurable on the regular expression (or
// from within a group).
#define PM_REGEXP_OPTION_STATE_SLOT_MINIMUM 'a'
#define PM_REGEXP_OPTION_STATE_SLOT_MAXIMUM 'x'
#define PM_REGEXP_OPTION_STATE_SLOTS (PM_REGEXP_OPTION_STATE_SLOT_MAXIMUM - PM_REGEXP_OPTION_STATE_SLOT_MINIMUM + 1)
#define PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUM 'a'
#define PRISM_REGEXP_OPTION_STATE_SLOT_MAXIMUM 'x'
#define PRISM_REGEXP_OPTION_STATE_SLOTS (PRISM_REGEXP_OPTION_STATE_SLOT_MAXIMUM - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUM + 1)

// This is the set of options that are configurable on the regular expression.
typedef struct {
uint8_t values[PM_REGEXP_OPTION_STATE_SLOTS];
uint8_t values[PRISM_REGEXP_OPTION_STATE_SLOTS];
} pm_regexp_options_t;

// Initialize a new set of options to their default values.
static void
pm_regexp_options_init(pm_regexp_options_t *options) {
memset(options, PM_REGEXP_OPTION_STATE_INVALID, sizeof(uint8_t) * PM_REGEXP_OPTION_STATE_SLOTS);
options->values['i' - PM_REGEXP_OPTION_STATE_SLOT_MINIMUM] = PM_REGEXP_OPTION_STATE_TOGGLEABLE;
options->values['m' - PM_REGEXP_OPTION_STATE_SLOT_MINIMUM] = PM_REGEXP_OPTION_STATE_TOGGLEABLE;
options->values['x' - PM_REGEXP_OPTION_STATE_SLOT_MINIMUM] = PM_REGEXP_OPTION_STATE_TOGGLEABLE;
options->values['d' - PM_REGEXP_OPTION_STATE_SLOT_MINIMUM] = PM_REGEXP_OPTION_STATE_ADDABLE;
options->values['a' - PM_REGEXP_OPTION_STATE_SLOT_MINIMUM] = PM_REGEXP_OPTION_STATE_ADDABLE;
options->values['u' - PM_REGEXP_OPTION_STATE_SLOT_MINIMUM] = PM_REGEXP_OPTION_STATE_ADDABLE;
memset(options, PM_REGEXP_OPTION_STATE_INVALID, sizeof(uint8_t) * PRISM_REGEXP_OPTION_STATE_SLOTS);
options->values['i' - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUM] = PM_REGEXP_OPTION_STATE_TOGGLEABLE;
options->values['m' - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUM] = PM_REGEXP_OPTION_STATE_TOGGLEABLE;
options->values['x' - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUM] = PM_REGEXP_OPTION_STATE_TOGGLEABLE;
options->values['d' - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUM] = PM_REGEXP_OPTION_STATE_ADDABLE;
options->values['a' - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUM] = PM_REGEXP_OPTION_STATE_ADDABLE;
options->values['u' - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUM] = PM_REGEXP_OPTION_STATE_ADDABLE;
}

// Attempt to add the given option to the set of options. Returns true if it was
// added, false if it was already present.
static bool
pm_regexp_options_add(pm_regexp_options_t *options, uint8_t key) {
if (key >= PM_REGEXP_OPTION_STATE_SLOT_MINIMUM && key <= PM_REGEXP_OPTION_STATE_SLOT_MAXIMUM) {
key = (uint8_t) (key - PM_REGEXP_OPTION_STATE_SLOT_MINIMUM);
if (key >= PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUM && key <= PRISM_REGEXP_OPTION_STATE_SLOT_MAXIMUM) {
key = (uint8_t) (key - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUM);

switch (options->values[key]) {
case PM_REGEXP_OPTION_STATE_INVALID:
Expand All @@ -329,8 +329,8 @@ pm_regexp_options_add(pm_regexp_options_t *options, uint8_t key) {
// it was removed, false if it was already absent.
static bool
pm_regexp_options_remove(pm_regexp_options_t *options, uint8_t key) {
if (key >= PM_REGEXP_OPTION_STATE_SLOT_MINIMUM && key <= PM_REGEXP_OPTION_STATE_SLOT_MAXIMUM) {
key = (uint8_t) (key - PM_REGEXP_OPTION_STATE_SLOT_MINIMUM);
if (key >= PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUM && key <= PRISM_REGEXP_OPTION_STATE_SLOT_MAXIMUM) {
key = (uint8_t) (key - PRISM_REGEXP_OPTION_STATE_SLOT_MINIMUM);

switch (options->values[key]) {
case PM_REGEXP_OPTION_STATE_INVALID:
Expand Down
2 changes: 1 addition & 1 deletion test/prism/library_symbols_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_librubyparser_a_contains_hidden_pm_symbols
omit("librubyparser.a is not built") unless File.exist?(@librubyparser_a)

names(hidden_global_objdump_symbols(@librubyparser_a)).tap do |symbols|
assert_includes(symbols, "pm__parse")
assert_includes(symbols, "pm_parse")
assert_includes(symbols, "pm_version")
end
end
Expand Down
18 changes: 2 additions & 16 deletions test/prism/newline_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@

module Prism
class NewlineTest < TestCase
class NewlineVisitor < Visitor
attr_reader :source, :newlines

def initialize(source)
@source = source
@newlines = []
end

def visit(node)
newlines << source.line(node.location.start_offset) if node&.newline?
super(node)
end
end

base = File.dirname(__dir__)
Dir["{lib,test}/**/*.rb", base: base].each do |relative|
define_method("test_newline_flags_#{relative}") do
Expand All @@ -36,7 +22,7 @@ def assert_newlines(base, relative)

result = Prism.parse_file(filepath)
assert_empty result.errors
actual = yarp_lines(result)
actual = prism_lines(result)

source.each_line.with_index(1) do |line, line_number|
# Lines like `while (foo = bar)` result in two line flags in the
Expand Down Expand Up @@ -88,7 +74,7 @@ def rubyvm_lines(source)
lines.sort
end

def yarp_lines(result)
def prism_lines(result)
result.mark_newlines!

queue = [result.value]
Expand Down

0 comments on commit 9ea8d27

Please sign in to comment.