static void CopySourcePart (Position pos, int indent) { // Copy text described by pos from atg to gen int ch, nChars, i; if (pos != null) { Buffer.Pos = pos.beg; ch = Buffer.Read(); nChars = pos.len - 1; // CHANGES BY M.KRUEGER (#line pragma generation) gen.WriteLine(); gen.WriteLine(String.Format("#line {0} \"{1}\" ", Buffer.CountLines(pos.beg) + 1, Buffer.fileName)); // EOC Indent(indent); while (nChars >= 0) { while (ch == CR || ch == LF) { // eol is either CR or CRLF or LF gen.WriteLine(); Indent(indent); if (ch == CR) { ch = Buffer.Read(); nChars--; } // skip CR if (ch == LF) { ch = Buffer.Read(); nChars--; } // skip LF for (i = 1; i <= pos.col && ch <= ' '; i++) { // skip blanks at beginning of line ch = Buffer.Read(); nChars--; } if (i <= pos.col) pos.col = i - 1; // heading TABs => not enough blanks if (nChars < 0) goto done; } gen.Write((char)ch); ch = Buffer.Read(); nChars--; } done: if (indent > 0) gen.WriteLine(); } }
public ParserGen(Parser parser) { tab = parser.tab; errors = parser.errors; trace = parser.trace; buffer = parser.scanner.buffer; errorNr = -1; usingPos = null; }
protected void CopySourcePart(Position pos, int indent) { if (tab.lineDirectives && pos != null && pos.lineNumber > 0) { if (indent == 0) gen.WriteLine(); gen.WriteLine("#line " + pos.lineNumber + " " + Path.GetFileName(tab.srcName)); } tab.CopySourcePart(gen, pos, indent); if (tab.lineDirectives && pos != null && pos.lineNumber > 0) { if (indent == 0) gen.WriteLine(); else gen.Write(new string('\t', indent)); gen.WriteLine("#line default"); } }
void CopySourcePart (Position pos, int indent) { // Copy text described by pos from atg to gen int ch, i; if (pos != null) { buffer.Pos = pos.beg; ch = buffer.Read(); Indent(indent); while (buffer.Pos <= pos.end) { while (ch == CR || ch == LF) { // eol is either CR or CRLF or LF gen.WriteLine(); Indent(indent); if (ch == CR) ch = buffer.Read(); // skip CR if (ch == LF) ch = buffer.Read(); // skip LF for (i = 1; i <= pos.col && (ch == ' ' || ch == '\t'); i++) { // skip blanks at beginning of line ch = buffer.Read(); } if (i <= pos.col) pos.col = i - 1; // heading TABs => not enough blanks if (buffer.Pos > pos.end) goto done; } gen.Write((char)ch); ch = buffer.Read(); } done: if (indent > 0) gen.WriteLine(); } }
void Resolver( #line 398 "Coco.atg" //SOURCE beg=18206,len=16,col=10 out Position pos #line default //END SOURCE ) { Expect(38); Expect(31); #line 399 "Coco.atg" //SOURCE beg=18267,len=36,col=37 int beg = la.pos; int col = la.col; #line default //END SOURCE Condition(); #line 400 "Coco.atg" //SOURCE beg=18343,len=79,col=37 pos = new Position(beg, t.pos - beg, col, GetVirtualFile(), GetVirtualLine()); #line default //END SOURCE }
void SemText( #line 494 "Coco.atg" //SOURCE beg=22445,len=16,col=9 out Position pos #line default //END SOURCE ) { Expect(40); #line 495 "Coco.atg" //SOURCE beg=22502,len=66,col=36 int beg = la.pos; int col = la.col; int vline = GetVirtualLine(); #line default //END SOURCE while (StartOf(13)) { if (StartOf(14)) { Get(); } else if (la.kind == _badString) { Get(); #line 497 "Coco.atg" //SOURCE beg=22616,len=41,col=36 SemErr("bad string in semantic action"); #line default //END SOURCE } else { Get(); #line 498 "Coco.atg" //SOURCE beg=22696,len=51,col=36 SemErr("missing end of previous semantic action"); #line default //END SOURCE } } Expect(41); #line 500 "Coco.atg" //SOURCE beg=22791,len=68,col=36 pos = new Position(beg, t.pos - beg, col, GetVirtualFile(), vline); #line default //END SOURCE }
void SemText(out Position pos) { Expect(39); int beg = la.pos; int col = la.col; while (StartOf(13)) { if (StartOf(14)) { Get(); } else if (la.kind == 4) { Get(); SemErr("bad string in semantic action"); } else { Get(); SemErr("missing end of previous semantic action"); } } Expect(40); pos = new Position(beg, t.pos - beg, col); }
void Resolver(out Position pos) { Expect(37); Expect(30); int beg = la.pos; int col = la.col; Condition(); pos = new Position(beg, t.pos, col); }
public static void Init (string file, string dir) { srcName = file; srcDir = dir; errorNr = -1; usingPos = null; }
void Resolver(out Position pos) { Expect(44); Expect(37); int beg = la.pos; int col = la.col; int line = la.line; Condition(); pos = new Position(beg, t.pos, col, line); }
string GetSource(Position pos) { StringWriter w = new StringWriter(); tab.CopySourcePart(w, pos, 0); return w.ToString(); }
bool IsNamedFirstSet(Position pos) { return GetSource(pos).StartsWith(namedFirstSetMarker, StringComparison.Ordinal); }
public void CopySourcePart(TextWriter dest, Position pos, int indent) { // Copy text described by pos from atg to dest if (pos != null) { int ch, i; buffer.Pos = pos.beg; ch = buffer.Read(); // skip lead whitespace - only arises in some circumstances, // such as when surrounding tokens are used to define the content. while ( buffer.Pos <= pos.end && (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n') ) { ch = buffer.Read(); } // track if the line might need indenting (eg, after a newline) bool mightIndent = true; while (buffer.Pos <= pos.end) { // eol is either CR or CRLF or LF while (ch == CR || ch == LF) { dest.WriteLine(); mightIndent = true; if (ch == CR) ch = buffer.Read(); // skip CR if (ch == LF) ch = buffer.Read(); // skip LF for (i = 1; i <= pos.col && (ch == ' ' || ch == '\t'); i++) { // skip blanks at beginning of line ch = buffer.Read(); } if (i <= pos.col) pos.col = i - 1; // heading TABs => not enough blanks if (buffer.Pos > pos.end) goto Done; } if (buffer.Pos == pos.end && ch == ' ') { // disallow extra trailing blank that would otherwise // sneak in with this common construction: // (. code .) vs. the less readable (.code.) } else { if (mightIndent) { for (int t=0; t < indent; ++t) dest.Write('\t'); mightIndent = false; } dest.Write((char)ch); } ch = buffer.Read(); } Done: if (indent > 0) dest.WriteLine(); } }
void ParseResolver(out Position pos) { Expect(39); Expect(32); int beg = la.pos; int col = la.col; ParseCondition(); pos = new Position(beg, t.pos, col); }
void UsingDecl(out Position pos) { Expect(41); int beg = t.pos; while (StartOf(4)) { Get(); } Expect(42); int end = t.pos; while (la.kind == 41) { Get(); while (StartOf(4)) { Get(); } Expect(42); end = t.pos; } pos = new Position(beg, end - beg + 1, 0); }
string Pos(Position pos) { if (pos == null) return " "; else return String.Format("{0,5}", pos.beg); }
void CopySourcePart(Position pos, int indent) { // Copy text described by pos from atg to gen int ch, i; if (pos != null) { buffer.Pos = pos.beg; ch = buffer.Read(); if (tab.emitLines) { gen.WriteLine(); gen.WriteLine("#line {0} \"{1}\"", pos.line, tab.srcName); } Indent(indent); while (buffer.Pos <= pos.end) { while (ch == CR || ch == LF) { // eol is either CR or CRLF or LF gen.WriteLine(); Indent(indent); if (ch == CR) ch = buffer.Read(); // skip CR if (ch == LF) ch = buffer.Read(); // skip LF for (i = 1; i <= pos.col && (ch == ' ' || ch == '\t'); i++) { // skip blanks at beginning of line ch = buffer.Read(); } if (buffer.Pos > pos.end) goto done; } gen.Write((char)ch); ch = buffer.Read(); } done: if (indent > 0) gen.WriteLine(); } }
void ExpectedConflict(out Position pos, out List<Symbol> conflictSymbols) { Symbol sym; conflictSymbols = new List<Symbol>(); Expect(45); Expect(37); int beg = la.pos; int col = la.col; int line = la.line; ConflictSymbol(out sym); if (sym != null) conflictSymbols.Add(sym); while (la.kind == 46) { Get(); ConflictSymbol(out sym); if (sym != null) conflictSymbols.Add(sym); } Expect(38); pos = new Position(beg, t.pos, col, line); }
void CopySourcePart (Position pos, int indent) { // Copy text described by pos from atg to gen if (DirectDebug) { //-- PxCoco: Added #line directives and some gen.WriteLine's //-- PxCoco: ident is being ignored in favor of the original indention for error mapping int nChars; if (pos != null) { buffer.Pos = pos.beg; nChars = pos.len - 1; if (nChars >= 0) { gen.WriteLine("\n#line {0} \"{1}\" //SOURCE beg={2},len={3},col={4}", pos.virtualLine, pos.virtualFile == null ? "~grammar file~" : pos.virtualFile, pos.beg, pos.len, pos.col); indent = pos.col; Indent(indent); //just copy while (nChars-- >= 0) gen.Write((char)buffer.Read()); gen.WriteLine("\n#line default //END SOURCE"); } //End If: No chars in source } //End If: pos exists } else { // Copy text described by pos from atg to gen int ch, nChars, i; if (pos != null) { buffer.Pos = pos.beg; ch = buffer.Read(); nChars = pos.len - 1; Indent(indent); if(nChars >= 0) gen.Write("/*{1}:{0}*/", pos.virtualLine, pos.virtualFile == null ? "~grammar~" : System.IO.Path.GetFileName(pos.virtualFile)); while (nChars >= 0) { while (ch == CR || ch == LF) { // eol is either CR or CRLF or LF gen.WriteLine(); Indent(indent); if (ch == CR) { ch = buffer.Read(); nChars--; } // skip CR if (ch == LF) { ch = buffer.Read(); nChars--; } // skip LF for (i = 1; i <= pos.col && (ch == ' ' || ch == '\t'); i++) { // skip blanks at beginning of line ch = buffer.Read(); nChars--; } if (i <= pos.col) pos.col = i - 1; // heading TABs => not enough blanks if (nChars < 0) goto done; } gen.Write((char)ch); ch = buffer.Read(); nChars--; } done: if (indent > 0) gen.WriteLine(); } } }
void SemText(out Position pos) { Expect(48); int beg = la.pos; int col = la.col; int line = la.line; while (StartOf(15)) { if (StartOf(16)) { Get(); } else if (la.kind == 4) { Get(); SemErr("bad string in semantic action"); } else { Get(); SemErr("missing end of previous semantic action"); } } Expect(49); pos = new Position(beg, t.pos, col, line); }
static void ResolveExpr(out Position pos) { Expect(35); Expect(28); int beg = la.pos; int col = la.col; if (la.kind == 8 || la.kind == 36) { if (la.kind == 8) { Get(); } else { Get(); } CondPart(); } else if (la.kind == 28) { Get(); CondPart(); Expect(29); } else if (StartOf(21)) { Get(); CondPart(); } else SynErr(52); pos = new Position(beg, t.pos - beg, col); }
void CopySourcePart(Position pos, int indent) { tab.CopySourcePart(gen, pos, indent); }
public ParserOutput(Tab tab, Errors errors, TextWriter trace, Buffer buffer, Position uspos) { this.tab = tab; this.errors = errors; this.trace = trace; this.buffer = buffer; this.usingPos = uspos; errorNr = -1; }