comment syntax suppported

This commit is contained in:
amarjeetkapoor1 2016-06-09 17:13:57 +05:30
parent 0f9949326b
commit a9059b6f27
4 changed files with 86 additions and 10 deletions

View file

@ -12,8 +12,8 @@
* with the CGAL library and distribute executables, as long as you
* follow the requirements of the GNU GPL in regard to all of the
* software in the executable aside from CGAL.
*
* This program is distributed in the hope that it will be useful,
*
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
@ -49,6 +49,11 @@ void Assignment::add_annotations(AnnotationList *annotations)
}
}
void Assignment::add_annotation(Annotation *annotation)
{
this->annotations.insert(std::pair<const std::string, Annotation *>((*annotation).get_name(), &(*annotation)));
}
bool Assignment::has_annotations() const
{
return !annotations.empty();

View file

@ -33,6 +33,7 @@
#include "parsersettings.h"
#include "parser_yacc.h"
#include "module.h"
#include<iostream>
#include <assert.h>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
@ -202,13 +203,21 @@ use[ \t\r\n>]*"<" { BEGIN(cond_use); }
[\n\r\t ]
\/\/ BEGIN(cond_lcomment);
\/\/ { return COMMENT;}
"//"[^0-9"["] { BEGIN(cond_lcomment); stringcontents.clear(); return DCOMMENT;}
<cond_lcomment>{
\n { BEGIN(INITIAL); }
{UNICODE} { parser_error_pos -= strlen(lexertext) - 1; }
[^\n]
\n { BEGIN(INITIAL);
parserlval.text = strdup(stringcontents.c_str());
std::cout<<"afaf";
return TOK_STRING; }
{UNICODE} {
parser_error_pos -= strlen(lexertext) - 1;
stringcontents += lexertext; }
[^\n] { stringcontents += lexertext;}
}
"/*" BEGIN(cond_comment);
<cond_comment>{
"*/" { BEGIN(INITIAL); }

View file

@ -24,7 +24,7 @@
*
*/
%expect 2 /* Expect 2 shift/reduce conflict for ifelse_statement - "dangling else problem" */
//%expect 3 /* Expect 2 shift/reduce conflict for ifelse_statement - "dangling else problem" */
%{
@ -88,15 +88,18 @@ fs::path parser_sourcefile;
%token TOK_MODULE
%token TOK_ANNOTATION
%token COMMENT DCOMMENT
%token TOK_FUNCTION
%token TOK_IF
%token TOK_ELSE
%token TOK_FOR
%token TOK_LET
%token TOK_EACH
%token TOK_EACH
%token <text> TOK_ID
%token <text> TOK_STRING
%token <text> CTOK_STRING
%token <text> TOK_USE
%token <number> TOK_NUMBER
@ -140,6 +143,10 @@ fs::path parser_sourcefile;
%type <arg> argument_decl
%type <annotation> annotation
%type <annotation> parameter
%type <annotations> parameters
%type <annotation> description
%type <annotations> descriptions
%type <annotations> annotations
%type <text> module_id
@ -171,7 +178,7 @@ annotations:
$$->push_back(*$2);
delete $2;
}
annotation:
TOK_ANNOTATION TOK_ID '(' arguments_call ')'
{
@ -179,6 +186,41 @@ annotation:
free($2);
}
descriptions:
description
{
$$ = new AnnotationList();
$$->push_back(*$1);
delete $1;
}
description:
DCOMMENT arguments_call
{
$$ = Annotation::create("Description", *$2);
}
parameters:
parameter
{
$$ = new AnnotationList();
$$->push_back(*$1);
delete $1;
}
|
parameters parameter
{
$$ = $1;
$$->push_back(*$2);
delete $2;
}
parameter:
COMMENT arguments_call
{
$$ = Annotation::create("Parameter", *$2);
}
statement:
';'
| '{' inner_input '}'
@ -187,10 +229,24 @@ statement:
if ($1) scope_stack.top()->addChild($1);
}
| assignment
| annotations assignment
| annotations assignment
{
$2->add_annotations($1);
}
| assignment parameters
{
$1->add_annotations($2);
}
| descriptions assignment
{
$2->add_annotations($1);
}
| descriptions assignment parameters
{
$2->add_annotations($1);
$2->add_annotations($3);
}
| TOK_MODULE TOK_ID '(' arguments_decl optional_commas ')'
{
Module *newmodule = new Module();
@ -383,6 +439,11 @@ expr:
$$ = new ExpressionConst(ValuePtr(std::string($1)));
free($1);
}
| CTOK_STRING
{
$$ = new ExpressionConst(ValuePtr(std::string($1)));
free($1);
}
| TOK_NUMBER
{
$$ = new ExpressionConst(ValuePtr($1));

View file

@ -23,7 +23,8 @@ public:
virtual ~Assignment();
virtual void add_annotations(AnnotationList *annotations);
virtual void add_annotation(Annotation *annotations);
virtual bool has_annotations() const;
virtual const Annotation * annotation(const std::string &name) const;