amath  1.8.5
Simple command line calculator
language.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2014-2018 Carsten Sonne Larsen <cs@innolan.net>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * Project homepage:
26  * https://amath.innolan.net
27  *
28  */
29 
30 #ifndef AMATH_LANGUAGE_BASE_H
31 #define AMATH_LANGUAGE_BASE_H
32 
33 #include "lib/charval.h"
34 #include "main/symbol.h"
35 #include "loc/help.h"
36 #include "loc/text.h"
37 #include "loc/ident.h"
38 #include "loc/kword.h"
39 
40 class Language : public CharValidator
41 {
42 public:
43  Language();
44  virtual ~Language();
45  char* GetText(int id);
46  char* GetHelpText(char* ident);
47  char* GetHelpText(Symbol symbol);
48  Symbol FindKeyword(const char* ident) const;
49  virtual char GetFractionPoint() = 0;
50  virtual bool CharIsAlNum(unsigned long character) = 0;
51  virtual bool CharIsAlpha(unsigned long character) = 0;
52  virtual bool CharIsDigit(unsigned long character) = 0;
53  virtual bool CharIsPunct(unsigned long character) = 0;
54  virtual bool CharIsSpace(unsigned long character) = 0;
55  virtual bool CharIsCntrl(unsigned long character) = 0;
56  virtual bool CharIsQuote(unsigned long character);
57  virtual bool CharIsBlank(unsigned long character);
58  virtual bool CharIsNewLine(unsigned long character);
59  virtual bool CharIsOperator(unsigned long character);
60  virtual bool StrIsEqualLoc(const char* s1, const char* s2) = 0;
61  virtual bool Validate(char c) = 0;
62  void SetAnsiMode(bool value);
63 
64 protected:
65  virtual char* Translate(textdef* def) = 0;
66  virtual char* Translate(helptextdef* def) = 0;
67  virtual char* Translate(identhelpdef* def) = 0;
68 
70  unsigned int keywordcount;
71  unsigned int textcount;
72  unsigned int identcount;
73  unsigned int helpcount;
74  unsigned int aliascount;
75 
76 private:
77  char* FindAlias(const char* ident) const;
78  char* UntagText(const char* text);
79  char* lastText;
80  bool ansiMode;
81 };
82 
83 #endif
virtual bool CharIsSpace(unsigned long character)=0
char * UntagText(const char *text)
Definition: language.cpp:199
virtual char * Translate(identhelpdef *def)=0
virtual char * Translate(helptextdef *def)=0
virtual bool CharIsBlank(unsigned long character)
Definition: language.cpp:232
virtual bool CharIsAlNum(unsigned long character)=0
Symbol FindKeyword(const char *ident) const
Definition: language.cpp:118
virtual bool CharIsAlpha(unsigned long character)=0
virtual bool CharIsPunct(unsigned long character)=0
virtual bool Validate(char c)=0
virtual char GetFractionPoint()=0
char * FindAlias(const char *ident) const
Definition: language.cpp:105
Character representation of keyword tied with its symbol.
Definition: kword.h:48
char * GetHelpText(Symbol symbol)
Definition: language.cpp:177
char * GetText(int id)
Definition: language.cpp:132
virtual bool StrIsEqualLoc(const char *s1, const char *s2)=0
unsigned int helpcount
Definition: language.h:73
virtual bool CharIsQuote(unsigned long character)
Definition: language.cpp:227
Definition: amatht.h:33
unsigned int identcount
Definition: language.h:72
unsigned int textcount
Definition: language.h:71
virtual ~Language()
Definition: language.cpp:87
Language()
Definition: language.cpp:76
char * lastText
Definition: language.h:79
keyworddef * keywordsloc
Definition: language.h:69
unsigned int aliascount
Definition: language.h:74
void SetAnsiMode(bool value)
Definition: language.cpp:100
virtual bool CharIsNewLine(unsigned long character)
Definition: language.cpp:244
virtual bool CharIsDigit(unsigned long character)=0
virtual bool CharIsCntrl(unsigned long character)=0
unsigned int keywordcount
Definition: language.h:70
char * GetHelpText(char *ident)
Definition: language.cpp:154
virtual char * Translate(textdef *def)=0
virtual bool CharIsOperator(unsigned long character)
Definition: language.cpp:253
bool ansiMode
Definition: language.h:80