blob: 2138d4809fccd584709438b9826986ae3a026433 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.com289e4fc2009-08-31 18:04:51 +00008#ifndef ForthParser_DEFINED
9#define ForthParser_DEFINED
10
11#include "SkTDict.h"
reed@android.comde2e7fb2009-09-02 02:07:32 +000012//#include "SkString.h"
reed@android.com289e4fc2009-08-31 18:04:51 +000013
14class ForthWord;
15class FCode;
16
17class ForthParser {
18public:
19 ForthParser();
20 ~ForthParser();
21
22 const char* parse(const char text[], FCode*);
23
24 void addWord(const char name[], ForthWord* word) {
25 this->add(name, strlen(name), word);
26 }
27
28 void add(const char name[], size_t len, ForthWord* word) {
reed@android.comde2e7fb2009-09-02 02:07:32 +000029 // SkString str(name, len);
30 // SkDebugf("add %s %p\n", str.c_str(), word);
reed@google.com1d5aaa82011-05-31 15:35:54 +000031 SkDEBUGCODE(bool isNewWord = )fDict.set(name, len, word);
32 SkASSERT(isNewWord);
reed@android.com289e4fc2009-08-31 18:04:51 +000033 }
34
35 ForthWord* find(const char name[], size_t len) const {
36 ForthWord* word;
37 return fDict.find(name, len, &word) ? word : NULL;
38 }
39
40private:
41 void addStdWords();
42
43 SkTDict<ForthWord*> fDict;
44};
45
46#endif