difftreelog
refactor move string unescaping to lexer
in: master
7 files changed
crates/jrsonnet-ir-parser/src/lib.rsdiffbeforeafterboth3 ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec, Destruct, Expr,3 ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec, Destruct, Expr,4 ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IdentityKind, IfElse,4 ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IdentityKind, IfElse,5 IfSpecData, ImportKind, IndexPart, Member, NumValue, ObjBody, ObjComp, ObjMembers, Slice,5 IfSpecData, ImportKind, IndexPart, Member, NumValue, ObjBody, ObjComp, ObjMembers, Slice,6 SliceDesc, Source, Span, Spanned, TrivialVal, UnaryOpType, Visibility, unescape,6 SliceDesc, Source, Span, Spanned, TrivialVal, UnaryOpType, Visibility,7};7};8use jrsonnet_lexer::{Lexeme, Lexer, Span as LexSpan, SyntaxKind, T, collect_lexed_str_block};8use jrsonnet_lexer::{9 Lexeme, Lexer, Span as LexSpan, SyntaxKind, T, collect_lexed_str_block, unescape,10};91110pub struct ParserSettings {12pub struct ParserSettings {11 pub source: Source,13 pub source: Source,174 let s = match kind {176 let s = match kind {175 SyntaxKind::STRING_DOUBLE => {177 SyntaxKind::STRING_DOUBLE => {176 let inner = &text[1..text.len() - 1];178 let inner = &text[1..text.len() - 1];177 unescape::unescape(inner).ok_or_else(|| p.error("invalid string escape".into()))?179 unescape(inner).ok_or_else(|| p.error("invalid string escape".into()))?178 }180 }179 SyntaxKind::STRING_SINGLE => {181 SyntaxKind::STRING_SINGLE => {180 let inner = &text[1..text.len() - 1];182 let inner = &text[1..text.len() - 1];181 unescape::unescape(inner).ok_or_else(|| p.error("invalid string escape".into()))?183 unescape(inner).ok_or_else(|| p.error("invalid string escape".into()))?182 }184 }183 SyntaxKind::STRING_DOUBLE_VERBATIM => {185 SyntaxKind::STRING_DOUBLE_VERBATIM => {184 let inner = &text[2..text.len() - 1];186 let inner = &text[2..text.len() - 1];crates/jrsonnet-ir/src/lib.rsdiffbeforeafterboth9pub mod function;9pub mod function;10mod location;10mod location;11mod source;11mod source;12pub mod unescape;13pub mod visit;12pub mod visit;141315pub use location::CodeLocation;14pub use location::CodeLocation;crates/jrsonnet-ir/src/unescape.rsdiffbeforeafterbothno changes
crates/jrsonnet-lexer/src/lib.rsdiffbeforeafterboth1mod generated;1mod generated;2mod lex;2mod lex;3pub mod string;3mod string_block;4pub mod string_block;455#[derive(Clone, Copy, Debug)]6#[derive(Clone, Copy, Debug)]6pub struct Span(pub u32, pub u32);7pub struct Span(pub u32, pub u32);788pub use generated::syntax_kinds::SyntaxKind;9pub use generated::syntax_kinds::SyntaxKind;9pub use lex::{Lexeme, Lexer, lex};10pub use lex::{Lexeme, Lexer, lex};11pub use string::unescape;10pub use string_block::{CollectStrBlock, collect_lexed_str_block};12pub use string_block::{CollectStrBlock, collect_lexed_str_block};1113crates/jrsonnet-lexer/src/string.rsdiffbeforeafterbothno changes
crates/jrsonnet-peg-parser/Cargo.tomldiffbeforeafterboth12[dependencies]12[dependencies]13jrsonnet-gcmodule.workspace = true13jrsonnet-gcmodule.workspace = true14jrsonnet-ir.workspace = true14jrsonnet-ir.workspace = true15jrsonnet-lexer.workspace = true15peg.workspace = true16peg.workspace = true161717[lints]18[lints]crates/jrsonnet-peg-parser/src/lib.rsdiffbeforeafterboth3 ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BindSpec, CompSpec, Destruct, DestructRest, Expr,3 ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BindSpec, CompSpec, Destruct, DestructRest, Expr,4 ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IdentityKind, IfElse,4 ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IdentityKind, IfElse,5 IfSpecData, ImportKind, IndexPart, Member, NumValue, ObjBody, ObjComp, ObjMembers, Slice,5 IfSpecData, ImportKind, IndexPart, Member, NumValue, ObjBody, ObjComp, ObjMembers, Slice,6 SliceDesc, Source, Span, Spanned, TrivialVal, Visibility, unescape,6 SliceDesc, Source, Span, Spanned, TrivialVal, Visibility,7};7};8use jrsonnet_lexer::unescape;8use peg::parser;9use peg::parser;91010pub struct ParserSettings {11pub struct ParserSettings {165 / "\\x" hex_char() hex_char()166 / "\\x" hex_char() hex_char()166 / ['\\'] (quiet! { ['b' | 'f' | 'n' | 'r' | 't' | '"' | '\''] } / expected!("<escape character>"))167 / ['\\'] (quiet! { ['b' | 'f' | 'n' | 'r' | 't' | '"' | '\''] } / expected!("<escape character>"))167 pub rule string() -> String168 pub rule string() -> String168 = ['"'] str:$(string_char(<"\"">)*) ['"'] {? unescape::unescape(str).ok_or("<escaped string>")}169 = ['"'] str:$(string_char(<"\"">)*) ['"'] {? unescape(str).ok_or("<escaped string>")}169 / ['\''] str:$(string_char(<"\'">)*) ['\''] {? unescape::unescape(str).ok_or("<escaped string>")}170 / ['\''] str:$(string_char(<"\'">)*) ['\''] {? unescape(str).ok_or("<escaped string>")}170 / quiet!{ "@'" str:$(("''" / (!['\''][_]))*) "'" {str.replace("''", "'")}171 / quiet!{ "@'" str:$(("''" / (!['\''][_]))*) "'" {str.replace("''", "'")}171 / "@\"" str:$(("\"\"" / (!['"'][_]))*) "\"" {str.replace("\"\"", "\"")}172 / "@\"" str:$(("\"\"" / (!['"'][_]))*) "\"" {str.replace("\"\"", "\"")}172 / string_block() } / expected!("<string>")173 / string_block() } / expected!("<string>")