epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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.com | 289e4fc | 2009-08-31 18:04:51 +0000 | [diff] [blame] | 8 | #ifndef ForthParser_DEFINED |
| 9 | #define ForthParser_DEFINED |
| 10 | |
| 11 | #include "SkTDict.h" |
reed@android.com | de2e7fb | 2009-09-02 02:07:32 +0000 | [diff] [blame] | 12 | //#include "SkString.h" |
reed@android.com | 289e4fc | 2009-08-31 18:04:51 +0000 | [diff] [blame] | 13 | |
| 14 | class ForthWord; |
| 15 | class FCode; |
| 16 | |
| 17 | class ForthParser { |
| 18 | public: |
| 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.com | de2e7fb | 2009-09-02 02:07:32 +0000 | [diff] [blame] | 29 | // SkString str(name, len); |
| 30 | // SkDebugf("add %s %p\n", str.c_str(), word); |
reed@google.com | 1d5aaa8 | 2011-05-31 15:35:54 +0000 | [diff] [blame] | 31 | SkDEBUGCODE(bool isNewWord = )fDict.set(name, len, word); |
| 32 | SkASSERT(isNewWord); |
reed@android.com | 289e4fc | 2009-08-31 18:04:51 +0000 | [diff] [blame] | 33 | } |
| 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 | |
| 40 | private: |
| 41 | void addStdWords(); |
| 42 | |
| 43 | SkTDict<ForthWord*> fDict; |
| 44 | }; |
| 45 | |
| 46 | #endif |