mirror of
https://codeberg.org/icewind/php-literal-parser.git
synced 2026-06-03 10:34:08 +02:00
allow trailing semicolon
This commit is contained in:
parent
20dad94035
commit
688f4fb6f4
4 changed files with 26 additions and 17 deletions
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "php-literal-parser"
|
||||
description = "parser for php literals"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||
edition = "2018"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ pub enum Token {
|
|||
Float,
|
||||
#[regex("-?(0|[1-9][0-9]*(_[0-9]+)*|0[xX][0-9a-fA-F]+(_[0-9a-fA-F]+)*|0[0-7]+(_[0-7]+)*|0[bB][01]+(_[01]+)*)")]
|
||||
Integer,
|
||||
#[token(";")]
|
||||
SemiColon,
|
||||
#[error]
|
||||
#[regex(r"[ \t\n\f]+", logos::skip)]
|
||||
Error,
|
||||
|
|
|
|||
|
|
@ -52,10 +52,13 @@ where
|
|||
{
|
||||
let mut deserializer = Deserializer::from_str(s);
|
||||
let t = T::deserialize(&mut deserializer)?;
|
||||
if deserializer.next_token().is_none() {
|
||||
Ok(t)
|
||||
} else {
|
||||
Err(RawParseError::TrailingCharacters.into())
|
||||
match deserializer.next_token() {
|
||||
None
|
||||
| Some(SpannedToken {
|
||||
token: Token::SemiColon,
|
||||
..
|
||||
}) => Ok(t),
|
||||
Some(_) => Err(RawParseError::TrailingCharacters.into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
use maplit::hashmap;
|
||||
use php_literal_parser::{from_str, Key, ParseError, Value};
|
||||
|
||||
#[test]
|
||||
fn test_parse_value() {
|
||||
fn parse(source: &str) -> Result<Value, ParseError> {
|
||||
fn parse(source: &str) -> Result<Value, ParseError> {
|
||||
match from_str(source) {
|
||||
Ok(res) => Ok(res),
|
||||
Err(err) => {
|
||||
|
|
@ -11,10 +10,10 @@ fn test_parse_value() {
|
|||
Err(sourced.into_inner())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
use maplit::hashmap;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_value() {
|
||||
assert_eq!(Value::Bool(true), parse("true").unwrap());
|
||||
assert_eq!(Value::Bool(false), parse("false").unwrap());
|
||||
assert_eq!(Value::Int(12), parse("12").unwrap());
|
||||
|
|
@ -132,3 +131,8 @@ fn test_parse_value() {
|
|||
parse(r#"array("2"=>3,"foo" => 4, null => 5, true => 6, false => 7)"#).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trailing_semi() {
|
||||
assert_eq!(Value::Int(12), parse(r#"12;"#).unwrap());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue