All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
scanner.h
Go to the documentation of this file.
1 #ifndef uscript_scanner_h
2 #define uscript_scanner_h
3 
4 #include "vm.h"
5 #include "chunk.h"
6 
7 namespace uscript {
8 enum TokenType {
9  // Single-character tokens.
15 
16  // One or two character tokens.
21 
22  // Literals.
24 
25  // Keywords.
30 
31  // more keywords
33 
36 };
37 
38 struct Token {
40  const char *start;
41  int length;
42 };
43 
44 class Scanner {
45  const char *start;
46  const char *current;
47 public:
48  Scanner();
49  void SetSource(const char *_start);
50 
51  Token ScanToken();
53  Token ErrorToken(const char *message) const;
54  bool IsAtEnd() const;
55  char Advance();
56  bool Match(char c);
57  void SkipWhitespace();
58  Token String();
59  Token Number();
60  Token Identifier();
61  TokenType IdentifierType() const;
62 };
63 
64 
65 } // end namespace
66 #endif
Token ErrorToken(const char *message) const
Definition: scanner.cc:175
Token String()
Definition: scanner.cc:116
const char * start
Definition: scanner.h:45
void SetSource(const char *_start)
Definition: scanner.cc:11
bool IsAtEnd() const
Definition: scanner.cc:104
bool Match(char c)
Definition: scanner.cc:91
TokenType IdentifierType() const
Definition: scanner.cc:140
TokenType type
Definition: scanner.h:39
Token Identifier()
Definition: scanner.cc:169
Token MakeToken(TokenType type) const
Definition: scanner.cc:108
Token ScanToken()
Definition: scanner.cc:48
TokenType
Definition: scanner.h:8
void SkipWhitespace()
Definition: scanner.cc:16
Token Number()
Definition: scanner.cc:127
const char * start
Definition: scanner.h:40
const char * current
Definition: scanner.h:46
char Advance()
Definition: scanner.cc:99