Skip to content

Commit

Permalink
Add to tokens comments and whitespaces if Y2EXPORTCOMMENTS is set
Browse files Browse the repository at this point in the history
it is needed for exporting comments from ycp code to ruby one. It is enclosed in
env variable to avoid performance regression in common run.
  • Loading branch information
jreidinger committed Jun 26, 2013
1 parent deac37f commit 200f4d0
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 153 deletions.
12 changes: 12 additions & 0 deletions libycp/src/Scanner.cc
Expand Up @@ -324,6 +324,18 @@ Scanner::scannedType () const
return m_scannedType;
}

void
Scanner::setCommentBefore (const string & comment_before)
{
m_commentBefore = comment_before;
}

std::string
Scanner::commentBefore () const
{
return m_commentBefore;
}


int
Scanner::lineNumber () const
Expand Down
9 changes: 9 additions & 0 deletions libycp/src/include/ycp/Scanner.h
Expand Up @@ -120,6 +120,11 @@ class Scanner : public yyFlexLexer, public Logger
*/
constTypePtr m_scannedType;

/**
* Holds the comment before the most recent token
*/
std::string m_commentBefore;

/**
* Holds the line number of scanned_value
*/
Expand Down Expand Up @@ -263,6 +268,8 @@ class Scanner : public yyFlexLexer, public Logger
*/
constTypePtr scannedType() const;

std::string commentBefore () const;

/**
* Gets the line number of the latest scanned token.
*/
Expand Down Expand Up @@ -309,6 +316,8 @@ class Scanner : public yyFlexLexer, public Logger
*/
void setScannedToken (const tokenValue & value, constTypePtr type);

void setCommentBefore (const string & comment_before);

/**
* Internal helper function that deals with strings of arbitrary
* length
Expand Down
10 changes: 9 additions & 1 deletion libycp/src/parser.yy
Expand Up @@ -19,12 +19,13 @@
Implementation rules
yystype is a struct with four elements
yystype is a struct with five elements
YCodePtr c pointer to code (where applicable)
tokenValue v value of token (where applicable)
constTypePtr t type of current syntactic element
int l line number of syntactic element
string com comment preceding the token
c and v somehow represent a similar kind of information and are
mostly valid alternating.
Expand All @@ -33,13 +34,19 @@
identifiers, etc.
c is used for the 'high level' (parser) syntax like expressions,
statements, blocks, etc.
NOTE that the distinction is mostly between terminals and nonterminals,
but notably the 'type' nonterminal noes not have YCode and holds a Type
tree instead.
t is valid everywhere since every syntactic element has a type.
** t == 0 means 'error', all other yystype are undefined in this case.
l is valid everywhere since every syntactic element appears at a
distinctive line number in the source file.
com is valid for scanner tokens. As soon as there is an YCode, we
move it off com to c.
/-*/
%{
#include <stdio.h>
Expand Down Expand Up @@ -85,6 +92,7 @@ struct yystype_type {
tokenValue v; // token (for scanner level syntax)
constTypePtr t; // type (NULL for error)
int l;
std::string com; // comment before the token
};
#define YYSTYPE yystype_type

Expand Down

0 comments on commit 200f4d0

Please sign in to comment.