Skip to content

Commit

Permalink
[PRISM] Sync to latest prism
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Feb 24, 2024
1 parent e439419 commit fc656ac
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
2 changes: 1 addition & 1 deletion prism/prism.c
Expand Up @@ -9829,7 +9829,7 @@ parser_lex(pm_parser_t *parser) {
)
{
// Since we know we're about to add an __END__ comment, we know we
// need to add all of the newlines to get the correct column
// need at add all of the newlines to get the correct column
// information for it.
const uint8_t *cursor = parser->current.end;
while ((cursor = next_newline(cursor, parser->end - cursor)) != NULL) {
Expand Down
49 changes: 45 additions & 4 deletions prism/templates/template.rb
Expand Up @@ -10,6 +10,39 @@ module Prism
JAVA_BACKEND = ENV["PRISM_JAVA_BACKEND"] || "truffleruby"
JAVA_STRING_TYPE = JAVA_BACKEND == "jruby" ? "org.jruby.RubySymbol" : "String"

# This module contains methods for escaping characters in JavaDoc comments.
module JavaDoc
ESCAPES = {
"'" => "'",
"\"" => """,
"@" => "@",
"&" => "&",
"<" => "&lt;",
">" => "&gt;"
}.freeze

def self.escape(value)
value.gsub(/['&"<>@]/, ESCAPES)
end
end

# A comment attached to a field or node.
class Comment
attr_reader :value

def initialize(value)
@value = value
end

def each_line(&block)
value.each_line { |line| yield line.prepend(" ").rstrip }
end

def each_java_line(&block)
Comment.new(JavaDoc.escape(value)).each_line(&block)
end
end

# This represents a field on a node. It contains all of the necessary
# information to template out the code for that field.
class Field
Expand All @@ -21,8 +54,12 @@ def initialize(name:, comment: nil, **options)
@options = options
end

def each_comment_line
comment.each_line { |line| yield line.prepend(" ").rstrip } if comment
def each_comment_line(&block)
Comment.new(comment).each_line(&block) if comment
end

def each_comment_java_line(&block)
Comment.new(comment).each_java_line(&block) if comment
end

def semantic_field?
Expand Down Expand Up @@ -317,8 +354,12 @@ def initialize(config)
@comment = config.fetch("comment")
end

def each_comment_line
comment.each_line { |line| yield line.prepend(" ").rstrip }
def each_comment_line(&block)
Comment.new(comment).each_line(&block)
end

def each_comment_java_line(&block)
Comment.new(comment).each_java_line(&block)
end

def semantic_fields
Expand Down

0 comments on commit fc656ac

Please sign in to comment.