Exemplo n.º 1
0
        public PonyTextParagraphStruct(PonyToken token) : base(StructureType.ParagraphStruct, token)
        {
            structureBases = new List <PonyTextStructureBase>();

            if (!string.IsNullOrEmpty(token.Text))
            {
                structureBases.Add(new PonyTextLiteralStruct(token));
            }
        }
Exemplo n.º 2
0
 public void TryStartParagraph(PonyToken token)
 {
     if (currentContext.StructureType == StructureType.ParagraphStruct)
     {
         if (token != null && !string.IsNullOrEmpty(token.Text))
         {
             AddLiteral(token);
         }
     }
     else
     {
         setContext(new PonyTextParagraphStruct(token));
     }
 }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
 public PonyTextDirective(PonyToken token) : base(StructureType.DirectiveStruct, token)
 {
     arguments = new List <PonyTextStructureBase>();
     name      = token.Text;
 }
Exemplo n.º 5
0
 public void AddLiteral(PonyToken token)
 {
     addToContext(new PonyTextLiteralStruct(token));
 }
Exemplo n.º 6
0
 protected PonyTextStructureBase(StructureType structureType, PonyToken token)
 {
     StructureType        = structureType;
     this.AssociatedToken = token;
 }
Exemplo n.º 7
0
 public PonyTextMapStruct(PonyToken token) : base(StructureType.MapStruct, token)
 {
     map = new Dictionary <string, PonyTextStructureBase>();
 }
Exemplo n.º 8
0
 public PonyTextMarcoStruct(PonyToken token) : base(StructureType.MarcoStruct, token)
 {
     MarcoName  = token.Text;
     formatArgs = new List <PonyTextStructureBase>();
 }
Exemplo n.º 9
0
 public PonyTextNumStruct(PonyToken token) : base(StructureType.NumberStruct, token)
 {
     num = decimal.Parse(token.Text);
 }
Exemplo n.º 10
0
 public void AddLiteralMapping(string key, PonyToken token)
 {
     addToMappingContext(key, new PonyTextLiteralStruct(token));
 }
Exemplo n.º 11
0
 public void StartMappingStruct(PonyToken token)
 {
     setContext(new PonyTextMapStruct(token));
 }
Exemplo n.º 12
0
 public void StartDirective(PonyToken token)
 {
     setContext(new PonyTextDirective(token));
 }
Exemplo n.º 13
0
 public void StartTextStructure(PonyToken token)
 {
     setContext(new PonyTextStruct(token));
 }
Exemplo n.º 14
0
 public void AddMarco(PonyToken token)
 {
     addToContext(new PonyTextMarcoStruct(token));
 }
Exemplo n.º 15
0
 public void AddNumber(PonyToken token)
 {
     addToContext(new PonyTextNumStruct(token));
 }
Exemplo n.º 16
0
 public PonyTextStruct(PonyToken token) : base(StructureType.PTextStruct, token)
 {
     structs = new List <PonyTextStructureBase>();
 }
Exemplo n.º 17
0
 public PonyTextDirectivesBlock(PonyToken token) : base(StructureType.DirectiveBlockStruct, token)
 {
     textDirectives = new List <PonyTextDirective>();
 }
Exemplo n.º 18
0
 public void AddNumMapping(string key, PonyToken token)
 {
     addToMappingContext(key, new PonyTextNumStruct(token));
 }
Exemplo n.º 19
0
 public void WriteToken(PonyToken token)
 {
     buffer.Enqueue(token);
 }
Exemplo n.º 20
0
 public void AddMarcoMapping(string key, PonyToken token)
 {
     addToMappingContext(key, new PonyTextMarcoStruct(token));
 }
Exemplo n.º 21
0
 public void StartFormatableMarcoStruct(PonyToken token)
 {
     setContext(new PonyTextMarcoStruct(token));
 }
Exemplo n.º 22
0
 public static PreProcessTrace CreateTraceTokenLevel(PonyToken token)
 {
     return(new PreProcessTrace(token));
 }
Exemplo n.º 23
0
 private void Lexer_onTokenGenerated(PonyToken token)
 {
     Console.WriteLine(token);
 }
Exemplo n.º 24
0
 public PreProcessTrace(PonyToken erroneousToken, string erroneousFilename)
 {
     this.erroneousToken    = erroneousToken;
     this.erroneousFilename = erroneousFilename;
 }
Exemplo n.º 25
0
        //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);
            }
        }
Exemplo n.º 26
0
 public PreProcessTrace(PonyToken erroneousToken)
 {
     this.erroneousToken = erroneousToken;
 }
Exemplo n.º 27
0
 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);
         }
     }
 }
Exemplo n.º 28
0
 public PonyTextLiteralStruct(PonyToken token) : base(StructureType.LiteralStruct, token)
 {
     content = token.Text.Trim('"');
 }