source: other-projects/rsyntax-textarea/devel-packages/jflex-1.4.3/src/java_cup/runtime/ComplexSymbolFactory.java@ 25584

Last change on this file since 25584 was 25584, checked in by davidb, 12 years ago

Initial cut an a text edit area for GLI that supports color syntax highlighting

File size: 3.9 KB
Line 
1package java_cup.runtime;
2
3/**
4 * Default Implementation for SymbolFactory, creates
5 * plain old Symbols
6 *
7 * @version last updated 27-03-2006
8 * @author Michael Petter
9 */
10
11/* *************************************************
12 class DefaultSymbolFactory
13
14 interface for creating new symbols
15 ***************************************************/
16public class ComplexSymbolFactory implements SymbolFactory{
17 public static class Location {
18 private String unit="unknown";
19 private int line, column;
20 public Location(String unit, int line, int column){
21 this.unit=unit;
22 this.line=line;
23 this.column=column;
24 }
25 public Location(int line, int column){
26 this.line=line;
27 this.column=column;
28 }
29 public String toString(){
30 return unit+":"+line+"/"+column;
31 }
32 public int getColumn(){
33 return column;
34 }
35 public int getLine(){
36 return line;
37 }
38 public String getUnit(){
39 return unit;
40 }
41 }
42 /**
43 * ComplexSymbol with detailed Location Informations and a Name
44 */
45 public static class ComplexSymbol extends Symbol {
46 protected String name;
47 protected Location xleft,xright;
48 public ComplexSymbol(String name, int id) {
49 super(id);
50 this.name=name;
51 }
52 public ComplexSymbol(String name, int id, Object value) {
53 super(id,value);
54 this.name=name;
55 }
56 public String toString(){
57 if (xleft==null || xright==null) return "Symbol: "+name;
58 return "Symbol: "+name+" ("+xleft+" - "+xright+")";
59 }
60 public ComplexSymbol(String name, int id, int state) {
61 super(id,state);
62 this.name=name;
63 }
64 public ComplexSymbol(String name, int id, Symbol left, Symbol right) {
65 super(id,left,right);
66 this.name=name;
67 if (left!=null) this.xleft = ((ComplexSymbol)left).xleft;
68 if (right!=null) this.xright= ((ComplexSymbol)right).xright;
69 }
70 public ComplexSymbol(String name, int id, Location left, Location right) {
71 super(id);
72 this.name=name;
73 this.xleft=left;
74 this.xright=right;
75 }
76 public ComplexSymbol(String name, int id, Symbol left, Symbol right, Object value) {
77 super(id,value);
78 this.name=name;
79 if (left!=null) this.xleft = ((ComplexSymbol)left).xleft;
80 if (right!=null) this.xright= ((ComplexSymbol)right).xright;
81 }
82 public ComplexSymbol(String name, int id, Location left, Location right, Object value) {
83 super(id,value);
84 this.name=name;
85 this.xleft=left;
86 this.xright=right;
87 }
88 public Location getLeft(){
89 return xleft;
90 }
91 public Location getRight(){
92 return xright;
93 }
94 }
95
96
97 // Factory methods
98 public Symbol newSymbol(String name, int id, Location left, Location right, Object value){
99 return new ComplexSymbol(name,id,left,right,value);
100 }
101 public Symbol newSymbol(String name, int id, Location left, Location right){
102 return new ComplexSymbol(name,id,left,right);
103 }
104 public Symbol newSymbol(String name, int id, Symbol left, Symbol right, Object value){
105 return new ComplexSymbol(name,id,left,right,value);
106 }
107 public Symbol newSymbol(String name, int id, Symbol left, Symbol right){
108 return new ComplexSymbol(name,id,left,right);
109 }
110 public Symbol newSymbol(String name, int id){
111 return new ComplexSymbol(name,id);
112 }
113 public Symbol newSymbol(String name, int id, Object value){
114 return new ComplexSymbol(name,id,value);
115 }
116 public Symbol startSymbol(String name, int id, int state){
117 return new ComplexSymbol(name,id,state);
118 }
119}
Note: See TracBrowser for help on using the repository browser.