title: Backslash conflict in Words and linebreak in Pyparsing
body: <p>I'm having a hard time with a grammar that allows '\' in the parameter names (ex. net\&lt;8>). However, '\' also serves as a continuation line (see Ex2.). Ex1 works fine, but there's a conflict between the <em>linebreak</em> and <em>identifier</em> variables. </p>
  
  <h3>Ex1: working (netlist.sp)</h3>
  
  <pre><code>subckt INVERTER A Z gnd gnds vdd vdds
  M1 (Z A vdd vdds) pmos w=0.4 l=0.1
  M2 (Z A gnd gnds) nmos w=0.2 l=0.1
  ends INVERTER
  
  I1 (net1 net2 0 gnds! vdd! vdds!) INVERTER
  
  subckt INVERTER_2 A Z gnd gnds vdd vdds
  M1 (Z A vdd vdds) pmos w=0.4 l=0.1
  M2 (Z A gnd gnds) nmos w=0.2 l=0.1
  ends INVERTER_2
  
  I2 (net\&lt;8\&gt; net2 0 gnds! vdd! vdds!) INVERTER_2
  
  I3 (net1 net2 0 gnds! vdd! vdds!) INVERTER_2
  </code></pre>
  
  <h3>Ex2: not working (netlist2.sp)</h3>
  
  <pre><code>subckt INVERTER A Z gnd gnds vdd vdds
  M1 (Z A vdd vdds) pmos w=0.4 l=0.1
  M2 (Z A gnd gnds) nmos w=0.2 l=0.1
  ends INVERTER
  
  I1 (net1 net2 0 gnds! vdd! vdds!) INVERTER
  
  subckt INVERTER_2 A Z gnd gnds \
                    vdd vdds
  M1 (Z A vdd vdds) pmos w=0.4 l=0.1
  M2 (Z A gnd gnds) nmos w=0.2 l=0.1
  ends INVERTER_2
  
  I2 (net\&lt;8\&gt; net2 0 gnds! vdd! vdds!) INVERTER_2
  
  I3 (net1 net2 0 gnds! vdd! vdds!) INVERTER_2
  </code></pre>
  
  <h3>The code</h3>
  
  <pre><code>import pyparsing as pp
  import json
  
  EOL = pp.LineEnd().suppress() # end of line
  linebreak = pp.Suppress(pp.Keyword('\\') + pp.LineEnd())
  identifier = pp.Word(pp.alphanums + '_!&lt;&gt;\\')
  number = pp.pyparsing_common.number
  net = identifier
  instref = identifier
  instname = identifier
  subcktname = identifier
  subcktname_end = pp.Keyword("ends").suppress()
  comment = pp.Suppress("//" + pp.SkipTo(pp.LineEnd()))
  expression = pp.Word(pp.alphanums + '._*+-/()')
  
  input_file = open(netlist.sp,'r')
  file_string = input_file.read()
  input_file.close()
  
  for t, s, e in parse_netlist().scanString(file_string):
      print(json.dumps(t.asDict()['netlist'], indent=2))
  
  def parse_netlist():
          pp.ParserElement.setDefaultWhitespaceChars(' \t')
  
          nets = (pp.Optional(pp.Suppress('('))
                  + pp.OneOrMore(net('net') | linebreak)
                  + pp.Optional(pp.Suppress(')'))
                 )
  
          inst_param_value = expression('expression')
  
          inst_parameter = pp.Dict(pp.Group(identifier('param_name')
                                    + pp.Suppress("=")
                                    + inst_param_value('param_value')
                                   ))
  
          parameters = pp.Group(pp.OneOrMore(inst_parameter | linebreak)
                               ).setResultsName('parameters')
  
          instance = pp.Dict(pp.Group(instname('inst_name')
                              + nets('nets')
                              + instref('reference')
                              + pp.Optional(parameters)
                              + EOL
                             )).setResultsName('instance', listAllMatches=True)
  
          subckt_core = pp.Group(pp.ZeroOrMore(instance | EOL | comment)
                                ).setResultsName('subckt_core', listAllMatches=True)
  
          subckt = pp.Group(pp.Keyword("subckt").suppress()
                            + subcktname('subckt_name')
                            + nets('nets')
                            + EOL
                            + subckt_core
                            + subcktname_end
                            + pp.matchPreviousExpr(subcktname).suppress()
                            + EOL
                           ).setResultsName('subcircuit', listAllMatches=True)
  
          netlist = pp.OneOrMore(subckt
                                 | instance
                                 | comment('comment')
                                 | EOL
                                ).setResultsName('netlist') + pp.StringEnd()
  
          return netlist
  </code></pre>
  
  <h3>Output of Ex1</h3>
  
  <pre><code>[
    {
      "subckt_name": "INVERTER",
      "net": "vdds",
      "nets": [
        "A",
        "Z",
        "gnd",
        "gnds",
        "vdd",
        "vdds"
      ],
      "subckt_core": [
        {
          "instance": [
            {
              "M1": {
                "inst_name": "M1",
                "net": "vdds",
                "nets": [
                  "Z",
                  "A",
                  "vdd",
                  "vdds"
                ],
                "reference": "pmos",
                "parameters": {
                  "w": "0.4",
                  "l": "0.1"
                }
              }
            },
            {
              "M2": {
                "inst_name": "M2",
                "net": "gnds",
                "nets": [
                  "Z",
                  "A",
                  "gnd",
                  "gnds"
                ],
                "reference": "nmos",
                "parameters": {
                  "w": "0.2",
                  "l": "0.1"
                }
              }
            }
          ]
        }
      ]
    },
    {
      "I1": {
        "inst_name": "I1",
        "net": "vdds!",
        "nets": [
          "net1",
          "net2",
          "0",
          "gnds!",
          "vdd!",
          "vdds!"
        ],
        "reference": "INVERTER",
        "parameters": []
      }
    },
    {
      "subckt_name": "INVERTER_2",
      "net": "vdds",
      "nets": [
        "A",
        "Z",
        "gnd",
        "gnds",
        "vdd",
        "vdds"
      ],
      "subckt_core": [
        {
          "instance": [
            {
              "M1": {
                "inst_name": "M1",
                "net": "vdds",
                "nets": [
                  "Z",
                  "A",
                  "vdd",
                  "vdds"
                ],
                "reference": "pmos",
                "parameters": {
                  "w": "0.4",
                  "l": "0.1"
                }
              }
            },
            {
              "M2": {
                "inst_name": "M2",
                "net": "gnds",
                "nets": [
                  "Z",
                  "A",
                  "gnd",
                  "gnds"
                ],
                "reference": "nmos",
                "parameters": {
                  "w": "0.2",
                  "l": "0.1"
                }
              }
            }
          ]
        }
      ]
    },
    {
      "I2": {
        "inst_name": "I2",
        "net": "vdds!",
        "nets": [
          "net\\&lt;8\\&gt;",
          "net2",
          "0",
          "gnds!",
          "vdd!",
          "vdds!"
        ],
        "reference": "INVERTER_2",
        "parameters": []
      }
    },
    {
      "I3": {
        "inst_name": "I3",
        "net": "vdds!",
        "nets": [
          "net1",
          "net2",
          "0",
          "gnds!",
          "vdd!",
          "vdds!"
        ],
        "reference": "INVERTER_2",
        "parameters": []
      }
    }
  ]
  </code></pre>
  
  <h3>Output of Ex2</h3>
  
  <pre><code>[
    {
      "I2": {
        "inst_name": "I2",
        "net": "vdds!",
        "nets": [
          "INST_IN\\&lt;8\\&gt;",
          "net2",
          "0",
          "gnds!",
          "vdd!",
          "vdds!"
        ],
        "reference": "INVERTER2",
        "parameters": []
      }
    },
    {
      "I3": {
        "inst_name": "I3",
        "net": "vdds!",
        "nets": [
          "net1",
          "net2",
          "0",
          "gnds!",
          "vdd!",
          "vdds!"
        ],
        "reference": "INVERTER3",
        "parameters": []
      }
    }
  ]
  </code></pre>
  
  <h2>The grammar:</h2>
  
  <p>Formatting Subcircuit Definitions:</p>
  
  <pre><code>subckt SubcircuitName [(] node1 ... nodeN [)]
  [ parameters name1=value1 ... [nameN=valueN]]
  .
  .
  .
  instance, model, ic, or nodeset statements—or
  further subcircuit definitions
  .
  .
  .
  ends [SubcircuitName]
  </code></pre>
  
  <p>Formatting the Instance Statement:</p>
  
  <pre><code>name [(]node1 ... nodeN[)] master [[param1=value1] ...[paramN=valueN]]
  </code></pre>