-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpatch_parser.py
More file actions
30 lines (24 loc) · 1021 Bytes
/
Copy pathpatch_parser.py
File metadata and controls
30 lines (24 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import re
with open('src/parser.rs', 'r') as f:
content = f.read()
# Replace return type of parse_params
content = content.replace(
'fn parse_params(&mut self) -> NuResult<Vec<(String, Option<Type>)>>',
'fn parse_params(&mut self) -> NuResult<Vec<crate::ast::Param>>'
)
# In parse_params, parse capability
content = content.replace(
'let name = self.expect_ident("parameter name")?;',
'let cap = self.try_parse_capability();\n let name = self.expect_ident("parameter name")?;'
)
content = content.replace(
'params.push((name, ty));',
'params.push(crate::ast::Param { name, ty, cap });'
)
# Replace return type of parse_params_with_defaults
content = content.replace(
'fn parse_params_with_defaults(\n &mut self,\n ) -> NuResult<(Vec<(String, Option<Type>)>, Vec<Option<Expr>>)>',
'fn parse_params_with_defaults(\n &mut self,\n ) -> NuResult<(Vec<crate::ast::Param>, Vec<Option<Expr>>)>'
)
with open('src/parser.rs', 'w') as f:
f.write(content)