Class: Foxtail::Syntax::Parser::AST::StringLiteral
- Inherits:
-
BaseLiteral
- Object
- BaseNode
- SyntaxNode
- BaseLiteral
- Foxtail::Syntax::Parser::AST::StringLiteral
- Defined in:
- lib/foxtail/syntax/parser/ast/string_literal.rb
Overview
Represents quoted string literals with escape sequence processing
Instance Attribute Summary
Attributes inherited from BaseLiteral
Attributes inherited from SyntaxNode
Attributes inherited from BaseNode
Instance Method Summary collapse
-
#parse ⇒ Hash
Parse the string literal value, processing escape sequences Handles backslash escapes, Unicode escapes (uHHHH, UHHHHHH), and validates Unicode scalar values.
Methods inherited from BaseLiteral
Methods inherited from SyntaxNode
Methods inherited from BaseNode
#==, #accept, #children, #initialize, #to_h
Constructor Details
This class inherits a constructor from Foxtail::Syntax::Parser::AST::BaseLiteral
Instance Method Details
#parse ⇒ Hash
Parse the string literal value, processing escape sequences Handles backslash escapes, Unicode escapes (uHHHH, UHHHHHH), and validates Unicode scalar values
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/foxtail/syntax/parser/ast/string_literal.rb', line 12 def parse # Backslash backslash, backslash double quote, uHHHH, UHHHHHH. known_escapes = /(?:\\\\|\\"|\\u(\h{4})|\\U(\h{6}))/ escaped_value = @value.gsub(known_escapes) {|match| codepoint4 = $1 codepoint6 = $2 case match when "\\\\" "\\" when '\\"' '"' else codepoint = (codepoint4 || codepoint6).to_i(16) if codepoint <= 0xd7ff || 0xe000 <= codepoint # It's a Unicode scalar value. codepoint.chr(Encoding::UTF_8) else # Escape sequences representing surrogate code points are # well-formed but invalid in Fluent. Replace them with U+FFFD # REPLACEMENT CHARACTER. "\uFFFD" end end } {value: escaped_value} end |