Commits

Ned Batchelder  committed e760d5a

Split the main program into its own file.

  • Participants
  • Parent commits 05fe9b3

Comments (0)

Files changed (2)

+"""A main program for jslex."""
+
+import sys
+from jslex import JsLexer
+
+def show_js_tokens(jstext, ws=False):
+    line = 1
+    lexer = JsLexer()
+    for name, tok in lexer.lex(jstext):
+        print_it = True
+        if name == 'ws' and not ws:
+            print_it = False
+        if print_it:
+            print "%4d %s: %r" % (line, name, tok)
+        line += tok.count("\n")
+
+if __name__ == '__main__':
+    show_js_tokens(open(sys.argv[1]).read())
             tok = '"REGEX"';
         c.append(tok)
     return ''.join(c)
-
-if __name__ == '__main__':
-    import sys
-    lexer = JsLexer()
-    for name, tok in lexer.lex(open(sys.argv[1]).read()):
-        print "%s: %r" % (name, tok)
-