1
2
3
4
5
6 #include <sng2html/sng2html/LexerContext.hpp>
7 #include <sng2html/sng2html/LexerFile.hpp>
8 #include <sng2html/sng2html/Identifier.hpp>
9 #include <soulng/util/Unicode.hpp>
10 #include <soulng/util/Path.hpp>
11 #include <algorithm>
12 #include <string>
13 #include <iostream>
14 #include <fstream>
15
16 namespace sng2html { namespace sng2html {
17
18 using namespace soulng::unicode;
19 using namespace soulng::util;
20
21 LexerContext::LexerContext(IdentifierClassKind identifierClassKind) : any(), epsilon('\0'), idStart(new Class(0)), idCont(new Class(0))
22 {
23 if (identifierClassKind == IdentifierClassKind::unicode)
24 {
25 MakeUnicodeIdentifierClasses(*this);
26 symbols.push_back(idStart);
27 symbols.push_back(idCont);
28 }
29 else if (identifierClassKind == IdentifierClassKind::ascii)
30 {
31 MakeAsciiIdentifierClasses(*this);
32 symbols.push_back(idStart);
33 symbols.push_back(idCont);
34 }
35 }
36
37 LexerContext::~LexerContext()
38 {
39 for (Symbol* symbol : symbols)
40 {
41 delete symbol;
42 }
43 }
44
45 Symbol* LexerContext::MakeChar(char32_t c)
46 {
47 auto it = charSymbols.find(c);
48 if (it != charSymbols.cend())
49 {
50 return it->second;
51 }
52 Symbol* symbol = new Char(c);
53 symbols.push_back(symbol);
54 charSymbols[c] = symbol;
55 return symbol;
56 }
57
58 Symbol* LexerContext::MakeRange(char32_t start, char32_t end)
59 {
60 Range range(start, end);
61 auto it = rangeSymbols.find(range);
62 if (it != rangeSymbols.cend())
63 {
64 return it->second;
65 }
66 Symbol* symbol = new Range(start, end);
67 symbols.push_back(symbol);
68 rangeSymbols[range] = symbol;
69 return symbol;
70 }
71
72 Class* LexerContext::MakeClass()
73 {
74 Class* cls = new Class(0);
75 symbols.push_back(cls);
76 return cls;
77 }
78
79 } }