public PonyTextParagraphStruct(PonyToken token) : base(StructureType.ParagraphStruct, token) { structureBases = new List <PonyTextStructureBase>(); if (!string.IsNullOrEmpty(token.Text)) { structureBases.Add(new PonyTextLiteralStruct(token)); } }
public void TryStartParagraph(PonyToken token) { if (currentContext.StructureType == StructureType.ParagraphStruct) { if (token != null && !string.IsNullOrEmpty(token.Text)) { AddLiteral(token); } } else { setContext(new PonyTextParagraphStruct(token)); } }
private void parseNext(PonyToken token) { int colSelector = getTokenMapping(token); if (colSelector == -1) { tokenGenerator.HaltGenerator(); errorListener.OnParserErrorReported("Unrecognized Token", currentState, token.ToString()); return; } int nextState = transitionTable[currentState, colSelector]; if (nextState == -1) { tokenGenerator.HaltGenerator(); errorListener.OnParserErrorReported("Invalid Transition", currentState, token.ToString()); return; } buildTextStruct(nextState, token); currentState = nextState; }
public PonyTextDirective(PonyToken token) : base(StructureType.DirectiveStruct, token) { arguments = new List <PonyTextStructureBase>(); name = token.Text; }
public void AddLiteral(PonyToken token) { addToContext(new PonyTextLiteralStruct(token)); }
protected PonyTextStructureBase(StructureType structureType, PonyToken token) { StructureType = structureType; this.AssociatedToken = token; }
public PonyTextMapStruct(PonyToken token) : base(StructureType.MapStruct, token) { map = new Dictionary <string, PonyTextStructureBase>(); }
public PonyTextMarcoStruct(PonyToken token) : base(StructureType.MarcoStruct, token) { MarcoName = token.Text; formatArgs = new List <PonyTextStructureBase>(); }
public PonyTextNumStruct(PonyToken token) : base(StructureType.NumberStruct, token) { num = decimal.Parse(token.Text); }
public void AddLiteralMapping(string key, PonyToken token) { addToMappingContext(key, new PonyTextLiteralStruct(token)); }
public void StartMappingStruct(PonyToken token) { setContext(new PonyTextMapStruct(token)); }
public void StartDirective(PonyToken token) { setContext(new PonyTextDirective(token)); }
public void StartTextStructure(PonyToken token) { setContext(new PonyTextStruct(token)); }
public void AddMarco(PonyToken token) { addToContext(new PonyTextMarcoStruct(token)); }
public void AddNumber(PonyToken token) { addToContext(new PonyTextNumStruct(token)); }
public PonyTextStruct(PonyToken token) : base(StructureType.PTextStruct, token) { structs = new List <PonyTextStructureBase>(); }
public PonyTextDirectivesBlock(PonyToken token) : base(StructureType.DirectiveBlockStruct, token) { textDirectives = new List <PonyTextDirective>(); }
public void AddNumMapping(string key, PonyToken token) { addToMappingContext(key, new PonyTextNumStruct(token)); }
public void WriteToken(PonyToken token) { buffer.Enqueue(token); }
public void AddMarcoMapping(string key, PonyToken token) { addToMappingContext(key, new PonyTextMarcoStruct(token)); }
public void StartFormatableMarcoStruct(PonyToken token) { setContext(new PonyTextMarcoStruct(token)); }
public static PreProcessTrace CreateTraceTokenLevel(PonyToken token) { return(new PreProcessTrace(token)); }
private void Lexer_onTokenGenerated(PonyToken token) { Console.WriteLine(token); }
public PreProcessTrace(PonyToken erroneousToken, string erroneousFilename) { this.erroneousToken = erroneousToken; this.erroneousFilename = erroneousFilename; }
//L $ @ { [ ] } % : ID Q LF NUM ( ) //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 private int getTokenMapping(PonyToken token) { PonyTokenType tokenType = token.TokenType; PonyTokenType examedToken; switch (tokenType) { case PonyTokenType.LITERAL: return(0); case PonyTokenType.LBRACE: builder.StartMappingStruct(token); context.Push(tokenType); return(3); case PonyTokenType.RBRACE: if (!context.TryPop(out examedToken) || examedToken != PonyTokenType.LBRACE) { return(-1); } builder.EndCurrentContext(); return(6); case PonyTokenType.LBRACKET: context.Push(tokenType); return(4); case PonyTokenType.RBRACKET: if (!context.TryPop(out examedToken) || examedToken != PonyTokenType.LBRACKET) { return(-1); } if (!context.TryPop(out examedToken) || examedToken != PonyTokenType.DOLLAR) { return(-1); } builder.EndCurrentContext(); return(5); case PonyTokenType.LPAREN: context.Push(tokenType); return(13); case PonyTokenType.RPAREN: if (!context.TryPop(out examedToken) || examedToken != PonyTokenType.LPAREN) { return(-1); } builder.EndCurrentContext(); return(14); case PonyTokenType.AT: return(2); case PonyTokenType.ID: return(9); case PonyTokenType.CRLF: if (currentState == 3 && currentState == 5) { if (!context.TryPeek(out examedToken) || examedToken != PonyTokenType.DOLLAR) { return(-1); } } return(11); case PonyTokenType.QUOTE: return(10); case PonyTokenType.COLON: return(8); case PonyTokenType.DOLLAR: if (currentState == 4) { if (!context.TryPop(out examedToken) || examedToken != PonyTokenType.DOLLAR) { return(-1); } builder.EndCurrentContext(); return(1); } context.Push(tokenType); return(1); case PonyTokenType.PERCENTAGE: if (currentState == 0 || currentState == 10) { if (!context.TryPop(out examedToken) || examedToken != PonyTokenType.PERCENTAGE) { return(-1); } builder.EndCurrentContext(); if (currentState == 10) { // if we transit from 10. then the prev end ctx is only // end the paragraph struct. But the TextStruct ctx not ended. // so we need end for one more time thus to ensure we leave the TextStruct completely. builder.EndCurrentContext(); } return(7); } builder.StartTextStructure(token); context.Push(tokenType); return(7); case PonyTokenType.NUMBER: return(12); default: return(-1); } }
public PreProcessTrace(PonyToken erroneousToken) { this.erroneousToken = erroneousToken; }
private void buildTextStruct(int nextState, PonyToken token) { if (currentState == 10 && currentState == nextState) { builder.AddLiteral(token); } else if (currentState == 0 && nextState == 10) { builder.TryStartParagraph(token); } else if (nextState == 5) { builder.StartFormatableMarcoStruct(token); } else if (currentState == 1 && nextState == 2) { builder.TryStartParagraph(token.DeriveEmptyToken()); } else if (currentState == 6 && nextState == 3) { builder.StartDirective(token); } else if (currentState == 1 && nextState == 4) { builder.StartDirectiveBlock(token.DeriveEmptyToken()); } else if (nextState == 8) { tokenAsKey = token.Text.Trim('"'); } else if (currentState == 9 && nextState == 7) { if (token.TokenType == PonyTokenType.ID) { builder.AddMarcoMapping(tokenAsKey, token); } else if (token.TokenType == PonyTokenType.NUMBER) { builder.AddNumMapping(tokenAsKey, token); } else if (token.TokenType == PonyTokenType.QUOTE) { builder.AddLiteralMapping(tokenAsKey, token); } } else if ((currentState == 5 || currentState == 3) && nextState == 4) { builder.EndCurrentContext(); } else if (currentState == 10 && nextState == 0) { builder.EndCurrentContext(); } else if (currentState == 3) { if (token.TokenType == PonyTokenType.ID) { builder.AddMarco(token); } else if (token.TokenType == PonyTokenType.NUMBER) { builder.AddNumber(token); } else if (token.TokenType == PonyTokenType.LITERAL) { builder.AddLiteral(token); } else if (token.TokenType == PonyTokenType.QUOTE) { builder.AddLiteral(token); } } }
public PonyTextLiteralStruct(PonyToken token) : base(StructureType.LiteralStruct, token) { content = token.Text.Trim('"'); }