mirror of
https://github.com/ruby/ruby.git
synced 2025-08-25 14:05:02 +02:00
[PRISM] Sync to latest prism
This commit is contained in:
parent
e439419baa
commit
fc656acee9
2 changed files with 46 additions and 5 deletions
|
@ -9829,7 +9829,7 @@ parser_lex(pm_parser_t *parser) {
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
// Since we know we're about to add an __END__ comment, we know we
|
// 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.
|
// information for it.
|
||||||
const uint8_t *cursor = parser->current.end;
|
const uint8_t *cursor = parser->current.end;
|
||||||
while ((cursor = next_newline(cursor, parser->end - cursor)) != NULL) {
|
while ((cursor = next_newline(cursor, parser->end - cursor)) != NULL) {
|
||||||
|
|
|
@ -10,6 +10,39 @@ module Prism
|
||||||
JAVA_BACKEND = ENV["PRISM_JAVA_BACKEND"] || "truffleruby"
|
JAVA_BACKEND = ENV["PRISM_JAVA_BACKEND"] || "truffleruby"
|
||||||
JAVA_STRING_TYPE = JAVA_BACKEND == "jruby" ? "org.jruby.RubySymbol" : "String"
|
JAVA_STRING_TYPE = JAVA_BACKEND == "jruby" ? "org.jruby.RubySymbol" : "String"
|
||||||
|
|
||||||
|
# This module contains methods for escaping characters in JavaDoc comments.
|
||||||
|
module JavaDoc
|
||||||
|
ESCAPES = {
|
||||||
|
"'" => "'",
|
||||||
|
"\"" => """,
|
||||||
|
"@" => "@",
|
||||||
|
"&" => "&",
|
||||||
|
"<" => "<",
|
||||||
|
">" => ">"
|
||||||
|
}.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
|
# This represents a field on a node. It contains all of the necessary
|
||||||
# information to template out the code for that field.
|
# information to template out the code for that field.
|
||||||
class Field
|
class Field
|
||||||
|
@ -21,8 +54,12 @@ module Prism
|
||||||
@options = options
|
@options = options
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_comment_line
|
def each_comment_line(&block)
|
||||||
comment.each_line { |line| yield line.prepend(" ").rstrip } if comment
|
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
|
end
|
||||||
|
|
||||||
def semantic_field?
|
def semantic_field?
|
||||||
|
@ -317,8 +354,12 @@ module Prism
|
||||||
@comment = config.fetch("comment")
|
@comment = config.fetch("comment")
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_comment_line
|
def each_comment_line(&block)
|
||||||
comment.each_line { |line| yield line.prepend(" ").rstrip }
|
Comment.new(comment).each_line(&block)
|
||||||
|
end
|
||||||
|
|
||||||
|
def each_comment_java_line(&block)
|
||||||
|
Comment.new(comment).each_java_line(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def semantic_fields
|
def semantic_fields
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue