mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
.
This commit is contained in:
parent
0425d84989
commit
f63d52130f
2 changed files with 29 additions and 10 deletions
|
@ -4,7 +4,7 @@ package org.eclipse.cdt.debug.mi.core.output;
|
||||||
*/
|
*/
|
||||||
public class MIOutput {
|
public class MIOutput {
|
||||||
|
|
||||||
public static final String terminator = "(gdb)\n";
|
public static final String terminator = "(gdb)";
|
||||||
public static final MIOOBRecord[] nullOOBRecord = new MIOOBRecord[0];
|
public static final MIOOBRecord[] nullOOBRecord = new MIOOBRecord[0];
|
||||||
MIResultRecord rr = null;
|
MIResultRecord rr = null;
|
||||||
MIOOBRecord[] oobs = null;
|
MIOOBRecord[] oobs = null;
|
||||||
|
|
|
@ -82,7 +82,11 @@ import java.util.StringTokenizer;
|
||||||
public class MIParser {
|
public class MIParser {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the AST for MI.
|
* Point of entry to create an AST for MI.
|
||||||
|
*
|
||||||
|
* @param buffer Output from MI Channel.
|
||||||
|
* @return MIOutput
|
||||||
|
* @see MIOutput
|
||||||
*/
|
*/
|
||||||
public MIOutput parse(String buffer) {
|
public MIOutput parse(String buffer) {
|
||||||
MIOutput mi = new MIOutput();
|
MIOutput mi = new MIOutput();
|
||||||
|
@ -98,19 +102,22 @@ public class MIParser {
|
||||||
if (Character.isDigit(token.charAt(0))) {
|
if (Character.isDigit(token.charAt(0))) {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
while (Character.isDigit(token.charAt(i)) && i < token.length()) {
|
while (Character.isDigit(token.charAt(i)) && i < token.length()) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
String numbers = token.substring(i);
|
String numbers = token.substring(i);
|
||||||
try {
|
try {
|
||||||
id = Integer.parseInt(numbers);
|
id = Integer.parseInt(numbers);
|
||||||
} catch(NumberFormatException e) {
|
} catch(NumberFormatException e) {
|
||||||
}
|
}
|
||||||
|
// Consume the token.
|
||||||
token = token.substring(i);
|
token = token.substring(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process ResultRecord | Out-Of-Band Records
|
// Process ResultRecord | Out-Of-Band Records
|
||||||
if (token.charAt(0) == '^') {
|
if (token.charAt(0) == '^') {
|
||||||
rr = processMIResultRecord(token.substring(1), id);
|
rr = processMIResultRecord(token.substring(1), id);
|
||||||
|
//} else if(token.startsWith(MIOutput.terminator)) {
|
||||||
|
// break;
|
||||||
} else {
|
} else {
|
||||||
MIOOBRecord band = processMIOOBRecord(token.substring(1), id);
|
MIOOBRecord band = processMIOOBRecord(token.substring(1), id);
|
||||||
if (band != null) {
|
if (band != null) {
|
||||||
|
@ -156,6 +163,8 @@ public class MIParser {
|
||||||
return rr;
|
return rr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
MIOOBRecord processMIOOBRecord(String buffer, int id) {
|
MIOOBRecord processMIOOBRecord(String buffer, int id) {
|
||||||
MIOOBRecord oob = null;
|
MIOOBRecord oob = null;
|
||||||
char c = buffer.charAt(0);
|
char c = buffer.charAt(0);
|
||||||
|
@ -180,6 +189,7 @@ public class MIParser {
|
||||||
if (i != -1) {
|
if (i != -1) {
|
||||||
String asyncClass = buffer.substring(1, i);
|
String asyncClass = buffer.substring(1, i);
|
||||||
async.setAsyncClass(asyncClass);
|
async.setAsyncClass(asyncClass);
|
||||||
|
// Consume the async-class and the comma
|
||||||
buffer = buffer.substring(i + 1);
|
buffer = buffer.substring(i + 1);
|
||||||
}
|
}
|
||||||
MIResult[] res = processMIResults(buffer);
|
MIResult[] res = processMIResults(buffer);
|
||||||
|
@ -200,13 +210,16 @@ public class MIParser {
|
||||||
stream = new MILogStreamOutput();
|
stream = new MILogStreamOutput();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
stream.setCString(translate (new StringBuffer(buffer.substring(1))));
|
stream.setCString(translateCString(buffer.substring(1)));
|
||||||
oob = stream;
|
oob = stream;
|
||||||
}
|
}
|
||||||
return oob;
|
return oob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assuming that the usual leading comma was consume.
|
||||||
|
*/
|
||||||
MIResult[] processMIResults(String buffer) {
|
MIResult[] processMIResults(String buffer) {
|
||||||
List aList = new ArrayList();
|
List aList = new ArrayList();
|
||||||
StringBuffer sb = new StringBuffer(buffer);
|
StringBuffer sb = new StringBuffer(buffer);
|
||||||
|
@ -251,9 +264,8 @@ public class MIParser {
|
||||||
sb.deleteCharAt(0);
|
sb.deleteCharAt(0);
|
||||||
value = processMIList(sb);
|
value = processMIList(sb);
|
||||||
} else if (sb.charAt(0) == '"') {
|
} else if (sb.charAt(0) == '"') {
|
||||||
sb.deleteCharAt(0);
|
|
||||||
MIConst cnst = new MIConst();
|
MIConst cnst = new MIConst();
|
||||||
cnst.setCString(translate(sb));
|
cnst.setCString(translateCString(sb));
|
||||||
value = cnst;
|
value = cnst;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
@ -279,13 +291,20 @@ public class MIParser {
|
||||||
return new MIList();
|
return new MIList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String translateCString(String str) {
|
||||||
|
return translateCString(new StringBuffer(str));
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: TODO
|
// FIXME: TODO
|
||||||
// FIXME: Side effect in the loop
|
// FIXME: Side effect in the loop
|
||||||
// FIXME: Deal with <repeat>
|
// FIXME: Deal with <repeat>
|
||||||
String translate(StringBuffer sb) {
|
String translateCString(StringBuffer sb) {
|
||||||
boolean escape = false;
|
boolean escape = false;
|
||||||
boolean quoteFound = false;
|
boolean termination = false;
|
||||||
for (int i = 0; i < sb.length() || quoteFound; i++) {
|
if (sb.charAt(0) == '"') {
|
||||||
|
sb.deleteCharAt(0);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < sb.length() || termination; i++) {
|
||||||
switch (sb.charAt(i)) {
|
switch (sb.charAt(i)) {
|
||||||
case '\\':
|
case '\\':
|
||||||
if (escape) {
|
if (escape) {
|
||||||
|
@ -318,7 +337,7 @@ public class MIParser {
|
||||||
sb.deleteCharAt(i - 1);
|
sb.deleteCharAt(i - 1);
|
||||||
escape = false;
|
escape = false;
|
||||||
} else {
|
} else {
|
||||||
quoteFound = true;
|
termination = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue