]> O.S.I.I.S - jp/crow.git/commitdiff
change style grammar for value, editor parser ok
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 27 Feb 2018 18:21:36 +0000 (19:21 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 27 Feb 2018 18:21:36 +0000 (19:21 +0100)
CrowIDE/src/SourceEditor/Parser.cs
CrowIDE/src/SourceEditor/StyleParser.cs

index f3dced9bd3a34bdcb2ee269aefae99cd38f64e40..f655fa490b8fb00a077494fc26025666c1c7c61b 100644 (file)
@@ -198,17 +198,6 @@ namespace Crow.Coding
                        currentTok = default(Token);
                }
                /// <summary>
-               /// Save current token into current TokensLine after having skipped white spaces and raz current token
-               /// </summary>
-               protected void saveAndResetAfterWhiteSpaceSkipping() {                  
-                       buffer[currentLine].Tokens.Add (currentTok);
-                       currentTok = default(Token);
-                       if (WpToken == null)
-                               return;
-                       buffer[currentLine].Tokens.Add ((Token)WpToken);
-                       WpToken = null;
-               }
-               /// <summary>
                /// read one char and add current token to current TokensLine, current token is reset
                /// </summary>
                /// <param name="type">Type of the token</param>
@@ -226,14 +215,6 @@ namespace Crow.Coding
                        saveAndResetCurrentTok ();
                }
                /// <summary>
-               /// Save current tok after having skipped white spaces
-               /// </summary>
-               /// <param name="type">set the type of the tok</param>
-               protected void saveAndResetAfterWhiteSpaceSkipping(System.Enum type) {
-                       currentTok.Type = (TokenType)type;
-                       saveAndResetAfterWhiteSpaceSkipping ();
-               }
-               /// <summary>
                /// Peek next char, emit '\n' if current column > buffer's line length
                /// Throw error if eof is true
                /// </summary>
@@ -302,30 +283,20 @@ namespace Crow.Coding
                        return tmp;
                }
                /// <summary>
-               /// skip white spaces, but not line break. Save spaces in a WhiteSpace token and dont
-               /// save it directely if currentTok is not null
+               /// skip white spaces, but not line break. Save spaces in a WhiteSpace token.
                /// </summary>
                protected void SkipWhiteSpaces () {
-                       if (WpToken != null)
-                               throw new ParsingException (this, "white space token already pending");
-                       Token wp = default(Token);
+                       if (currentTok.Type != TokenType.Unknown)
+                               throw new ParsingException (this, "current token should be reset to unknown (0) before skiping white spaces");
                        while (!eol) {
                                if (!char.IsWhiteSpace (Peek ())||Peek()=='\n')
                                        break;
-                               if (wp.Type == TokenType.Unknown)
-                                       wp.Start = CurrentPosition;
-                               wp += Read();
-                               wp.Type = TokenType.WhiteSpace;
+                               readToCurrTok (currentTok.Type == TokenType.Unknown);
+                               currentTok.Type = TokenType.WhiteSpace;
                        }
-                       if (wp.Type == TokenType.Unknown)
-                               return;
-                       wp.End = CurrentPosition;
-                       if (currentTok.Type == TokenType.Unknown)
-                               buffer [currentLine].Tokens.Add (wp);
-                       else
-                               WpToken = wp;
+                       if (currentTok.Type != TokenType.Unknown)
+                               saveAndResetCurrentTok ();
                }
-               protected object WpToken = null;
                #endregion
        }
 }
\ No newline at end of file
index e699695d78009f5846158c37ce29135bf43e0dc4..9952b2679bc71d0aefb3b49b4b503cb8cc2aa530 100644 (file)
@@ -9,7 +9,7 @@ namespace Crow.Coding
 {
        public class StyleParser : Parser
        {
-               enum States { init, classNames, members }
+               enum States { init, classNames, members, value, endOfStatement }
 
                public StyleParser (CodeBuffer _buffer) : base(_buffer)
                {
@@ -41,7 +41,6 @@ namespace Crow.Coding
                        Debug.WriteLine (string.Format("parsing line:{0}", currentLine));
                        CodeLine cl = buffer [currentLine];
                        cl.Tokens = new List<Token> ();
-                       WpToken = null;
 
                        //retrieve current parser state from previous line
                        if (currentLine > 0)
@@ -80,62 +79,68 @@ namespace Crow.Coding
                                        }
                                        break;
                                case ',':
-                                       if (currentTok.Type != TokenType.Identifier || curState == States.members )                                     
+                                       if (curState != States.init || curState != States.classNames )
                                                throw new ParsingException (this, "Unexpected char ','");
-                                       saveAndResetAfterWhiteSpaceSkipping (TokenType.Type);//save previous token as class
-                                       readToCurrTok (true);
-                                       saveAndResetCurrentTok (TokenType.UnaryOp);
+                                       readAndResetCurrentTok (TokenType.UnaryOp, true);
                                        curState = States.classNames;
                                        break;
                                case '{':
-                                       if (currentTok.Type != TokenType.Identifier || curState == States.members)
-                                               throw new ParsingException (this, "Unexpected char '}'");
-
-                                       saveAndResetAfterWhiteSpaceSkipping (TokenType.Type);//save previous token as class
-
-                                       readToCurrTok (true);
-                                       saveAndResetCurrentTok (TokenType.OpenBlock);
+                                       if (!(curState == States.init || curState == States.classNames))
+                                               throw new ParsingException (this, "Unexpected char '{'");
+                                       readAndResetCurrentTok (TokenType.OpenBlock, true);
                                        curState = States.members;
                                        break;
                                case '}':
                                        if (curState != States.members)
                                                throw new ParsingException (this, "Unexpected char '}'");
-                                       readToCurrTok (true);
-                                       saveAndResetCurrentTok (TokenType.CloseBlock);
+                                       readAndResetCurrentTok (TokenType.CloseBlock, true);
                                        curState = States.classNames;
                                        break;
                                case '=':
-                                       if (currentTok.Type != TokenType.Identifier)
+                                       if (curState == States.classNames)
                                                throw new ParsingException (this, "Unexpected char '='");
-
-                                       saveAndResetAfterWhiteSpaceSkipping ();//save previous token as propertyname
-
-                                       curState = States.members;
-
-                                       readToCurrTok (true);
-                                       saveAndResetCurrentTok (TokenType.Affectation);
-
-                                       SkipWhiteSpaces ();
-
-                                       currentTok+=ReadLineUntil(";");
+                                       readAndResetCurrentTok (TokenType.Affectation, true);
+                                       curState = States.value;
+                                       break;
+                               case '"':
+                                       if (curState != States.value)
+                                               throw new ParsingException (this, "Unexpected char '\"'");                                      
+                                       readAndResetCurrentTok (TokenType.StringLitteralOpening, true);
+
+                                       while (!eol) {
+                                               currentTok += ReadLineUntil ("\"");
+                                               if (currentTok.Content [currentTok.Content.Length - 1] == '\\')
+                                                       readToCurrTok ();
+                                               else
+                                                       break;
+                                       }
+                                       if (eol)
+                                               throw new ParsingException (this, "Unexpected end of line");
                                        saveAndResetCurrentTok (TokenType.StringLitteral);
 
-                                       if (Peek() != ';')
-                                               throw new ParsingException (this, "Expecting ';'");
-                                       readToCurrTok (true);
-                                       saveAndResetCurrentTok (TokenType.StatementEnding);
+                                       readAndResetCurrentTok (TokenType.StringLitteralClosing, true);
+                                       curState = States.endOfStatement;
+                                       break;
+                               case ';':
+                                       if (curState != States.endOfStatement)
+                                               throw new ParsingException (this, "Unexpected end of statement");                                       
+                                       readAndResetCurrentTok (TokenType.StatementEnding, true);
+                                       curState = States.members;
                                        break;
                                default:
                                        if (currentTok.Type != TokenType.Unknown)
-                                               throw new ParsingException (this, "error");
+                                               throw new ParsingException (this, "error curtok not null");
+                                       if (curState == States.value)
+                                               throw new ParsingException (this, "expecting value enclosed in '\"'");
+                                       if (curState == States.endOfStatement)
+                                               throw new ParsingException (this, "expecting end of statement");                                        
                                        
                                        if (nextCharIsValidCharStartName) {                                             
                                                readToCurrTok (true);
                                                while (nextCharIsValidCharName)
                                                        readToCurrTok ();
                                        }
-                                       currentTok.Type = TokenType.Identifier;
-                                       currentTok.End = CurrentPosition;
+                                       saveAndResetCurrentTok (TokenType.Identifier);
                                        break;
                                }
                        }