ltlparse: allow comments

* src/ltlparse/ltlscan.ll: Skip comments.
* src/ltltest/ltlfilt.test: Test this.
* NEWS: Mention it.
This commit is contained in:
Alexandre Duret-Lutz 2014-12-11 21:43:08 +01:00
parent 9cee6e6fa1
commit f9e859d765
3 changed files with 34 additions and 4 deletions

2
NEWS
View file

@ -63,6 +63,8 @@ New in spot 1.99a (not yet released)
either by Divine (as patched by the LTSmin people) or by either by Divine (as patched by the LTSmin people) or by
Spins (the LTSmin compiler for Promela). Spins (the LTSmin compiler for Promela).
- LTL formulas can include /* comments */.
- Spot is now compiling in C++11 mode. The set of features we use - Spot is now compiling in C++11 mode. The set of features we use
requires GCC >= 4.6 or Clang >= 3.1. These minimum versions requires GCC >= 4.6 or Clang >= 3.1. These minimum versions
are old enough that it should not be an issue to most people. are old enough that it should not be an issue to most people.

View file

@ -40,6 +40,8 @@ static int start_token = 0;
static int parent_level = 0; static int parent_level = 0;
static bool missing_parent = false; static bool missing_parent = false;
static bool lenient_mode = false; static bool lenient_mode = false;
static int orig_cond = 0;
static unsigned comment_level = 0;
typedef ltlyy::parser::token token; typedef ltlyy::parser::token token;
@ -50,6 +52,7 @@ typedef ltlyy::parser::token token;
%x in_bra %x in_bra
%x sqbracket %x sqbracket
%x lbt %x lbt
%x in_COMMENT
BOX "[]"|"□"|"⬜"|"◻" BOX "[]"|"□"|"⬜"|"◻"
DIAMOND "<>"|"◇"|"⋄"|"♢" DIAMOND "<>"|"◇"|"⋄"|"♢"
@ -61,6 +64,8 @@ CIRCLE "()"|"○"|"◯"
NOT "!"|"~"|"¬" NOT "!"|"~"|"¬"
BOXARROW {BOX}{ARROWL}|"|"{ARROWL}|"↦" BOXARROW {BOX}{ARROWL}|"|"{ARROWL}|"↦"
BOXDARROW {BOX}{DARROWL}|"|"{DARROWL}|"⤇" BOXDARROW {BOX}{DARROWL}|"|"{DARROWL}|"⤇"
eol \n+|\r+
eol2 (\n\r)+|(\r\n)+
%% %%
@ -74,6 +79,30 @@ BOXDARROW {BOX}{DARROWL}|"|"{DARROWL}|"⤇"
yylloc->step(); yylloc->step();
%} %}
<*>"/""*"+ {
if (YY_START != in_COMMENT)
{
orig_cond = YY_START;
BEGIN(in_COMMENT);
comment_level = 0;
}
++comment_level;
}
<in_COMMENT>{
[^*/\n\r]* continue;
"/"[^*\n\r]* continue;
"*"+[^*/\n\r]* continue;
{eol} yylloc->lines(yyleng); yylloc->end.column = 1;
{eol2} yylloc->lines(yyleng / 2); yylloc->end.column = 1;
"*"+"/" if (--comment_level == 0) BEGIN(orig_cond);
<<EOF>> {
BEGIN(orig_cond);
error_list.push_back(
spot::ltl::one_parse_error(*yylloc,
"unclosed comment"));
return 0;
}
}
"(" { "(" {
if (!lenient_mode) if (!lenient_mode)
@ -308,7 +337,6 @@ BOXDARROW {BOX}{DARROWL}|"|"{DARROWL}|"⤇"
return token::ATOMIC_PROP; return token::ATOMIC_PROP;
} }
<*>. return *yytext; <*>. return *yytext;
<<EOF>> return token::END_OF_INPUT; <<EOF>> return token::END_OF_INPUT;

View file

@ -34,14 +34,14 @@ checkopt()
# The empty lines in the file are meant, we want to make sure that # The empty lines in the file are meant, we want to make sure that
# they are ignored. # they are ignored.
cat >formulas <<EOF cat >formulas <<EOF
GFa | FGb GFa | FGb /* comment to ignore */
F(GFa | Gb) F(GFa | /* tricky /* comment */)*/ Gb)
F(b W GFa) F(b W GFa)
GFa | Gb GFa | Gb
b W GFa b W GFa
!{a;b*;c}! !{a;b*;c}!
!{a:b*:c} !{a:b[*/*ignore me*/]:c/*ignore this comment*/}
a U Fb a U Fb
G(a & Xb) G(a & Xb)
Xa Xa