fhttp-core 2.1.0

core library for the fhttp tool
Documentation
WHITESPACE = _{ " " }
COMMENT = _{ "#" ~ (!NEWLINE ~ ANY)* ~ NEWLINE }

method = @{ ASCII_ALPHANUMERIC+ }
url = @{ (!NEWLINE ~ ANY)+ }

first_line = { method ~ url }
// ascii 33-126, except ":" according to https://stackoverflow.com/questions/47687379/what-characters-are-allowed-in-http-header-values
header_tokens = { "!" | "\"" | "#" | "$" | "%" | "&" | "'" | "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | ";" | "<" | "=" | ">" | "?" | "@" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "[" | "\\" | "]" | "^" | "_" | "`" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "{" | "|" | "}" | "~" }
header_name = { header_tokens+ }
header_value = { (LETTER | NUMBER | PUNCTUATION | SYMBOL | " ")+ }
header_line = { header_name ~ ":" ~ header_value }

body = { (!NEWLINE{2,} ~ ANY)* }

body_and_response_handler = _{ body ~ NEWLINE{2,} ~ response_handler }

response_handler_end = _{ "%}" }
response_handler_exp = { (!response_handler_end ~ ANY)+ }
response_handler_json = { "json" ~ response_handler_exp }
response_handler_deno = { "deno" ~ response_handler_exp }
response_handler_impl = _{
	response_handler_json |
	response_handler_deno
}
response_handler = _{
	">" ~ "{%" ~ NEWLINE* ~
	response_handler_impl ~
	response_handler_end
}

file = {
	SOI ~
	first_line ~ NEWLINE? ~
	(header_line ~ NEWLINE?)* ~
	NEWLINE* ~
	(
		(response_handler) |
		(body_and_response_handler) |
		body
	) ~
	NEWLINE* ~
	EOI
}