-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNMDocumentAssembler.m
38 lines (29 loc) · 942 Bytes
/
NMDocumentAssembler.m
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
31
32
33
34
35
36
37
38
#import "NMDocumentAssembler.h"
#import <ParseKit/ParseKit.h>
#import "NMDocument.h"
#import "NMParagraph.h"
@implementation NMDocumentAssembler
- (NMDocument *)currentFrom:(PKAssembly *)assembly {
if (!assembly.target) {
assembly.target = [NMDocument document];
}
return (NMDocument *)assembly.target;
}
- (void)didMatchText:(PKAssembly *)assembly {
NMDocument *doc = [self currentFrom:assembly];
[doc addText:[[assembly pop] stringValue]];
}
- (void)didMatchLiteralText:(PKAssembly *)assembly {
NMDocument *doc = [self currentFrom:assembly];
[doc addText:[[[assembly pop] stringValue] stripPrefixBackslash]];
}
- (void)didMatchEmphasizedTag:(PKAssembly *)assembly {
[[self currentFrom:assembly] startOrCloseEmphasizedText];
}
- (void)didMatchParaSeparator:(PKAssembly *)assembly {
[[self currentFrom:assembly] startNewParagraph];
}
- (void)didMatchDocument:(PKAssembly *)assembly {
[self currentFrom:assembly];
}
@end