pest-parser / site

This repo contains the source code for https://pest.rs
http://pest.rs/
Apache License 2.0
13 stars 16 forks source link

Pest format bug #58

Open kerstop opened 6 months ago

kerstop commented 6 months ago

Describe the bug using the editor on pest.rs I found a bug in the formater that creates an invalid schema

To Reproduce Here is the link to the editor, clicking on format moves the closing } on the number rule into a comment.

https://pest.rs/?g=N4Ig5gTghgtjURALhAdQBIEkAqBRAygAoCCAwrgAQC8FA%2BsBQBQA6IFrFAPuyM8wC4duAOVyoAMplEBKCgF9mAOyUA3KABsArgFMKe-dQoNGAewBGAK20BjflwoJoAT3sBnfhACWisPY877ADMNV11uRU11dVkFRXMrWwM9GgZWYA4APyZ4m35aAAcoTwgKLJYQABpMihzbAqKIaQAqaQB%2BUp4FNljavMLiwwZ3Lx8O1iRqtS1dWMcoFyTBngBtSY0AstYqtiypnWaxkABdDliImDNtEqSUpQNWAFpWdqyKAHo3ildPMGVFPXKAAYhBQAOQARlBADooaCAJygjrEfCkTCYWgAEUwAHEcC0OuUodVkaj0VjcdgWi89B8KIFoLZPCY-npWLhWJxWNpquUANQgx6sNqlElozE4vHvT7aAAe%2BWZ2kUgkUsX8ukWS1YatOSmC6lCGpSPD1oR1igiUQ1mpAFvUZqUw28vit%2BhoABJUrw%2BLwdhRvIorrRHaMsqw%2BGHukp-YHg86DDQAAIMaMQIMeJ20awACwQTXkUfNMfTPkzOZKNCMd30AEJyuGffYw%2BGhUjhABNKvcJv1gndhtdr09gdvAUgMyjwKj5RsAcQUeCEDSTs8Zs81iaYkosXoXAADXFFOAABY5EuVUpKiBvPlNPxkCB0v99KwA%2B4neMjDwUzVLLkP8A5HkKon1ZEAoH%2BOYnA-ZZwShABWCoKDVRDbUQ8FtAeAA2I5gPuEBYwoAB3Tx%2BCzChtFcawoHybQABMKFokxNDMdRdAAR00Ex%2BAojgkBXb0OM8awAGsKDMCATEI-5AhMGUeO9MMVRAOQgA#editor 

Or here is the un-formated input.

WHITESPACE = _{ (" " | "\t" | NEWLINE) }

value       = { (object | array | string | true | false | null) }
object      = { "{" ~ (object_pair ~ ("," ~ object_pair)*)? ~ "}" }
object_pair = { string ~ ":" ~ value }
array       = { "[" ~ value ~ ("," ~ value)* ~ "]" }
number      = {
    "-"? ~  // sign
  ("0" | '1'..'9' ~ ASCII_DIGIT*) ~ ("." ~ ASCII_DIGIT*)? ~  // fraction
  "E"|"e" ~ ("+" | "-")? ~ASCII_DIGIT* // exponent
}
true        = { "true" }
false       = { "false" }
null        = { "null" }

string            = ${ "\"" ~ inner_string ~ "\"" }
inner_string      = @{ inner_string_char* }
inner_string_char =  {
    !("\"" | "\\") ~ ANY
  | "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
  | "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}

Expected behavior Running format should not change the semantics of the source