aboutsummaryrefslogtreecommitdiffstats
path: root/prism/prism.h
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2023-12-01 12:22:01 -0500
committergit <svn-admin@ruby-lang.org>2023-12-01 20:53:34 +0000
commit492c82cb417a92d1941f10b52e77ec0c4b2cc8a6 (patch)
tree3358d814456f46c6adb80921e968d1fb5258ce04 /prism/prism.h
parentb77551adee831302f22dc7d9fdccd597923511c4 (diff)
downloadruby-492c82cb417a92d1941f10b52e77ec0c4b2cc8a6.tar.gz
[ruby/prism] Prism.parse_success?(source)
A lot of tools use Ripper/RubyVM::AbstractSyntaxTree to determine if a source is valid. These tools both create an AST instead of providing an API that will return a boolean only. This new API only creates the C structs, but doesn't bother reifying them into Ruby/the serialization API. Instead it only returns true/false, which is significantly more efficient. https://github.com/ruby/prism/commit/7014740118
Diffstat (limited to 'prism/prism.h')
-rw-r--r--prism/prism.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/prism/prism.h b/prism/prism.h
index ab5811f9ac..590cd74016 100644
--- a/prism/prism.h
+++ b/prism/prism.h
@@ -153,6 +153,16 @@ PRISM_EXPORTED_FUNCTION void pm_serialize_lex(pm_buffer_t *buffer, const uint8_t
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
/**
+ * Parse the source and return true if it parses without errors or warnings.
+ *
+ * @param source The source to parse.
+ * @param size The size of the source.
+ * @param data The optional data to pass to the parser.
+ * @return True if the source parses without errors or warnings.
+ */
+PRISM_EXPORTED_FUNCTION bool pm_parse_success_p(const uint8_t *source, size_t size, const char *data);
+
+/**
* Returns a string representation of the given token type.
*
* @param token_type The token type to convert to a string.