public static string Parse(Afx.Lexer lexer) { char openingQuoteSign; char closingQuoteSign; var contents = new StringBuilder(); var willBeEscaped = false; if (lexer.IsSingleQuote() || lexer.IsDoubleQuote()) { openingQuoteSign = lexer.Consume(); } else { throw new AfxException("Unquoted String literal"); } while (true) { if (lexer.IsEnd()) { throw new AfxException($"Unfinished string literal \"{contents.ToString()}\""); } if (lexer.IsBackSlash() && !willBeEscaped) { willBeEscaped = true; lexer.Consume(); continue; } if (lexer.IsSingleQuote() || lexer.IsDoubleQuote()) { closingQuoteSign = lexer.Consume(); if (!willBeEscaped && openingQuoteSign == closingQuoteSign) { return(contents.ToString()); } contents.Append(closingQuoteSign); willBeEscaped = false; continue; } contents.Append(lexer.Consume()); willBeEscaped = false; } }
public static PropParsingResult Parse(Afx.Lexer lexer) { var identifier = Identifier.Parse(lexer); if (lexer.IsEqualSign()) { lexer.Consume(); if (lexer.IsSingleQuote() || lexer.IsDoubleQuote()) { return(new PropParsingResult() { Type = AstNodeType.String, Payload = StringLiteral.Parse(lexer), Identifier = identifier }); } if (lexer.IsOpeningBrace()) { return(new PropParsingResult() { Type = AstNodeType.Expression, Payload = Expression.Parse(lexer), Identifier = identifier }); } throw new AfxException($"Prop-Assignment \"{identifier}\" was not followed by quotes or braces"); } else if (lexer.IsWhiteSpace() || lexer.IsForwardSlash() || lexer.IsClosingBracket()) { return(new PropParsingResult() { Type = AstNodeType.Boolean, Payload = true, Identifier = identifier }); } else { throw new AfxException($"Prop identifier \"{identifier}\" is neither assignment nor boolean"); } }