Handle single quotes
This commit is contained in:
parent
4d503899a3
commit
d66e146a89
@ -33,7 +33,8 @@ Fl_Text_Display::Style_Table_Entry CodeEditor::
|
|||||||
{ FL_BLUE, FL_COURIER, 11 }, // D - Strings
|
{ FL_BLUE, FL_COURIER, 11 }, // D - Strings
|
||||||
{ FL_DARK_RED, FL_COURIER, 11 }, // E - Directives
|
{ FL_DARK_RED, FL_COURIER, 11 }, // E - Directives
|
||||||
{ FL_DARK_RED, FL_COURIER_BOLD, 11 }, // F - Types
|
{ FL_DARK_RED, FL_COURIER_BOLD, 11 }, // F - Types
|
||||||
{ FL_BLUE, FL_COURIER_BOLD, 11 } // G - Keywords
|
{ FL_BLUE, FL_COURIER_BOLD, 11 }, // G - Keywords
|
||||||
|
{ 220, /* med cyan */ FL_COURIER, 11 } // H - Single quote chars
|
||||||
};
|
};
|
||||||
|
|
||||||
// attempt to make the fluid code editor widget honour textsize setting
|
// attempt to make the fluid code editor widget honour textsize setting
|
||||||
@ -61,6 +62,7 @@ void CodeEditor::style_parse(const char *in_tbuff, // text buffer to par
|
|||||||
// 'E' - Directives #define, #include..
|
// 'E' - Directives #define, #include..
|
||||||
// 'F' - Types void, char..
|
// 'F' - Types void, char..
|
||||||
// 'G' - Keywords if, while..
|
// 'G' - Keywords if, while..
|
||||||
|
// 'H' - Chars 'x'
|
||||||
|
|
||||||
StyleParse sp;
|
StyleParse sp;
|
||||||
sp.tbuff = in_tbuff;
|
sp.tbuff = in_tbuff;
|
||||||
@ -83,8 +85,10 @@ void CodeEditor::style_parse(const char *in_tbuff, // text buffer to par
|
|||||||
if ( !sp.parse_escape() ) break;
|
if ( !sp.parse_escape() ) break;
|
||||||
} else if ( strncmp(sp.tbuff, "//", 2)==0 ) { // Line comment?
|
} else if ( strncmp(sp.tbuff, "//", 2)==0 ) { // Line comment?
|
||||||
if ( !sp.parse_line_comment() ) break;
|
if ( !sp.parse_line_comment() ) break;
|
||||||
} else if ( c == '"' ) { // Start of quoted string?
|
} else if ( c == '"' ) { // Start of double quoted string?
|
||||||
if ( !sp.parse_quoted_string() ) break;
|
if ( !sp.parse_quoted_string('"', 'D') ) break;
|
||||||
|
} else if ( c == '\'' ) { // Start of single quoted string?
|
||||||
|
if ( !sp.parse_quoted_string('\'', 'H') ) break;
|
||||||
} else if ( c == '#' && sp.lwhite ) { // Start of '#' directive?
|
} else if ( c == '#' && sp.lwhite ) { // Start of '#' directive?
|
||||||
if ( !sp.parse_directive() ) break;
|
if ( !sp.parse_directive() ) break;
|
||||||
} else if ( !sp.last && (islower(c) || c == '_') ) { // Possible C/C++ keyword?
|
} else if ( !sp.last && (islower(c) || c == '_') ) { // Possible C/C++ keyword?
|
||||||
|
@ -258,18 +258,19 @@ int StyleParse::parse_keyword() {
|
|||||||
return parse_over_key(key, style);
|
return parse_over_key(key, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Style parse a quoted string.
|
// Style parse a quoted string, either "" or ''.
|
||||||
// Returns 0 if hit end of buffer, 1 otherwise.
|
// Returns 0 if hit end of buffer, 1 otherwise.
|
||||||
//
|
//
|
||||||
int StyleParse::parse_quoted_string() {
|
int StyleParse::parse_quoted_string(char quote_char, // e.g. '"' or '\''
|
||||||
style = 'D'; // start string style
|
char in_style) { // style for quoted text
|
||||||
|
style = in_style; // start string style
|
||||||
if ( !parse_over_char() ) return 0; // parse over opening quote
|
if ( !parse_over_char() ) return 0; // parse over opening quote
|
||||||
|
|
||||||
// Parse until closing quote reached
|
// Parse until closing quote reached
|
||||||
char c;
|
char c;
|
||||||
while ( len > 0 ) {
|
while ( len > 0 ) {
|
||||||
c = tbuff[0];
|
c = tbuff[0];
|
||||||
if ( c == '"' ) { // Closing quote? Parse and done
|
if ( c == quote_char ) { // Closing quote? Parse and done
|
||||||
if ( !parse_over_char() ) return 0; // close quote
|
if ( !parse_over_char() ) return 0; // close quote
|
||||||
break;
|
break;
|
||||||
} else if ( c == '\\' ) { // Escape sequence? Parse over, continue
|
} else if ( c == '\\' ) { // Escape sequence? Parse over, continue
|
||||||
|
@ -50,7 +50,8 @@ public:
|
|||||||
int parse_over_key(const char *key, char s);
|
int parse_over_key(const char *key, char s);
|
||||||
int parse_over_angles(char s);
|
int parse_over_angles(char s);
|
||||||
int parse_keyword(); // "switch"
|
int parse_keyword(); // "switch"
|
||||||
int parse_quoted_string(); // "hello"
|
int parse_quoted_string(char quote_char, char in_style);
|
||||||
|
// "hello", 'x'
|
||||||
int parse_directive(); // "#define"
|
int parse_directive(); // "#define"
|
||||||
int parse_line_comment(); // "// text.."
|
int parse_line_comment(); // "// text.."
|
||||||
int parse_escape(); // "\'"
|
int parse_escape(); // "\'"
|
||||||
|
Loading…
Reference in New Issue
Block a user