curl-parser-ruben4ick

Crates.iocurl-parser-ruben4ick
lib.rscurl-parser-ruben4ick
version0.1.0
created_at2025-11-10 20:28:49.650472+00
updated_at2025-11-10 20:28:49.650472+00
descriptionA parser that takes a curl command as plain text input, parses it, and extracts structured information from it.
homepage
repositoryhttps://github.com/ruben4ick/curl-parser
max_upload_size
id1926108
size26,912
Anton Ruban (ruben4ick)

documentation

README

Curl Parser

A parser that takes a curl command as plain text input, parses it, and extracts structured information from it.

Technical description

It reads a single curl command and extracts the following request components:

  • HTTP method (e.g., GET, POST)
  • URL
  • Headers
  • Body

Example input

curl -X POST "https://my.example.com/create" \
  -H "Authorization: Bearer 123" \
  -H "Content-Type: application/json" \
  -d '{"name": "New Item", "description": "It is a new item."}'

Example output

method: POST
url: https://my.example.com/create
headers:
  Authorization: Bearer 123
  Content-Type: application/json
body:
{"name": "New Item", "description": "It is a new item."}

Grammar

//A single space or tab character.
whitespace = _{ " " | "\t" }

// A backslash followed by optional whitespace and one or more newlines.
slash = _{ "\\" ~ whitespace* ~ NEWLINE+ }

// “whitespace super-set”: any mix of spaces, tabs, newlines, or slashes.
wss = _{ (whitespace | NEWLINE | slash)* }

// Text in single quotes.
single_quoted = _{ "'"  ~ (!"'"  ~ ANY)* ~ "'" }

// Text in double quotes.
double_quoted = _{ "\"" ~ ( "\\\"" | !"\"" ~ ANY )* ~ "\"" }

// Either single or double quoted text.
quoted = _{ double_quoted | single_quoted }

// Unquoted token without spaces.
bare_word = @{ (!(whitespace | NEWLINE) ~ ANY)+ }

// Quoted or unquoted value.
value = { quoted | bare_word }

// Non-whitespace characters.
none_ws = { (!whitespace ~ ANY)+ }

// Raw http or https URL.
url_plain = @{ "http" ~ "s"? ~ "://" ~ none_ws }

// Quoted or raw URL.
url = { single_quoted | double_quoted | url_plain }

// HTTP method flag (-X, --request).
method_flag = { ( "-X" | "--request" ) ~ whitespace+ ~ value }

// Header flag (-H, --header).
header_flag = { ( "-H" | "--header"  ) ~ whitespace+ ~ value }

// Data flag (-d, --data).
data_flag = { ( "-d" | "--data" ) ~ whitespace+ ~ value }

// Any supported flag.
option = _{ method_flag | header_flag | data_flag }

// Full curl command.
curl = { SOI
  ~ ( "#" ~ (!NEWLINE ~ ANY)* ~ NEWLINE )*
  ~ wss ~ "curl" ~ wss
  ~ (option ~ wss)* ~ url? ~ (wss ~ option ~ wss)*
  ~ wss ~ EOI
}

Crates.io

The parser is available as a Rust crate: curl-parser-ruben4ick

Commit count: 0

cargo fmt