-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdfview.flex
More file actions
87 lines (74 loc) · 2.53 KB
/
pdfview.flex
File metadata and controls
87 lines (74 loc) · 2.53 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java_cup.runtime.*;
%%
%class PdfView
%unicode
%cup
%line
%column
%{
private Symbol symbol(int type) {
return new Symbol(type, yyline, yycolumn);
}
private Symbol symbol(int type, Object value) {
return new Symbol(type, yyline, yycolumn, value);
}
private StringBuilder contentBuffer = new StringBuilder();
private int braceDepth = 0;
%}
LineTerminator = \r|\n|\r\n
SingleLineComment = --.+
COMMENT = {SingleLineComment}
WHITESPACE = {LineTerminator} | [ \t\f]
LANG = [\w]+
%state BRACE_CONTENT
%%
<YYINITIAL> {
"TL" { return symbol(sym.TL); }
"P" { return symbol(sym.P); }
"AU" { return symbol(sym.AU); }
"AUI" { return symbol(sym.AUI); }
"DATE" { return symbol(sym.DATE); }
"NH" { return symbol(sym.NH); }
"NH 1" { return symbol(sym.NH_1); }
"NH 2" { return symbol(sym.NH_2); }
"H" { return symbol(sym.H); }
"AB" { return symbol(sym.AB); }
"IP" { return symbol(sym.IP); }
"BP" { return symbol(sym.BP); }
"BP 4" { return symbol(sym.BP_4); }
"CB " {LANG} { return symbol(sym.CB, yytext().substring(3)); } // Only return the language
"{" {
contentBuffer.setLength(0);
braceDepth = 1;
yybegin(BRACE_CONTENT);
}
{WHITESPACE} { /* Ignore */ }
{COMMENT} { /* Ignore */ }
// Fallback
. {
System.err.println("Invalid character at line " + yyline + " column " + yycolumn + ": '" + yytext() + "'");
}
}
<BRACE_CONTENT> {
"{" {
braceDepth++;
contentBuffer.append(yytext());
}
"}" {
braceDepth--;
if (braceDepth == 0) {
// Found matching closing brace
String content = contentBuffer.toString().trim();
// System.out.println(content);
yybegin(YYINITIAL);
return symbol(sym.CONTENT, content);
} else {
contentBuffer.append(yytext());
}
}
[^{}]+ {
// String matched = yytext();
// System.err.println("Captured: '" + matched + "'");
contentBuffer.append(yytext());
}
}