diff options
| author | 2014-08-10 01:03:40 -0400 | |
|---|---|---|
| committer | 2014-08-10 01:03:40 -0400 | |
| commit | d24d2b9ad9b5c895020b56f700a72906346482e5 (patch) | |
| tree | da360c07209e6e327325db53dbb4df05e77cb7e9 /src/cuchaz/enigma/analysis/Lexer.java | |
| parent | added sorting for deobfuscated classes (diff) | |
| download | enigma-fork-d24d2b9ad9b5c895020b56f700a72906346482e5.tar.gz enigma-fork-d24d2b9ad9b5c895020b56f700a72906346482e5.tar.xz enigma-fork-d24d2b9ad9b5c895020b56f700a72906346482e5.zip | |
completely re-wrote token recognizer to bootstrap from Procyon's AST
changed imports to guava instead of whatever collections library happened to be on my classpath
Diffstat (limited to 'src/cuchaz/enigma/analysis/Lexer.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/Lexer.java | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/src/cuchaz/enigma/analysis/Lexer.java b/src/cuchaz/enigma/analysis/Lexer.java deleted file mode 100644 index 602e3a9..0000000 --- a/src/cuchaz/enigma/analysis/Lexer.java +++ /dev/null | |||
| @@ -1,79 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.analysis; | ||
| 12 | |||
| 13 | import java.util.Iterator; | ||
| 14 | |||
| 15 | import jsyntaxpane.SyntaxDocument; | ||
| 16 | import jsyntaxpane.Token; | ||
| 17 | import jsyntaxpane.TokenType; | ||
| 18 | import jsyntaxpane.lexers.JavaLexer; | ||
| 19 | |||
| 20 | public class Lexer implements Iterable<Token> | ||
| 21 | { | ||
| 22 | private SyntaxDocument m_doc; | ||
| 23 | private Iterator<Token> m_iter; | ||
| 24 | |||
| 25 | public Lexer( CharSequence source ) | ||
| 26 | { | ||
| 27 | m_doc = new SyntaxDocument( new JavaLexer() ); | ||
| 28 | m_doc.append( source.toString() ); | ||
| 29 | m_iter = m_doc.getTokens( 0, m_doc.getLength() ); | ||
| 30 | } | ||
| 31 | |||
| 32 | @Override | ||
| 33 | public Iterator<Token> iterator( ) | ||
| 34 | { | ||
| 35 | return m_iter; | ||
| 36 | } | ||
| 37 | |||
| 38 | public String getText( Token token ) | ||
| 39 | { | ||
| 40 | return token.getString( m_doc ); | ||
| 41 | } | ||
| 42 | |||
| 43 | public Token getFirstIdentifier( ) | ||
| 44 | { | ||
| 45 | for( Token token : this ) | ||
| 46 | { | ||
| 47 | if( token.type == TokenType.IDENTIFIER ) | ||
| 48 | { | ||
| 49 | return token; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | return null; | ||
| 53 | } | ||
| 54 | |||
| 55 | public Token getFirstIdentifierMatching( CharSequence val ) | ||
| 56 | { | ||
| 57 | for( Token token : this ) | ||
| 58 | { | ||
| 59 | if( token.type == TokenType.IDENTIFIER && getText( token ).equals( val.toString() ) ) | ||
| 60 | { | ||
| 61 | return token; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | return null; | ||
| 65 | } | ||
| 66 | |||
| 67 | public Token getLastIdentifier( ) | ||
| 68 | { | ||
| 69 | Token lastToken = null; | ||
| 70 | for( Token token : this ) | ||
| 71 | { | ||
| 72 | if( token.type == TokenType.IDENTIFIER ) | ||
| 73 | { | ||
| 74 | lastToken = token; | ||
| 75 | } | ||
| 76 | } | ||
| 77 | return lastToken; | ||
| 78 | } | ||
| 79 | } | ||