1 using System;
2 using System.Collections;
3
4 namespace soulcm.scm2html
5 {
6 public class Rule
7 {
8 public Rule(const ustring& name_, Expression* expression_) :
9 kind(Kind.lexical), name(name_), expression(expression_), parser(null)
10 {
11 }
12 public Rule(const ustring& name_, RuleParser* parser_) :
13 kind(Kind.parser), name(name_), parser(parser_), expression(null)
14 {
15 }
16 public enum Kind
17 {
18 lexical, parser
19 }
20 public const ustring& Name() const
21 {
22 return name;
23 }
24 public Expression* GetExpression() const
25 {
26 return expression;
27 }
28 public RuleParser* Parser() const
29 {
30 return parser;
31 }
32 private Kind kind;
33 private ustring name;
34 private Expression* expression;
35 private RuleParser* parser;
36 }
37
38 public class Grammar
39 {
40 public Grammar(const ustring& name_, const ustring& title_, const string& htmlFilePath_, LexerFile* lexerFile_) :
41 kind(Kind.lexical), name(name_), title(title_), htmlFilePath(htmlFilePath_), lexerFile(lexerFile_), parser(null), htmlFileName(name + u".html")
42 {
43 }
44 public Grammar(const ustring& name_, const ustring& title_, const string& htmlFilePath_, GrammarParser* parser_) :
45 kind(Kind.parser), name(name_), title(title_), htmlFilePath(htmlFilePath_), parser(parser_), lexerFile(null), htmlFileName(name + u".html")
46 {
47 }
48 public enum Kind
49 {
50 lexical, parser
51 }
52 public Kind GetKind() const
53 {
54 return kind;
55 }
56 public const ustring& Name() const
57 {
58 return name;
59 }
60 public const ustring& Title() const
61 {
62 return title;
63 }
64 public const string& HtmlFilePath() const
65 {
66 return htmlFilePath;
67 }
68 public GrammarParser* Parser() const
69 {
70 return parser;
71 }
72 public const ustring& HtmlFileName() const
73 {
74 return htmlFileName;
75 }
76 public const List<UniquePtr<Rule>>& Rules() const
77 {
78 return rules;
79 }
80 public void AddRule(Rule* rule)
81 {
82 rules.Add(UniquePtr<Rule>(rule));
83 }
84 private Kind kind;
85 private ustring name;
86 private ustring title;
87 private string htmlFilePath;
88 private LexerFile* lexerFile;
89 private GrammarParser* parser;
90 private ustring htmlFileName;
91 private string htmfFilePath;
92 private List<UniquePtr<Rule>> rules;
93 }
94 }