From fa0604515ae01baa8d260482e7e457723b87f214 Mon Sep 17 00:00:00 2001 From: Bart Debersaques Date: Fri, 23 Jan 2026 16:55:11 +0100 Subject: [PATCH] fix: fix: applies pattern of c_double_quoted to provide c_single_quoted, uncommented in c_flow_json_content in occordence to https://yaml.org/spec/1.2.2/#rule-c-flow-json-content as shared missing in https://github.com/moosetechnology/PetitParser/issues/66 --- .../PPYAMLGrammarTest.class.st | 11 +++ src/PetitYAML/PPYAMLGrammar.class.st | 93 ++++++++++++++++++- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/src/PetitYAML-Tests/PPYAMLGrammarTest.class.st b/src/PetitYAML-Tests/PPYAMLGrammarTest.class.st index 7529d2a..d0edab7 100644 --- a/src/PetitYAML-Tests/PPYAMLGrammarTest.class.st +++ b/src/PetitYAML-Tests/PPYAMLGrammarTest.class.st @@ -647,6 +647,17 @@ PPYAMLGrammarTest >> test_c_l_literal_strip [ self assert: result = '# text' ] +{ #category : #tests } +PPYAMLGrammarTest >> test_c_single_qouted [ + self parse: '''hi there''' rule: #c_single_quoted. + self assert: result = 'hi there'. + + self parse: ''' 1st non-empty + 2nd non-empty + 3rd non-empty ''' rule: #c_single_quoted. + self assert: result = ' 1st non-empty 2nd non-empty 3rd non-empty '. +] + { #category : #spec } PPYAMLGrammarTest >> test_l_block_mapping [ context YAMLN: -1. diff --git a/src/PetitYAML/PPYAMLGrammar.class.st b/src/PetitYAML/PPYAMLGrammar.class.st index 7654a12..e4fa39a 100644 --- a/src/PetitYAML/PPYAMLGrammar.class.st +++ b/src/PetitYAML/PPYAMLGrammar.class.st @@ -138,7 +138,17 @@ Class { 'l_block_sequence', 'l_block_mapping', 'l_bare_document', - 'aligns' + 'aligns', + 'c_single_quoted', + 'nb_single_text', + 'nb_single_multi_line', + 'nb_single_one_line', + 'nb_ns_single_in_line', + 's_single_next_line', + 'nb_single_char', + 'ns_single_char', + 's_single_escaped', + 's_single_break' ], #category : #PetitYAML } @@ -294,7 +304,7 @@ PPYAMLGrammar >> c_flow_indicator [ PPYAMLGrammar >> c_flow_json_content [ ^ c_flow_sequence / c_flow_mapping / - "c_single_quoted /" + c_single_quoted / c_double_quoted ] @@ -467,6 +477,15 @@ PPYAMLGrammar >> c_s_implicit_json_key [ ^ c_flow_json_node, s_separate_in_line optional ==> #first ] +{ #category : #spec } +PPYAMLGrammar >> c_single_quoted [ + ^ ($' asParser, nb_single_text, $' asParser) map: [ :first :text :second | + "first asString, text, second asString" + text + ] + +] + { #category : #spec } PPYAMLGrammar >> e_node [ ^ e_scalar @@ -748,6 +767,40 @@ PPYAMLGrammar >> nb_ns_plain_in_line [ ^ (s_white star, ns_plain_char) star flatten ] +{ #category : #spec } +PPYAMLGrammar >> nb_ns_single_in_line [ + ^ ( s_white star, ns_single_char) star flatten +] + +{ #category : #spec } +PPYAMLGrammar >> nb_single_char [ + ^ ($/ asParser not, $' asParser not), nb_json ==> #third +] + +{ #category : #spec } +PPYAMLGrammar >> nb_single_multi_line [ + ^ nb_ns_single_in_line, (s_single_next_line / (s_white star flatten)) + + map: [ :first :rest | + first, rest + ] + +] + +{ #category : #spec } +PPYAMLGrammar >> nb_single_one_line [ + ^ nb_single_char star flatten +] + +{ #category : #spec } +PPYAMLGrammar >> nb_single_text [ + ^ + (nb_single_multi_line if: [:context | context YAMLContext = #'flow-out' ]) / + (nb_single_multi_line if: [:context | context YAMLContext = #'flow-in' ]) / + (nb_single_one_line if: [:context | context YAMLContext = #'block-key' ]) / + (nb_single_one_line if: [:context | context YAMLContext = #'flow-key' ]) +] + { #category : #spec } PPYAMLGrammar >> ns_char [ ^ s_white not, nb_char ==> #second @@ -989,6 +1042,11 @@ PPYAMLGrammar >> ns_s_implicit_yaml_key [ ^ ns_flow_yaml_node, s_separate_in_line optional ==> #first ] +{ #category : #spec } +PPYAMLGrammar >> ns_single_char [ + ^ s_white not, nb_single_char ==> #second +] + { #category : #spec } PPYAMLGrammar >> s_b_comment [ ^ ( s_separate_in_line, c_nb_comment_text optional ) optional, b_comment @@ -1185,6 +1243,37 @@ PPYAMLGrammar >> s_separate_lines [ s_separate_in_line ] +{ #category : #spec } +PPYAMLGrammar >> s_single_break [ + ^ s_flow_folded / s_single_escaped + +] + +{ #category : #spec } +PPYAMLGrammar >> s_single_escaped [ + ^ PPFailingParser message: 's_single_escaped not yet implemented' +] + +{ #category : #spec } +PPYAMLGrammar >> s_single_next_line [ + ^ s_single_break, ( ns_single_char, nb_ns_single_in_line, + (s_single_next_line / (s_white star flatten))) optional + + map: [ :break :rest | + | retval | + retval := break. + rest ifNotNil: [ + retval := retval, rest first asString. + retval := retval, rest second. + rest third ifNotNil: [ + retval := retval, rest third. + ]. + retval + ] + ]. + +] + { #category : #spec } PPYAMLGrammar >> s_space [ ^ Character space asParser