Module: Ibex::Frontend::GeneratedParserMetadata
- Included in:
- GeneratedParserBase
- Defined in:
- lib/ibex/frontend/generated_parser_metadata.rb,
sig/ibex/frontend/generated_parser_metadata.rbs
Overview
Builds extended symbol metadata declarations for the generated grammar parser.
Instance Method Summary collapse
- #build_display_name(keyword, name, value) ⇒ AST::DisplayName
- #build_semantic_type(keyword, name, value) ⇒ AST::SemanticType
- #build_symbol_metadata(node_class, keyword, name, value, feature) ⇒ AST::DisplayName, AST::SemanticType
- #decode_metadata_value(token, feature) ⇒ String
Instance Method Details
#build_display_name(keyword, name, value) ⇒ AST::DisplayName
10 11 12 13 14 15 16 17 |
# File 'lib/ibex/frontend/generated_parser_metadata.rb', line 10 def build_display_name(keyword, name, value) # @type self: GeneratedParserBase extended_only!(keyword.location, "display declarations") result = (AST::DisplayName, keyword, name, value, "display") return result if result.is_a?(AST::DisplayName) raise Ibex::Error, "display metadata builder returned the wrong node" end |
#build_semantic_type(keyword, name, value) ⇒ AST::SemanticType
20 21 22 23 24 25 26 27 |
# File 'lib/ibex/frontend/generated_parser_metadata.rb', line 20 def build_semantic_type(keyword, name, value) # @type self: GeneratedParserBase extended_only!(keyword.location, "type declarations") result = (AST::SemanticType, keyword, name, value, "type") return result if result.is_a?(AST::SemanticType) raise Ibex::Error, "type metadata builder returned the wrong node" end |
#build_symbol_metadata(node_class, keyword, name, value, feature) ⇒ AST::DisplayName, AST::SemanticType
31 32 33 34 35 36 37 38 39 |
# File 'lib/ibex/frontend/generated_parser_metadata.rb', line 31 def (node_class, keyword, name, value, feature) # @type self: GeneratedParserBase unless keyword.location.line == name.location.line && name.location.line == value.location.line fail_at(keyword.location, "#{feature} declaration must be written on one line") end decoded = (value, feature) node_class.new(name: token_string(name), value: decoded, loc: keyword.location) end |
#decode_metadata_value(token, feature) ⇒ String
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ibex/frontend/generated_parser_metadata.rb', line 42 def (token, feature) # @type self: GeneratedParserBase literal = token_string(token) decoded = if literal.start_with?('"') literal.undump else (literal[1...-1] || "").gsub("\\'", "'").gsub("\\\\", "\\") end fail_at(token.location, "#{feature} value must not be empty") if decoded.strip.empty? fail_at(token.location, "#{feature} value must be a single line") if decoded.match?(/[\r\n]/) fail_at(token.location, "#{feature} value must not contain control characters") if decoded.match?(/[[:cntrl:]]/) decoded rescue RuntimeError => e fail_at(token.location, "invalid #{feature} value: #{e.}") end |