예제 #1
0
 public UstNode VisitLiteral([NotNull] ECMAScriptParser.LiteralContext context)
 {
     if (context.NullLiteral() != null)
     {
         return(new NullLiteral(context.GetTextSpan(), FileNode));
     }
     else if (context.BooleanLiteral() != null)
     {
         bool value;
         bool.TryParse(context.GetText(), out value);
         return(new BooleanLiteral(value, context.GetTextSpan(), FileNode));
     }
     else if (context.StringLiteral() != null)
     {
         string s = context.GetText();
         return(new StringLiteral(s.Substring(1, s.Length - 2), context.GetTextSpan(), FileNode));
     }
     else if (context.RegularExpressionLiteral() != null)
     {
         return(new StringLiteral(context.GetText(), context.GetTextSpan(), FileNode));
     }
     else
     {
         return(Visit(context.numericLiteral()));
     }
 }
 public override Node VisitLiteral(ECMAScriptParser.LiteralContext context)
 {
     if (context.RegularExpressionLiteral() != null)
     {
         throw new NotImplementedException(
                   GenerateErrorMessage(context, "regular expressions aren't supported."));
     }
     if (context.StringLiteral() != null)
     {
         return(new StringLiteral(context, context.StringLiteral().Symbol.Text));
     }
     if (context.BooleanLiteral() != null)
     {
         return(new BooleanLiteral(context, context.BooleanLiteral().Symbol.Text == "true"));
     }
     if (context.NullLiteral() != null)
     {
         return(new NullLiteral(context));
     }
     return(Visit(context.numericLiteral()));
 }