16
16
LangComment = namedtuple ('LangComment' , ['content' ])
17
17
18
18
19
+ BLANK_LINE = 'blank_line'
19
20
TAG_REGEX = re .compile (r'\{(ok|l10n-extra)\}' )
20
21
21
22
@@ -54,8 +55,8 @@ def save(self, path=None):
54
55
self .write_entity (f , child )
55
56
elif isinstance (child , LangComment ):
56
57
self .write_comment (f , child )
57
-
58
- f .write (u'\n \n ' )
58
+ elif child == BLANK_LINE :
59
+ f .write (u'\n ' )
59
60
60
61
def write_entity (self , f , entity ):
61
62
for comment in entity .comments :
@@ -88,17 +89,18 @@ def write_comment(self, f, comment):
88
89
89
90
90
91
class LangVisitor (NodeVisitor ):
91
- grammar = Grammar ("""
92
- lang_file = (comment / entity)*
92
+ grammar = Grammar (r """
93
+ lang_file = (comment / entity / blank_line )*
93
94
94
- comment = "##" line_content line_end
95
+ comment = "##" line_content "\n"
95
96
line_content = ~r".*"
96
- line_end = ("\\ n" / ~r"\s")+
97
+
98
+ blank_line = ~r"((?!\n)\s)*" "\n"
97
99
98
100
entity = entity_comment* string translation
99
- entity_comment = "#" line_content line_end
100
- string = ";" line_content line_end
101
- translation = line_content line_end
101
+ entity_comment = "#" line_content "\n"
102
+ string = ";" line_content "\n"
103
+ translation = line_content "\n"
102
104
""" )
103
105
104
106
def visit_lang_file (self , node , children ):
@@ -107,6 +109,9 @@ def visit_lang_file(self, node, children):
107
109
def visit_comment (self , node , (marker , content , end )):
108
110
return LangComment (content .text .strip ())
109
111
112
+ def visit_blank_line (self , node , (whitespace , newline )):
113
+ return BLANK_LINE
114
+
110
115
def visit_entity (self , node , (comments , string , translation )):
111
116
comments = self .normalize_zero_or_more_strings (comments )
112
117
0 commit comments