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 static final String terminator = "(gdb)\n";
|
||||
public static final String terminator = "(gdb)";
|
||||
public static final MIOOBRecord[] nullOOBRecord = new MIOOBRecord[0];
|
||||
MIResultRecord rr = null;
|
||||
MIOOBRecord[] oobs = null;
|
||||
|
|
|
@ -82,7 +82,11 @@ import java.util.StringTokenizer;
|
|||
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) {
|
||||
MIOutput mi = new MIOutput();
|
||||
|
@ -105,12 +109,15 @@ public class MIParser {
|
|||
id = Integer.parseInt(numbers);
|
||||
} catch(NumberFormatException e) {
|
||||
}
|
||||
// Consume the token.
|
||||
token = token.substring(i);
|
||||
}
|
||||
|
||||
// Process ResultRecord | Out-Of-Band Records
|
||||
if (token.charAt(0) == '^') {
|
||||
rr = processMIResultRecord(token.substring(1), id);
|
||||
//} else if(token.startsWith(MIOutput.terminator)) {
|
||||
// break;
|
||||
} else {
|
||||
MIOOBRecord band = processMIOOBRecord(token.substring(1), id);
|
||||
if (band != null) {
|
||||
|
@ -156,6 +163,8 @@ public class MIParser {
|
|||
return rr;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
MIOOBRecord processMIOOBRecord(String buffer, int id) {
|
||||
MIOOBRecord oob = null;
|
||||
char c = buffer.charAt(0);
|
||||
|
@ -180,6 +189,7 @@ public class MIParser {
|
|||
if (i != -1) {
|
||||
String asyncClass = buffer.substring(1, i);
|
||||
async.setAsyncClass(asyncClass);
|
||||
// Consume the async-class and the comma
|
||||
buffer = buffer.substring(i + 1);
|
||||
}
|
||||
MIResult[] res = processMIResults(buffer);
|
||||
|
@ -200,13 +210,16 @@ public class MIParser {
|
|||
stream = new MILogStreamOutput();
|
||||
break;
|
||||
}
|
||||
stream.setCString(translate (new StringBuffer(buffer.substring(1))));
|
||||
stream.setCString(translateCString(buffer.substring(1)));
|
||||
oob = stream;
|
||||
}
|
||||
return oob;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Assuming that the usual leading comma was consume.
|
||||
*/
|
||||
MIResult[] processMIResults(String buffer) {
|
||||
List aList = new ArrayList();
|
||||
StringBuffer sb = new StringBuffer(buffer);
|
||||
|
@ -251,9 +264,8 @@ public class MIParser {
|
|||
sb.deleteCharAt(0);
|
||||
value = processMIList(sb);
|
||||
} else if (sb.charAt(0) == '"') {
|
||||
sb.deleteCharAt(0);
|
||||
MIConst cnst = new MIConst();
|
||||
cnst.setCString(translate(sb));
|
||||
cnst.setCString(translateCString(sb));
|
||||
value = cnst;
|
||||
}
|
||||
return value;
|
||||
|
@ -279,13 +291,20 @@ public class MIParser {
|
|||
return new MIList();
|
||||
}
|
||||
|
||||
String translateCString(String str) {
|
||||
return translateCString(new StringBuffer(str));
|
||||
}
|
||||
|
||||
// FIXME: TODO
|
||||
// FIXME: Side effect in the loop
|
||||
// FIXME: Deal with <repeat>
|
||||
String translate(StringBuffer sb) {
|
||||
String translateCString(StringBuffer sb) {
|
||||
boolean escape = false;
|
||||
boolean quoteFound = false;
|
||||
for (int i = 0; i < sb.length() || quoteFound; i++) {
|
||||
boolean termination = false;
|
||||
if (sb.charAt(0) == '"') {
|
||||
sb.deleteCharAt(0);
|
||||
}
|
||||
for (int i = 0; i < sb.length() || termination; i++) {
|
||||
switch (sb.charAt(i)) {
|
||||
case '\\':
|
||||
if (escape) {
|
||||
|
@ -318,7 +337,7 @@ public class MIParser {
|
|||
sb.deleteCharAt(i - 1);
|
||||
escape = false;
|
||||
} else {
|
||||
quoteFound = true;
|
||||
termination = true;
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue