From c29ab50a3ddbdb34f3fdf25f41e709fff7bb07a4 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sun, 15 Jan 2023 05:04:35 +0530 Subject: [PATCH] chore: bruno lang improve parsing logic of headers and params --- packages/bruno-lang/src/headers-tag.js | 17 +++++------------ packages/bruno-lang/src/params-tag.js | 18 +++++------------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/packages/bruno-lang/src/headers-tag.js b/packages/bruno-lang/src/headers-tag.js index 5441bd00a..e371f152f 100644 --- a/packages/bruno-lang/src/headers-tag.js +++ b/packages/bruno-lang/src/headers-tag.js @@ -15,25 +15,18 @@ const { const newline = regex(/^\r?\n/); const newLineOrEndOfInput = choice([newline, endOfInput]); -const begin = sequenceOf([ - regex(/^headers[^\S\r\n]*/), - newline -]); -const end = sequenceOf([ - regex(/^\/headers[^\S\r\n]*/), - newLineOrEndOfInput -]); -const key = everyCharUntil(whitespace); -const value = everyCharUntil(whitespace); +const begin = regex(/^headers\s*\r?\n/); +const end = regex(/^[\r?\n]*\/headers\s*[\r?\n]*/); +const word = regex(/^[^\s\t\n]+/g); const line = sequenceOf([ optionalWhitespace, digit, whitespace, - key, + word, whitespace, - value, + word, newLineOrEndOfInput ]).map(([_, enabled, __, key, ___, value]) => { return { diff --git a/packages/bruno-lang/src/params-tag.js b/packages/bruno-lang/src/params-tag.js index a87c3a34f..d2cdbb02a 100644 --- a/packages/bruno-lang/src/params-tag.js +++ b/packages/bruno-lang/src/params-tag.js @@ -15,25 +15,17 @@ const { const newline = regex(/^\r?\n/); const newLineOrEndOfInput = choice([newline, endOfInput]); -const begin = sequenceOf([ - regex(/^params[^\S\r\n]*/), - newline -]); - -const end = sequenceOf([ - regex(/^\/params[^\S\r\n]*/), - newLineOrEndOfInput -]); -const key = everyCharUntil(whitespace); -const value = everyCharUntil(whitespace); +const begin = regex(/^params\s*\r?\n/); +const end = regex(/^[\r?\n]*\/params\s*[\r?\n]*/); +const word = regex(/^[^\s\t\n]+/g); const line = sequenceOf([ optionalWhitespace, digit, whitespace, - key, + word, whitespace, - value, + word, newLineOrEndOfInput ]).map(([_, enabled, __, key, ___, value]) => { return {