chore: bruno lang improve parsing logic of headers and params

This commit is contained in:
Anoop M D 2023-01-15 05:04:35 +05:30
parent 5e1d6cba4a
commit c29ab50a3d
2 changed files with 10 additions and 25 deletions

View File

@ -15,25 +15,18 @@ const {
const newline = regex(/^\r?\n/); const newline = regex(/^\r?\n/);
const newLineOrEndOfInput = choice([newline, endOfInput]); const newLineOrEndOfInput = choice([newline, endOfInput]);
const begin = sequenceOf([
regex(/^headers[^\S\r\n]*/),
newline
]);
const end = sequenceOf([ const begin = regex(/^headers\s*\r?\n/);
regex(/^\/headers[^\S\r\n]*/), const end = regex(/^[\r?\n]*\/headers\s*[\r?\n]*/);
newLineOrEndOfInput const word = regex(/^[^\s\t\n]+/g);
]);
const key = everyCharUntil(whitespace);
const value = everyCharUntil(whitespace);
const line = sequenceOf([ const line = sequenceOf([
optionalWhitespace, optionalWhitespace,
digit, digit,
whitespace, whitespace,
key, word,
whitespace, whitespace,
value, word,
newLineOrEndOfInput newLineOrEndOfInput
]).map(([_, enabled, __, key, ___, value]) => { ]).map(([_, enabled, __, key, ___, value]) => {
return { return {

View File

@ -15,25 +15,17 @@ const {
const newline = regex(/^\r?\n/); const newline = regex(/^\r?\n/);
const newLineOrEndOfInput = choice([newline, endOfInput]); const newLineOrEndOfInput = choice([newline, endOfInput]);
const begin = sequenceOf([ const begin = regex(/^params\s*\r?\n/);
regex(/^params[^\S\r\n]*/), const end = regex(/^[\r?\n]*\/params\s*[\r?\n]*/);
newline const word = regex(/^[^\s\t\n]+/g);
]);
const end = sequenceOf([
regex(/^\/params[^\S\r\n]*/),
newLineOrEndOfInput
]);
const key = everyCharUntil(whitespace);
const value = everyCharUntil(whitespace);
const line = sequenceOf([ const line = sequenceOf([
optionalWhitespace, optionalWhitespace,
digit, digit,
whitespace, whitespace,
key, word,
whitespace, whitespace,
value, word,
newLineOrEndOfInput newLineOrEndOfInput
]).map(([_, enabled, __, key, ___, value]) => { ]).map(([_, enabled, __, key, ___, value]) => {
return { return {