From: Jay Freeman (saurik) <saurik@saurik.com> Date: Fri, 14 Sep 2012 03:56:09 +0000 (-0700) Subject: Optionally return comments from lexer to highlight. X-Git-Tag: v0.9.460~26 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/abc79d6e51bae6d48642724135de4a2d5666a48c Optionally return comments from lexer to highlight. --- diff --git a/Cycript.l.in b/Cycript.l.in index 37707a6..58ed9fd 100644 --- a/Cycript.l.in +++ b/Cycript.l.in @@ -83,6 +83,12 @@ typedef cy::parser::token tk; yylloc->columns(yyleng); \ } +#define M { \ + if (yyextra->commented_) { \ + I(comment, Comment(Y), tk::Comment, hi::Comment); \ + } \ +} + int H(char c) { if (c >= '0' && c <= '9') return c - '0'; @@ -147,12 +153,12 @@ XMLName {XMLNameStart}{XMLNamePart}* <RegExp>\/{RegularExpressionBody}\/{RegularExpressionFlags} L C I(literal, RegEx(Y), tk::RegularExpressionLiteral, hi::Constant); -\/\/[^\n]* L +\/\/[^\n]* L M /* http://ostermiller.org/findcomment.html */ /* XXX: unify these two rules using !? */ \/\*!([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/ V() C I(comment, Comment(Y), tk::Comment, hi::Comment); -\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/ V(N) +\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/ V(N) M @begin E4X <RegExp>"<>" L F(tk::LeftRight, hi::Structure); diff --git a/Highlight.cpp b/Highlight.cpp index 7505167..2587d19 100644 --- a/Highlight.cpp +++ b/Highlight.cpp @@ -56,6 +56,7 @@ struct CYColor { void CYLexerHighlight(const char *data, size_t size, std::ostream &output, bool ignore) { CYStream stream(data, data + size); CYDriver driver(stream); + driver.commented_ = true; size_t offset(0); cy::position current; diff --git a/Parser.cpp b/Parser.cpp index f0ad37f..09aaf7a 100644 --- a/Parser.cpp +++ b/Parser.cpp @@ -30,6 +30,7 @@ CYDriver::CYDriver(std::istream &data, const std::string &filename) : state_(CYClear), data_(data), strict_(false), + commented_(false), filename_(filename), program_(NULL), auto_(false), diff --git a/Parser.hpp b/Parser.hpp index bff219b..d915305 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -506,6 +506,7 @@ class CYDriver { std::istream &data_; bool strict_; + bool commented_; enum Condition { RegExpCondition,