From 33e228945100aba33dabd40a8cbe77e621ba1bd3 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Fri, 12 Jun 2009 02:45:14 +0000 Subject: New FORTH lexer from bug #2804894. --- src/LexForth.cxx | 438 +++++++++++++++++-------------------------------------- 1 file changed, 130 insertions(+), 308 deletions(-) (limited to 'src') diff --git a/src/LexForth.cxx b/src/LexForth.cxx index f097b0e00..45d8903e8 100644 --- a/src/LexForth.cxx +++ b/src/LexForth.cxx @@ -1,10 +1,8 @@ // Scintilla source code edit control -/** @file LexCrontab.cxx - ** Lexer to use with extended crontab files used by a powerful - ** Windows scheduler/event monitor/automation manager nnCron. - ** (http://nemtsev.eserv.ru/) +/** @file LexForth.cxx + ** Lexer for FORTH **/ -// Copyright 1998-2001 by Neil Hodgson +// Copyright 1998-2003 by Neil Hodgson // The License.txt file describes the conditions under which this software may be distributed. #include @@ -17,6 +15,7 @@ #include "PropSet.h" #include "Accessor.h" +#include "StyleContext.h" #include "KeyWords.h" #include "Scintilla.h" #include "SciLexer.h" @@ -25,100 +24,29 @@ using namespace Scintilla; #endif -bool is_whitespace(int ch){ - return ch == '\n' || ch == '\r' || ch == '\t' || ch == ' '; +static inline bool IsAWordChar(int ch) { + return (ch < 0x80) && (isalnum(ch) || ch == '.' || + ch == '_' || ch == '?' || ch == '"' || ch == '@' || + ch == '!' || ch == '[' || ch == ']' || ch == '/' || + ch == '+' || ch == '-' || ch == '*' || ch == '<' || + ch == '>' || ch == '=' || ch == ';' || ch == '(' || + ch == ')' ); } -bool is_blank(int ch){ - return ch == '\t' || ch == ' '; +static inline bool IsAWordStart(int ch) { + return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '.'); } -//#define FORTH_DEBUG -#ifdef FORTH_DEBUG -static FILE *f_debug; -#define log(x) fputs(f_debug,x); -#else -#define log(x) -#endif - -#define STATE_LOCALE -#define BL ' ' -static Accessor *st; -static int cur_pos,pos1,pos2,pos0,lengthDoc; -char *buffer; - -char getChar(bool is_bl){ - char ch=st->SafeGetCharAt(cur_pos); - if(is_bl) if(is_whitespace(ch)) ch=BL; - return ch; +static inline bool IsANumChar(int ch) { + return (ch < 0x80) && (isxdigit(ch) || ch == '.' || ch == 'e' || ch == 'E' ); } -char getCharBL(){ - char ch=st->SafeGetCharAt(cur_pos); - return ch; -} -bool is_eol(char ch){ - return ch=='\n' || ch=='\r'; -} - -int parse(char ch, bool skip_eol){ -// pos1 - start pos of word -// pos2 - pos after of word -// pos0 - start pos - char c=0; - int len; - bool is_bl=ch==BL; - pos0=pos1=pos2=cur_pos; - for(;cur_pos9 && base>10) digit-=7; - if(digit<0) return false; - if(digit>=base) return false; - } - return true; -} - -bool is_number(char *s){ - if(strncmp(s,"0x",2)==0) return _is_number(s+2,16); - return _is_number(s,10); -} - -static void ColouriseForthDoc(unsigned int startPos, int length, int, WordList *keywordLists[], Accessor &styler) -{ - st=&styler; - cur_pos=startPos; - lengthDoc = startPos + length; - buffer = new char[length]; - -#ifdef FORTH_DEBUG - f_debug=fopen("c:\\sci.log","at"); -#endif +static void ColouriseForthDoc(unsigned int startPos, int length, int initStyle, WordList *keywordLists[], + Accessor &styler) { WordList &control = *keywordLists[0]; WordList &keyword = *keywordLists[1]; @@ -127,226 +55,120 @@ static void ColouriseForthDoc(unsigned int startPos, int length, int, WordList * WordList &preword2 = *keywordLists[4]; WordList &strings = *keywordLists[5]; - // go through all provided text segment - // using the hand-written state machine shown below - styler.StartAt(startPos); - styler.StartSegment(startPos); - while(parse(BL,true)!=0){ - if(pos0!=pos1){ - styler.ColourTo(pos0,SCE_FORTH_DEFAULT); - styler.ColourTo(pos1-1,SCE_FORTH_DEFAULT); - } - if(strcmp("\\",buffer)==0){ - styler.ColourTo(pos1,SCE_FORTH_COMMENT); - parse(1,false); - styler.ColourTo(pos2,SCE_FORTH_COMMENT); - }else if(strcmp("(",buffer)==0){ - styler.ColourTo(pos1,SCE_FORTH_COMMENT); - parse(')',true); - if(cur_pos