From ae49920256ed4702d99fc5d7249855d60b159f8e Mon Sep 17 00:00:00 2001 From: Sharan Roongta Date: Sat, 24 Jul 2021 17:40:27 +0200 Subject: [PATCH] support single and double quotes in key value pairs also escape characters not supported in double quotes --- examples/grid/material.yaml | 14 +++++++------- src/YAML_parse.f90 | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/grid/material.yaml b/examples/grid/material.yaml index b59d235ff..ef35f9281 100644 --- a/examples/grid/material.yaml +++ b/examples/grid/material.yaml @@ -6,29 +6,29 @@ homogenization: phase: Aluminum: - lattice: "cF" + "lattice": 'cF' mechanical: output: [F, P, F_e, F_p, L_p, O] elastic: {type: "Hooke", C_11: 106.75e+9, C_12: 60.41e+9, C_44: 28.34e+9} plastic: - type: phenopowerlaw - N_sl: [12] + 'type': "phenopowerlaw" + "N_sl": [12] a_sl: 2.25 atol_xi: 1.0 dot_gamma_0_sl: 0.001 h_0_sl-sl: 75.e+6 h_sl-sl: [1, 1, 1.4, 1.4, 1.4, 1.4, 1.4] n_sl: 20 - output: ["xi_sl"] + 'output': ['xi_sl'] xi_0_sl: [31.e+6] xi_inf_sl: [63.e+6] material: - homogenization: SX constituents: - - phase: Aluminum - v: 1.0 - O: [1.0, 0.0, 0.0, 0.0] + - 'phase': "Aluminum" + 'v': 1.0 + "O": [1.0, 0.0, 0.0, 0.0] - homogenization: SX constituents: - phase: Aluminum diff --git a/src/YAML_parse.f90 b/src/YAML_parse.f90 index 030cd2735..f876fd71f 100644 --- a/src/YAML_parse.f90 +++ b/src/YAML_parse.f90 @@ -71,8 +71,8 @@ recursive function parse_flow(YAML_flow) result(node) s = e d = s + scan(flow_string(s+1:),':') e = d + find_end(flow_string(d+1:),'}') - key = trim(adjustl(flow_string(s+1:d-1))) + if (key(1:1) == '"' .or. key(1:1) == "'" ) key = key(2:len(key)-1) myVal => parse_flow(flow_string(d+1:e-1)) ! parse items (recursively) select type (node) @@ -97,7 +97,7 @@ recursive function parse_flow(YAML_flow) result(node) allocate(tScalar::node) select type (node) class is (tScalar) - if(flow_string(1:1) == '"') then + if (flow_string(1:1) == '"' .or. flow_string(1:1) == "'") then node = trim(adjustl(flow_string(2:len(flow_string)-1))) else node = trim(adjustl(flow_string)) @@ -125,7 +125,7 @@ integer function find_end(str,e_char) N_cu = 0 i = 1 do while(i<=len_trim(str)) - if (str(i:i) == '"') i = i + scan(str(i+1:),'"') + if (str(i:i) == '"' .or. str(i:i) == "'") i = i + scan(str(i+1:),str(i:i)) if (N_sq==0 .and. N_cu==0 .and. scan(str(i:i),e_char//',') == 1) exit N_sq = N_sq + merge(1,0,str(i:i) == '[') N_cu = N_cu + merge(1,0,str(i:i) == '{')