Skip to content

Commit

Permalink
Parse lisp comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
indigoparadox committed Aug 9, 2024
1 parent 27397b8 commit 5fc0c96
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/mlispe.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ MERROR_RETVAL mlisp_env_dump(
" \"%s\" (" #const_name "): " fmt, \
i, &(strpool[e->name_strpool_idx]), e->value.name ); \

mdata_strpool_lock( &(parser->strpool), strpool ); \
mdata_strpool_lock( &(parser->strpool), strpool );
mdata_vector_lock( &(exec->env) );
while( i < mdata_vector_ct( &(exec->env) ) ) {
assert( mdata_vector_is_locked( &(exec->env) ) );
Expand Down Expand Up @@ -324,7 +324,7 @@ MERROR_RETVAL mlisp_env_dump(
i++;
}
mdata_vector_unlock( &(exec->env) );
mdata_strpool_unlock( &(parser->strpool), strpool ); \
mdata_strpool_unlock( &(parser->strpool), strpool );

cleanup:

Expand Down
18 changes: 17 additions & 1 deletion src/mlispp.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
f( MLISP_PSTATE_SYMBOL_OP, 1 ) \
f( MLISP_PSTATE_SYMBOL, 2 ) \
f( MLISP_PSTATE_STRING, 3 ) \
f( MLISP_PSTATE_LAMBDA_ARGS, 4 )
f( MLISP_PSTATE_LAMBDA_ARGS, 4 ) \
f( MLISP_PSTATE_COMMENT, 5 )

/**
* \addtogroup mlisp_parser MLISP Abstract Syntax Tree Parser
Expand Down Expand Up @@ -377,6 +378,12 @@ MERROR_RETVAL mlisp_parse_c( struct MLISP_PARSER* parser, char c ) {
switch( c ) {
case '\r':
case '\n':
if( MLISP_PSTATE_COMMENT == mlisp_parser_pstate( parser ) ) {
/* End comment on newline. */
mlisp_parser_pstate_pop( parser );
break;
}

case '\t':
case ' ':
if(
Expand Down Expand Up @@ -502,7 +509,16 @@ MERROR_RETVAL mlisp_parse_c( struct MLISP_PARSER* parser, char c ) {
}
break;

case ';':
if( MLISP_PSTATE_COMMENT != mlisp_parser_pstate( parser ) ) {
mlisp_parser_pstate_push( parser, MLISP_PSTATE_COMMENT );
break;
}

default:
if( MLISP_PSTATE_COMMENT == mlisp_parser_pstate( parser ) ) {
break;
}
retval = mlisp_parser_append_token( parser, c );
maug_cleanup_if_not_ok();
break;
Expand Down

0 comments on commit 5fc0c96

Please sign in to comment.