Improvements related to lexer
Improvements related to lexer: * duplicated clone elimination * magic numbers are replaced with constants * functions are moved form util to lit-char-helpers JerryScript-DCO-1.0-Signed-off-by: István Kádár ikadar@inf.u-szeged.hu
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "ecma-helpers.h"
|
||||
#include "lit-char-helpers.h"
|
||||
|
||||
/** \addtogroup parser Parser
|
||||
* @{
|
||||
@@ -28,132 +27,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks whether the next UTF8 character is a valid identifier start.
|
||||
*
|
||||
* @return non-zero if it is.
|
||||
*/
|
||||
int
|
||||
util_is_identifier_start (const uint8_t *src_p) /* pointer to a vaild UTF8 character */
|
||||
{
|
||||
if (*src_p <= 127)
|
||||
{
|
||||
return util_is_identifier_start_character (*src_p);
|
||||
}
|
||||
|
||||
return util_is_identifier_start_character (lit_utf8_peek_next (src_p));
|
||||
} /* util_is_identifier_start */
|
||||
|
||||
/**
|
||||
* Checks whether the next UTF8 character is a valid identifier part.
|
||||
*
|
||||
* @return non-zero if it is.
|
||||
*/
|
||||
int
|
||||
util_is_identifier_part (const uint8_t *src_p) /* pointer to a vaild UTF8 character */
|
||||
{
|
||||
if (*src_p <= 127)
|
||||
{
|
||||
return util_is_identifier_part_character (*src_p);
|
||||
}
|
||||
|
||||
return util_is_identifier_part_character (lit_utf8_peek_next (src_p));
|
||||
} /* util_is_identifier_part */
|
||||
|
||||
/**
|
||||
* Checks whether the character is a valid identifier start.
|
||||
*
|
||||
* @return non-zero if it is.
|
||||
*/
|
||||
int
|
||||
util_is_identifier_start_character (uint16_t chr) /**< EcmaScript character */
|
||||
{
|
||||
if (chr <= 127)
|
||||
{
|
||||
return (((chr | 0x20) >= LIT_CHAR_LOWERCASE_A && (chr | 0x20) <= LIT_CHAR_LOWERCASE_Z)
|
||||
|| chr == LIT_CHAR_DOLLAR_SIGN
|
||||
|| chr == LIT_CHAR_UNDERSCORE);
|
||||
}
|
||||
|
||||
return lit_char_is_unicode_letter (chr);
|
||||
|
||||
} /* util_is_identifier_start_character */
|
||||
|
||||
/**
|
||||
* Checks whether the character is a valid identifier part.
|
||||
*
|
||||
* @return non-zero if it is.
|
||||
*/
|
||||
int
|
||||
util_is_identifier_part_character (uint16_t chr) /**< EcmaScript character */
|
||||
{
|
||||
if (chr <= 127)
|
||||
{
|
||||
return (((chr | 0x20) >= LIT_CHAR_LOWERCASE_A && (chr | 0x20) <= LIT_CHAR_LOWERCASE_Z)
|
||||
|| (chr >= LIT_CHAR_0 && chr <= LIT_CHAR_9)
|
||||
|| chr == LIT_CHAR_DOLLAR_SIGN
|
||||
|| chr == LIT_CHAR_UNDERSCORE);
|
||||
}
|
||||
|
||||
return (lit_char_is_unicode_letter (chr)
|
||||
|| lit_char_is_unicode_non_letter_ident_part (chr));
|
||||
} /* util_is_identifier_part_character */
|
||||
|
||||
/**
|
||||
* Converts a character to UTF8 bytes.
|
||||
*
|
||||
* @return length of the UTF8 representation.
|
||||
*/
|
||||
size_t
|
||||
util_to_utf8_bytes (uint8_t *dst_p, /**< destination buffer */
|
||||
uint16_t chr) /**< EcmaScript character */
|
||||
{
|
||||
if (!(chr & ~0x007f))
|
||||
{
|
||||
/* 00000000 0xxxxxxx -> 0xxxxxxx */
|
||||
*dst_p = (uint8_t) chr;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(chr & ~0x07ff))
|
||||
{
|
||||
/* 00000yyy yyxxxxxx -> 110yyyyy 10xxxxxx */
|
||||
*(dst_p++) = (uint8_t) (0xc0 | ((chr >> 6) & 0x1f));
|
||||
*dst_p = (uint8_t) (0x80 | (chr & 0x3f));
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* zzzzyyyy yyxxxxxx -> 1110zzzz 10yyyyyy 10xxxxxx */
|
||||
*(dst_p++) = (uint8_t) (0xe0 | ((chr >> 12) & 0x0f));
|
||||
*(dst_p++) = (uint8_t) (0x80 | ((chr >> 6) & 0x3f));
|
||||
*dst_p = (uint8_t) (0x80 | (chr & 0x3f));
|
||||
return 3;
|
||||
} /* util_to_utf8_bytes */
|
||||
|
||||
/**
|
||||
* Returns the length of the UTF8 representation of a character.
|
||||
*
|
||||
* @return length of the UTF8 representation.
|
||||
*/
|
||||
size_t
|
||||
util_get_utf8_length (uint16_t chr) /**< EcmaScript character */
|
||||
{
|
||||
if (!(chr & ~0x007f))
|
||||
{
|
||||
/* 00000000 0xxxxxxx */
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(chr & ~0x07ff))
|
||||
{
|
||||
/* 00000yyy yyxxxxxx */
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* zzzzyyyy yyxxxxxx */
|
||||
return 3;
|
||||
} /* util_get_utf8_length */
|
||||
|
||||
/**
|
||||
* Free literal.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user