1 19 20 package org.netbeans.modules.languages.lexer; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import org.netbeans.api.languages.CharInput; 25 import org.netbeans.modules.languages.lexer.SLexer.TokenProperties; 26 import org.netbeans.modules.languages.lexer.SLexer.Vojta; 27 import org.netbeans.modules.languages.parser.Pattern; 28 29 30 class DelegatingInputBridge extends CharInput { 31 32 private InputBridge input; 33 private Pattern start; 34 private Pattern end; 35 private String tokenType; 36 private List <Vojta> embeddings = new ArrayList <Vojta> (); 37 38 DelegatingInputBridge ( 39 InputBridge input, 40 Pattern start, 41 Pattern end, 42 String tokenType 43 ) { 44 this.input = input; 45 this.start = start; 46 this.end = end; 47 this.tokenType = tokenType; 48 } 49 50 public char read () { 51 readEmbeddings (); 52 return input.read (); 53 } 54 55 public void setIndex (int index) { 56 input.setIndex (index); 57 } 58 59 public int getIndex () { 60 return input.getIndex (); 61 } 62 63 public char next () { 64 readEmbeddings (); 65 return input.next (); 66 } 67 68 public boolean eof () { 69 readEmbeddings (); 70 return input.eof (); 71 } 72 73 public String getString (int from, int to) { 74 return input.getString (from, to); 75 } 76 77 public String toString () { 78 return input.toString (); 79 } 80 81 public List <Vojta> getEmbeddings () { 82 List <Vojta> e = embeddings; 83 embeddings = new ArrayList <Vojta> (); 84 return e; 85 } 86 87 private void readEmbeddings () { 88 int startIndex = input.getIndex (); 89 if (!input.eof () && start.next (input) != null) { 90 int startSkipLength = input.getIndex () - startIndex; 91 int endSkipLength = input.getIndex (); 92 while (!input.eof () && end.next (input) == null) { 93 input.read (); 94 endSkipLength = input.getIndex (); 95 } 96 endSkipLength = input.getIndex () - endSkipLength; 97 embeddings.add ( 98 new Vojta ( 99 tokenType, 100 startIndex, 101 input.getIndex (), 102 new TokenProperties ( 103 "E", 104 startSkipLength, 105 endSkipLength 106 ) 107 ) 108 ); 109 } 110 } 111 } 112 113 114 | Popular Tags |