Skip to content

Commit

Permalink
Add row/col
Browse files Browse the repository at this point in the history
  • Loading branch information
beanflame committed May 26, 2024
1 parent 1c46da0 commit 275a4c7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 13 deletions.
53 changes: 40 additions & 13 deletions otne/src/otne_lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "otne_lexer.hpp"
using namespace std;


/*
bool isRussian(i18nChar ch) {
if ((ch >= L'а' && ch <= L'я') || (ch >= L'А' && ch <= L'Я')) { return true; }
Expand All @@ -27,6 +28,7 @@ bool isDigit(i18nChar ch) {
else { return false; }
}


bool isAlpha(i18nChar ch) {
if ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z')) { return true; }
else { return false; }
Expand All @@ -37,9 +39,10 @@ template<class T>
int getLength(T& arr) { return sizeof(arr) / sizeof(arr[0]); }

i18nString KeyWord[] = {
L"plug", L"module",
L"module",
L"static",
L"fn", L"num", L"text", L"string",
L"class",
L"func", L"int", L"string",
L"return",
L"bool", L"true", L"false", L"null",
L"if", L"elif", L"else", L"for", L"while", L"break"
Expand All @@ -59,13 +62,9 @@ int isKeyWord(i18nString token) {










// row表示行,col表示列
int row = 1;
int col = 1;



Expand All @@ -79,10 +78,33 @@ void lexer(i18nString Text) {
i18nChar ch;

while (stlPos < Text.length()) {


ch = Text[stlPos];


if (isText(ch)) {
while (isText(ch)) {
if(ch == L'\n')
{
row++;
col = 1;
stlPos++;
}









/*
if (isAlpha(ch)) {
while (isAlpha(ch)) {
token += ch;
stlPos++;
ch = Text[stlPos];
Expand Down Expand Up @@ -128,8 +150,8 @@ void lexer(i18nString Text) {
}
else if (isNum(ch)) {
while (isNum(ch) || (ch == L'.')) {
else if (isDigit(ch)) {
while (isDigit(ch) || (ch == L'.')) {
token += ch;
stlPos++;
ch = Text[stlPos];
Expand All @@ -151,13 +173,18 @@ void lexer(i18nString Text) {
stlPos++;
}
*/




else {
// wcout << ch;
stlPos++;
col++;
}

wcout << "\""<< ch << "\"" << L" row: " << row << L" col: " << col << endl;
}
}

Expand Down
12 changes: 12 additions & 0 deletions otne/src/otne_lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@
#include "otne_utf8.hpp"
void lexer(i18nString Text);

class lexer
{
public:
lexer();
~lexer();

public:


};


#endif

0 comments on commit 275a4c7

Please sign in to comment.