Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: tools/lexer_generator/rule_lexer.py

Issue 52593002: Experimental lexer generator: parse rules (in the .re file format) (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/lexer_generator/rule_parser.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/rule_lexer.py
diff --git a/WATCHLISTS b/tools/lexer_generator/rule_lexer.py
similarity index 71%
copy from WATCHLISTS
copy to tools/lexer_generator/rule_lexer.py
index 9c2bce9c5589c22649b4a2c94837f00c8d669be1..be7b42f01d9cbb85ff38ffa83bf2c23085726a36 100644
--- a/WATCHLISTS
+++ b/tools/lexer_generator/rule_lexer.py
@@ -25,22 +25,32 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-# Watchlist Rules
-# Refer: http://dev.chromium.org/developers/contributing-code/watchlists
-
-# IMPORTANT: The regular expression filepath is tested against each path using
-# re.search, so it is not usually necessary to add .*.
-
-{
- 'WATCHLIST_DEFINITIONS': {
- 'public_api': {
- 'filepath': 'include/',
- },
- },
-
- 'WATCHLISTS': {
- 'public_api': [
- 'phajdan.jr@chromium.org',
- ],
- },
-}
+import ply.lex as lex
+
+class RuleLexer:
+
+ tokens = (
+ 'ALIAS',
+ 'CONDITION_TRANSITION',
+ 'CONDITION'
+ )
+
+ t_ignore = " \t\n"
+
+ def t_ALIAS(self, t):
+ r'\s*(?P<name>[a-zA-Z0-9_]+)\s*=\s*(?P<regex>.+)\s*;\s*'
+ return t
+
+ def t_CONDITION_TRANSITION(self, t):
+ r'\s*<(?P<old>[a-zA-Z]+)>\s*(?P<regex>.+)\s*:=>\s*(?P<new>.+)\s*'
+ return t
+
+ def t_CONDITION(self, t):
+ r'\s*<(?P<old>[a-zA-Z]+)>\s*(?P<regex>.+)\s*{(?P<body>.+)}\s*'
+ return t
+
+ def t_error(self, t):
+ raise Exception("Illegal character '%s'" % t.value[0])
+
+ def build(self, **kwargs):
+ self.lexer = lex.lex(module=self, **kwargs)
« no previous file with comments | « no previous file | tools/lexer_generator/rule_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698