
from nodes import Node

class StringLiteral(Node):
    args = 0
    results = 1
    char = '"'

    def __init__(self, string):
        self.string = string

    @Node.test_func([], [""], "")
    @Node.test_func([], ["World"], "World\"")
    @Node.test_func([], ["Hello"], "Hello")
    def func(self):
        """String literal. Ends with " """
        return self.string

    def __repr__(self):
        return "%s: %r"%(self.__class__.__name__, self.string)
        
    @classmethod
    def accepts(cls, code, accept = False):
        if accept: code = '"'+code
        if code == "": return None, None
        if code[0] != StringLiteral.char:return None, None
        code = code[1:]
        string, sep, code = code.partition(StringLiteral.char)
        #if sep == "":
        #    code = "+"
        return code, cls(string)

from nodes import Node

class StringLiteral(Node):
    args = 0
    results = 1
    char = '"'

    def __init__(self, string):
        self.string = string

    @Node.test_func([], [""], "")
    @Node.test_func([], ["World"], "World\"")
    @Node.test_func([], ["Hello"], "Hello")
    def func(self):
        """String literal. Ends with " """
        return self.string

    def __repr__(self):
        return "%s: %r"%(self.__class__.__name__, self.string)
        
    @classmethod
    def accepts(cls, code, accept = False):
        if accept: code = '"'+code
        if code == "":
            return None, None
        if code[0] != StringLiteral.char:
            return None, None
        code = code[1:]
        rtn = ""
        end = False
        while code and not end:
            rtn += code[0]
            code = code[1:]
            if rtn.endswith('"'):
                if rtn.endswith(r'\"'):
                    continue
                end = True
                code = code[:-1]
        if rtn.endswith('"') and not rtn.endswith(r'\"'):
            rtn = rtn[:-1]
        rtn = rtn.replace(r'\"', '"')
        return code, cls(rtn)

Allow `"` to appear in string literals
Allow `"` to appear in string literals

  
  from nodes import Node
  
  class StringLiteral(Node):
      args = 0
      results = 1
      char = '"'
  
      def __init__(self, string):
          self.string = string
  
      @Node.test_func([], [""], "")
      @Node.test_func([], ["World"], "World\"")
      @Node.test_func([], ["Hello"], "Hello")
      def func(self):
          """String literal. Ends with " """
          return self.string
  
      def __repr__(self):
          return "%s: %r"%(self.__class__.__name__, self.string)
          
      @classmethod
      def accepts(cls, code, accept = False):
          if accept: code = '"'+code
+         if code == "":
-         if code == "": return None, None
+             return None, None
-         if code[0] != StringLiteral.char:return None, None
+         if code[0] != StringLiteral.char:
+             return None, None
          code = code[1:]
-         string, sep, code = code.partition(StringLiteral.char)
-         #if sep == "":
+         rtn = ""
+         end = False
+         while code and not end:
+             rtn += code[0]
-         #    code = "+"
+             code = code[1:]
+             if rtn.endswith('"'):
+                 if rtn.endswith(r'\"'):
+                     continue
+                 end = True
+                 code = code[:-1]
+         if rtn.endswith('"') and not rtn.endswith(r'\"'):
+             rtn = rtn[:-1]
+         rtn = rtn.replace(r'\"', '"')
-         return code, cls(string)
+         return code, cls(rtn)
+ 
Allow `"` to appear in string literals
## Code Before:

from nodes import Node

class StringLiteral(Node):
    args = 0
    results = 1
    char = '"'

    def __init__(self, string):
        self.string = string

    @Node.test_func([], [""], "")
    @Node.test_func([], ["World"], "World\"")
    @Node.test_func([], ["Hello"], "Hello")
    def func(self):
        """String literal. Ends with " """
        return self.string

    def __repr__(self):
        return "%s: %r"%(self.__class__.__name__, self.string)
        
    @classmethod
    def accepts(cls, code, accept = False):
        if accept: code = '"'+code
        if code == "": return None, None
        if code[0] != StringLiteral.char:return None, None
        code = code[1:]
        string, sep, code = code.partition(StringLiteral.char)
        #if sep == "":
        #    code = "+"
        return code, cls(string)
## Instruction:
Allow `"` to appear in string literals
## Code After:

from nodes import Node

class StringLiteral(Node):
    args = 0
    results = 1
    char = '"'

    def __init__(self, string):
        self.string = string

    @Node.test_func([], [""], "")
    @Node.test_func([], ["World"], "World\"")
    @Node.test_func([], ["Hello"], "Hello")
    def func(self):
        """String literal. Ends with " """
        return self.string

    def __repr__(self):
        return "%s: %r"%(self.__class__.__name__, self.string)
        
    @classmethod
    def accepts(cls, code, accept = False):
        if accept: code = '"'+code
        if code == "":
            return None, None
        if code[0] != StringLiteral.char:
            return None, None
        code = code[1:]
        rtn = ""
        end = False
        while code and not end:
            rtn += code[0]
            code = code[1:]
            if rtn.endswith('"'):
                if rtn.endswith(r'\"'):
                    continue
                end = True
                code = code[:-1]
        if rtn.endswith('"') and not rtn.endswith(r'\"'):
            rtn = rtn[:-1]
        rtn = rtn.replace(r'\"', '"')
        return code, cls(rtn)
