Initial commit
[profile/ivi/openjade.git] / style / SchemeParser.h
1 // Copyright (c) 1996 James Clark
2 // See the file copying.txt for copying permission.
3
4 #ifndef SchemeParser_INCLUDED
5 #define SchemeParser_INCLUDED 1
6
7 #include "Interpreter.h"
8 #include "Expression.h"
9 #include "Owner.h"
10
11 #ifdef DSSSL_NAMESPACE
12 namespace DSSSL_NAMESPACE {
13 #endif
14
15 class LangObj;
16
17 class SchemeParser : public Messenger {
18 public:
19   SchemeParser(Interpreter &, Owner<InputSource> &);
20   void parse();
21   void parseStandardChars();
22   void parseMapSdataEntity(const StringC &name, const StringC &text);
23   void parseNameChars();
24   void parseSeparatorChars();
25   bool parseExpression(Owner<Expression> &);
26 private:
27   SchemeParser(const SchemeParser &); // undefined
28   void operator=(const SchemeParser &); // undefined
29
30   enum {
31     allowEndOfEntity = 01,
32     allowFalse = 02,
33     allowKeyword = 04,
34     allowOpenParen = 010,
35     allowCloseParen = 020,
36     allowIdentifier = 040,
37     allowPeriod = 0100,
38     allowOtherExpr = 0200,  // number, character, glyph-id, quote, backquote
39     allowExpressionKey = 0400,
40     allowKeyDefine = 01000,
41     allowKeyElse = 02000,
42     allowKeyArrow = 04000, // =>
43     allowString = 010000,
44     allowHashOptional = 020000,
45     allowHashKey = 040000,
46     allowHashRest = 0100000,
47     allowUnquote = 0200000,
48     allowUnquoteSplicing = 0400000,
49     allowQuasiquoteKey = 01000000,
50     allowVector = 02000000,
51     allowHashContents = 04000000,
52     allowExpr = (allowFalse|allowKeyword|allowOpenParen|allowIdentifier
53                   |allowString|allowHashOptional|allowHashKey|allowHashRest
54                   |allowOtherExpr)
55   };
56   enum Token {
57     tokenEndOfEntity,
58     tokenTrue,
59     tokenFalse,
60     tokenString,
61     tokenIdentifier,
62     tokenKeyword,
63     tokenChar,
64     tokenNumber,
65     tokenGlyphId,
66     tokenOpenParen,
67     tokenCloseParen,
68     tokenPeriod,
69     tokenVector,
70     tokenQuote,
71     tokenQuasiquote,
72     tokenUnquote,
73     tokenUnquoteSplicing,
74     tokenHashRest,
75     tokenHashOptional,
76     tokenHashKey,
77     tokenHashContents,
78     tokenVoid
79   };
80   bool doDefine();
81   bool doDefineUnit();
82   bool doElement();
83   bool doOrElement();
84   bool doDefault();
85   bool doId();
86   bool doRoot();
87   bool doMode();
88   bool doDeclareInitialValue();
89   bool doDeclareCharacteristic();
90   bool doDeclareCharCharacteristicAndProperty();
91   bool doDeclareFlowObjectClass();
92   bool doDeclareClassAttribute();
93   bool doDeclareIdAttribute();
94   bool doDeclareFlowObjectMacro();
95   bool doDeclareDefaultLanguage();
96   bool doDefineLanguage();
97   bool doCollate();
98   bool doMultiCollatingElement();
99   bool doCollatingSymbol();
100   bool doCollatingOrder();
101   bool doWeights();
102   bool doToupper();
103   bool doTolower();
104   bool doDeclareCharProperty();
105   bool doAddCharProperties();
106   bool skipForm();
107   bool parseSpecialQuery(Owner<Expression> &expr, const char *query);
108   bool parseExpression(unsigned allowed, Owner<Expression> &,
109                        Identifier::SyntacticKey &, Token &);
110   bool parseBegin(Owner<Expression> &expr);
111   bool parseSet(Owner<Expression> &expr);
112   bool parseLambda(Owner<Expression> &);
113   bool parseLet(Owner<Expression> &);
114   bool parseLetStar(Owner<Expression> &);
115   bool parseLetrec(Owner<Expression> &);
116   bool parseBindingsAndBody(Vector<const Identifier *> &vars,
117                             NCVector<Owner<Expression> > &inits,
118                             Owner<Expression> &body);
119   bool parseBindingsAndBody1(Vector<const Identifier *> &vars,
120                              NCVector<Owner<Expression> > &inits,
121                              Owner<Expression> &body);
122   bool parseQuote(Owner<Expression> &);
123   bool parseIf(Owner<Expression> &);
124   bool parseCond(Owner<Expression> &, bool opt = 0);
125   bool parseCase(Owner<Expression> &);
126   bool parseOr(Owner<Expression> &);
127   bool parseAnd(Owner<Expression> &, bool opt = 0);
128   bool parseMake(Owner<Expression> &);
129   bool parseStyle(Owner<Expression> &);
130   bool parseWithMode(Owner<Expression> &);
131   bool parseFormals(Vector<const Identifier *> &,
132                     NCVector<Owner<Expression> > &,
133                     int &, bool &, int &);
134   bool parseDatum(unsigned otherAllowed, ELObj *&, Location &, Token &);
135   bool parseSelfEvaluating(unsigned otherAllowed, ELObj *&, Token &);
136   bool parseAbbreviation(const char *, ELObj *&);
137   bool parseQuasiquote(Owner<Expression> &);
138   bool parseQuasiquoteTemplate(unsigned level,
139                                unsigned allowed,
140                                Owner<Expression> &,
141                                Identifier::SyntacticKey &,
142                                Token &,
143                                bool &spliced);
144   void createQuasiquoteAbbreviation(const char *, Owner<Expression> &);
145   bool parseRuleBody(Owner<Expression> &, ProcessingMode::RuleType &);
146   bool getToken(unsigned, Token &);
147   bool handleNumber(unsigned, Token &);
148   bool handleIdentifier(unsigned, Token &);
149   void extendToken();
150   bool scanString();
151   void skipComment();
152   bool tokenRecover(unsigned, Token &);
153   bool scanString(unsigned, Token &);
154   ELObj *convertAfiiGlyphId(const StringC &);
155   Identifier *lookup(const StringC &str);
156   ProcessingMode *lookupProcessingMode(const StringC &);
157   void dispatchMessage(Message &);
158   void dispatchMessage(const Message &);
159   void initMessage(Message &msg);
160   bool dsssl2() const;
161   
162   Interpreter *interp_;
163   Owner<InputSource> in_;
164   StringC currentToken_;
165   ProcessingMode *defMode_;
166   const char *afiiPublicId_;
167   bool dsssl2_;
168   LangObj *lang_;
169 };
170
171 inline
172 Identifier *SchemeParser::lookup(const StringC &str)
173 {
174   return interp_->lookup(str);
175 }
176
177 inline
178 ProcessingMode *SchemeParser::lookupProcessingMode(const StringC &name)
179 {
180   return interp_->lookupProcessingMode(name);
181 }
182
183 inline
184 bool SchemeParser::dsssl2() const
185 {
186   return dsssl2_;
187 }
188
189 #ifdef DSSSL_NAMESPACE
190 }
191 #endif
192
193 #endif /* not SchemeParser_INCLUDED */