66#include "misc.h"
77#include "mpconfig.h"
88#include "lexer.h"
9+ #include "lexerunix.h"
910
1011#if MICROPY_ENABLE_LEXER_UNIX
1112
12- typedef struct _str_buf_t {
13- bool free ; // free src_beg when done
14- const char * src_beg ; // beginning of source
15- const char * src_cur ; // current location in source
16- const char * src_end ; // end (exclusive) of source
17- } str_buf_t ;
18-
19- unichar str_buf_next_char (str_buf_t * sb ) {
20- if (sb -> src_cur < sb -> src_end ) {
21- return * sb -> src_cur ++ ;
22- } else {
23- return MP_LEXER_CHAR_EOF ;
24- }
25- }
26-
27- void str_buf_free (str_buf_t * sb ) {
28- if (sb ) {
29- if (sb -> free ) {
30- m_del (char , (char * )sb -> src_beg , 0 /* unknown size of src_beg */ );
31- }
32- m_del_obj (str_buf_t , sb );
33- }
34- }
35-
36- mp_lexer_t * mp_lexer_new_from_str_len (const char * src_name , const char * str , uint len , bool free_str ) {
37- str_buf_t * sb = m_new (str_buf_t , 1 );
38- sb -> free = free_str ;
39- sb -> src_beg = str ;
40- sb -> src_cur = str ;
41- sb -> src_end = str + len ;
42- return mp_lexer_new (src_name , sb , (mp_lexer_stream_next_char_t )str_buf_next_char , (mp_lexer_stream_close_t )str_buf_free );
43- }
44-
4513mp_lexer_t * mp_lexer_new_from_file (const char * filename ) {
4614 int fd = open (filename , O_RDONLY );
4715 if (fd < 0 ) {
@@ -59,7 +27,7 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
5927 return NULL ;
6028 }
6129
62- return mp_lexer_new_from_str_len (filename , data , size , true );
30+ return mp_lexer_new_from_str_len (filename , data , size , size );
6331}
6432
6533/******************************************************************************/
0 commit comments