From eb16dde4c3acc2e140bff96ed43e3fc0fc554c90 Mon Sep 17 00:00:00 2001 From: Fabrice Reix Date: Sat, 16 Nov 2024 10:31:14 +0100 Subject: [PATCH] Treat Hurl string as template --- docs/spec/grammar/hurl.grammar | 31 +++---- packages/hurl_core/src/parser/filename.rs | 5 +- .../hurl_core/src/parser/filename_password.rs | 5 +- packages/hurl_core/src/parser/json.rs | 4 +- packages/hurl_core/src/parser/key_string.rs | 5 +- packages/hurl_core/src/parser/mod.rs | 1 + packages/hurl_core/src/parser/option.rs | 10 +-- packages/hurl_core/src/parser/placeholder.rs | 85 +++++++++++++++++++ .../hurl_core/src/parser/predicate_value.rs | 4 +- packages/hurl_core/src/parser/template.rs | 64 +------------- 10 files changed, 121 insertions(+), 93 deletions(-) create mode 100644 packages/hurl_core/src/parser/placeholder.rs diff --git a/docs/spec/grammar/hurl.grammar b/docs/spec/grammar/hurl.grammar index af95b3c190b..fcc83373306 100644 --- a/docs/spec/grammar/hurl.grammar +++ b/docs/spec/grammar/hurl.grammar @@ -225,11 +225,11 @@ very-verbose-option: "very-verbose" ":" boolean-option lt variable-definition: variable-name "=" variable-value -boolean-option: boolean | template +boolean-option: boolean | placeholder -integer-option: integer | template +integer-option: integer | placeholder -duration-option: (integer duration-unit?) | template +duration-option: (integer duration-unit?) | placeholder duration-unit: "ms" | "s" | "m" @@ -364,7 +364,7 @@ predicate-value: | oneline-file | oneline-hex | quoted-string - | template + | placeholder # Bytes @@ -391,7 +391,7 @@ oneline-hex: "hex," hexdigit* ";" # Strings -quoted-string: "\"" (quoted-string-content | template)* "\"" +quoted-string: "\"" (quoted-string-content | placeholder)* "\"" quoted-string-content: (quoted-string-text | quoted-string-escaped-char)* @@ -400,7 +400,7 @@ quoted-string-text: ~["\\]+ quoted-string-escaped-char: "\\" ("\"" | "\\" | "\b" | "\f" | "\n" | "\r" | "\t" | "\u" unicode-char) -key-string: (key-string-content | template)+ +key-string: (key-string-content | placeholder)+ key-string-content: (key-string-text | key-string-escaped-char)* @@ -409,7 +409,7 @@ key-string-text: (alphanum | "_" | "-" | "." | "[" | "]" | "@" | "$") + key-string-escaped-char: "\\" ("#" | ":" | "\\" | "\b" | "\f" | "\n" | "\r" | "\t" | "\u" unicode-char ) -value-string: (value-string-content | template)* +value-string: (value-string-content | placeholder)* value-string-content: (value-string-text | value-string-escaped-char)* @@ -418,7 +418,7 @@ value-string-text: ~[#\n\\]+ value-string-escaped-char: "\\" ("#" | "\\" | "\b" | "\f" | "\n" | "\r" | "\t" | "\u" unicode-char ) -oneline-string: "`" (oneline-string-content | template)* "`" +oneline-string: "`" (oneline-string-content | placeholder)* "`" oneline-string-content: (oneline-string-text | oneline-string-escaped-char)* @@ -429,7 +429,7 @@ oneline-string-escaped-char: "\\" ("`" | "#" | "\\" | "b" | "f" | "u" unicode-ch multiline-string: "```" multiline-string-type? ("," multiline-string-attribute)* lt - (multiline-string-content | template)* lt + (multiline-string-content | placeholder)* lt "```" multiline-string-type: @@ -449,7 +449,7 @@ multiline-string-text: ~[\\]+ ~"```" multiline-string-escaped-char: "\\" ( "\\" | "b" | "f" | "n" | "r" | "t" | "`" | "u" unicode-char) -filename: (filename-content | template)* +filename: (filename-content | placeholder)* filename-content: (filename-text | filename-escaped-char)* @@ -458,7 +458,7 @@ filename-text: ~[#;{} \n\\]+ filename-escaped-char: "\\" ( "\\" | "b" | "f" | "n" | "r" | "t" | "#" | ";"| " " | "{" | "}" | "u" unicode-char) -filename-password: (filename-password-content | template)* +filename-password: (filename-password-content | placeholder)* filename-password-content: (filename-password-text | filename-password-escaped-char)* @@ -470,10 +470,11 @@ unicode-char: "{" hexdigit+ "}" + # JSON json-value: - template + placeholder | json-object | json-array | json-string @@ -487,7 +488,7 @@ json-key-value: json-string ":" json-value json-array: "[" json-value ("," json-value)* "]" -json-string: "\"" (json-string-content | template)* "\"" +json-string: "\"" (json-string-content | placeholder)* "\"" json-string-content: json-string-text | json-string-escaped-char @@ -499,9 +500,9 @@ json-string-escaped-char: json-number: integer fraction? exponent? -# Template / Expression +# Expression -template: "{{" expr "}}" +placeholder: "{{" expr "}}" expr: (variable-name | function) (sp filter)* diff --git a/packages/hurl_core/src/parser/filename.rs b/packages/hurl_core/src/parser/filename.rs index c8f45811bba..28f1add618c 100644 --- a/packages/hurl_core/src/parser/filename.rs +++ b/packages/hurl_core/src/parser/filename.rs @@ -18,10 +18,11 @@ use crate::ast::*; use crate::parser::error::*; use crate::parser::primitives::try_literal; -use crate::parser::template; use crate::parser::{string, ParseResult}; use crate::reader::Reader; +use super::placeholder; + /// Parse a filename. /// /// A few characters need to be escaped such as space @@ -34,7 +35,7 @@ pub fn parse(reader: &mut Reader) -> ParseResult