From: Jay Freeman (saurik) Date: Sun, 15 Nov 2009 21:51:22 +0000 (+0000) Subject: Implemented YUI /*! ... */ documentation comments. X-Git-Tag: v0.9.432~167 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/320ce7537deb2d6f8a5db078d2d6aab1e1a77f8f?hp=9561f209ba7d08b95e2bd3b86b6338bd2537ea55 Implemented YUI /*! ... */ documentation comments. --- diff --git a/Cycript.l.in b/Cycript.l.in index 7323e25..91e6a63 100644 --- a/Cycript.l.in +++ b/Cycript.l.in @@ -161,6 +161,7 @@ XMLName {XMLNameStart}{XMLNamePart}* \/{RegularExpressionBody}\/{RegularExpressionFlags} E("") \/\/[^\n]* L +\/\*!(\n|[^\*]|\*[^/])*\*\/ V() C yylval->comment_ = new(yyextra->pool_) CYComment(apr_pstrmemdup(yyextra->pool_, yytext, yyleng)); return tk::Comment; \/\*(\n|[^\*]|\*[^/])*\*\/ V(N) @begin E4X diff --git a/Cycript.y.in b/Cycript.y.in index 79d277d..e22535d 100644 --- a/Cycript.y.in +++ b/Cycript.y.in @@ -67,6 +67,7 @@ typedef struct { CYBoolean *boolean_; CYClause *clause_; cy::Syntax::Catch *catch_; + CYComment *comment_; CYComprehension *comprehension_; CYCompound *compound_; CYDeclaration *declaration_; @@ -209,6 +210,8 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %token SemiColon ";" %token NewLine "\n" +%token Comment + %token OpenParen "(" %token CloseParen ")" @@ -1601,6 +1604,12 @@ MemberAccess /* }}} */ @end +/* YUI: Documentation Comments {{{ */ +Statement_ + : Comment { $$ = $1; } + ; +/* }}} */ + @begin E4X /* Lexer State {{{ */ LexPushRegExp diff --git a/Output.cpp b/Output.cpp index 9ffc4f6..04f893c 100644 --- a/Output.cpp +++ b/Output.cpp @@ -85,14 +85,24 @@ CYOutput &CYOutput::operator <<(char rhs) { for (unsigned i(0); i != indent_; ++i) out_ << " "; else goto done; - else goto work; + else if (rhs == '\r') { + if (right_) { + out_ << '\n'; + right_ = false; + goto mode; + } + } else goto work; + right_ = true; + mode: mode_ = NoMode; goto done; work: - if (mode_ == Terminated && rhs != '}') + if (mode_ == Terminated && rhs != '}') { + right_ = true; out_ << ';'; + } if (rhs == ';') { if (pretty_) @@ -116,6 +126,7 @@ CYOutput &CYOutput::operator <<(char rhs) { } else none: mode_ = NoMode; + right_ = true; out_ << rhs; done: return *this; @@ -141,6 +152,7 @@ CYOutput &CYOutput::operator <<(const char *rhs) { else mode_ = NoMode; + right_ = true; out_ << rhs; return *this; } @@ -222,6 +234,12 @@ void Catch::Output(CYOutput &out) const { } } +void CYComment::Output(CYOutput &out, CYFlags flags) const { + out << '\r'; + out << value_; + out << '\r'; +} + void CYCompound::Output(CYOutput &out, CYFlags flags) const { if (CYExpression *expression = expressions_) if (CYExpression *next = expression->next_) { diff --git a/Parser.hpp b/Parser.hpp index a76faaa..8f42bc3 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -83,6 +83,7 @@ struct CYOutput { std::ostream &out_; bool pretty_; unsigned indent_; + bool right_; enum { NoMode, @@ -96,6 +97,7 @@ struct CYOutput { out_(out), pretty_(false), indent_(0), + right_(false), mode_(NoMode) { } @@ -251,6 +253,20 @@ struct CYIdentifier : } }; +struct CYComment : + CYStatement +{ + const char *value_; + + CYComment(const char *value) : + value_(value) + { + } + + virtual CYStatement *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYLabel : CYStatement { diff --git a/Replace.cpp b/Replace.cpp index b41aac1..8039118 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -134,6 +134,10 @@ void CYClause::Replace(CYContext &context) { $T() next_->Replace(context); } +CYStatement *CYComment::Replace(CYContext &context) { + return NULL; +} + CYExpression *CYCompound::Replace(CYContext &context) { expressions_ = expressions_->ReplaceAll(context); return NULL;