difftreelog
feat(parser) use PathBuf for file names
in: master
2 files changed
crates/jsonnet-parser/src/expr.rsdiffbeforeafterboth1use serde::{Deserialize, Serialize};1use serde::{Deserialize, Serialize};2use std::{fmt::Debug, rc::Rc};2use std::{fmt::Debug, path::PathBuf, rc::Rc};334#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]5pub enum FieldName {5pub enum FieldName {50pub enum BinaryOpType {50pub enum BinaryOpType {51 Mul,51 Mul,52 Div,52 Div,53 // Mod is desugared to std.mod5354 // Mod,55 Add,54 Add,56 Sub,55 Sub,5756656466 In,65 In,6768 // Eq/Ne is desugared to std.equals69 // Eq,70 // Ne,716672 BitAnd,67 BitAnd,73 BitOr,68 BitOr,120 key: LocExpr,115 key: LocExpr,121 value: LocExpr,116 value: LocExpr,122 post_locals: Vec<BindSpec>,117 post_locals: Vec<BindSpec>,123 first: ForSpecData,124 rest: Vec<CompSpec>,118 rest: Vec<CompSpec>,125 },119 },126}120}225219226/// file, begin offset, end offset220/// file, begin offset, end offset227#[derive(Clone, PartialEq, Serialize, Deserialize)]221#[derive(Clone, PartialEq, Serialize, Deserialize)]228pub struct ExprLocation(pub String, pub usize, pub usize);222pub struct ExprLocation(pub PathBuf, pub usize, pub usize);229impl Debug for ExprLocation {223impl Debug for ExprLocation {230 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {224 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {231 write!(f, "{}:{:?}-{:?}", self.0, self.1, self.2)225 write!(f, "{:?}:{:?}-{:?}", self.0, self.1, self.2)232 }226 }233}227}234228crates/jsonnet-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jsonnet-parser/src/lib.rs
+++ b/crates/jsonnet-parser/src/lib.rs
@@ -4,7 +4,7 @@
extern crate test;
use peg::parser;
-use std::rc::Rc;
+use std::{path::PathBuf, rc::Rc};
mod expr;
pub use expr::*;
@@ -19,7 +19,7 @@
pub struct ParserSettings {
pub loc_data: bool,
- pub file_name: String,
+ pub file_name: PathBuf,
}
parser! {
@@ -118,14 +118,13 @@
/ assertion:assertion(s) {expr::Member::AssertStmt(assertion)}
/ field:field(s) {expr::Member::Field(field)}
pub rule objinside(s: &ParserSettings) -> expr::ObjBody
- = pre_locals:(b: obj_local(s) comma() {b})* "[" _ key:expr(s) _ "]" _ ":" _ value:expr(s) post_locals:(comma() b:obj_local(s) {b})* _ first:forspec(s) rest:(_ rest:compspec(s) {rest})? {
+ = pre_locals:(b: obj_local(s) comma() {b})* "[" _ key:expr(s) _ "]" _ ":" _ value:expr(s) post_locals:(comma() b:obj_local(s) {b})* _ forspec:forspec(s) others:(_ rest:compspec(s) {rest})? {
expr::ObjBody::ObjComp {
pre_locals,
key,
value,
post_locals,
- first,
- rest: rest.unwrap_or_default(),
+ rest: [vec![CompSpec::ForSpec(forspec)], others.unwrap_or_default()].concat(),
}
}
/ members:(member(s) ** comma()) comma()? {expr::ObjBody::MemberList(members)}
@@ -301,6 +300,7 @@
pub mod tests {
use super::{expr::*, parse};
use crate::ParserSettings;
+ use std::path::PathBuf;
macro_rules! parse {
($s:expr) => {
@@ -308,7 +308,7 @@
$s,
&ParserSettings {
loc_data: false,
- file_name: "test.jsonnet".to_owned(),
+ file_name: PathBuf::from("/test.jsonnet"),
},
)
.unwrap()