title: antlr4 literal string handling
body: <p>I have the following antlr4 grammar:</p>
  
  <pre><code>grammar squirrel;
  
  program: globalstatement+;
  
  globalstatement: globalvardef | classdef | functiondef;
  
  globalvardef: IDENT '=' constantexpr ';';
  
  classdef: CLASS IDENT '{' classstatement+ '}';
  
  functiondef: FUNCTION IDENT '(' parameterlist ')' functionbody;
  
  constructordef: CONSTRUCTOR '(' parameterlist ')' functionbody;
  
  parameterlist: IDENT (',' IDENT)* | ;
  
  functionbody: '{' statement* '}';
  
  classstatement: globalvardef | functiondef | constructordef;
  
  statement: expression ';';
  
  
  expression: 
      IDENT # ident |
      IDENT '=' expression # assignment |
      IDENT ('.' IDENT)+ # lookupchain |
      constantexpr # constant |
      IDENT '(' expressionlist ')' # functioncall |
      expression '+' expression # addition;
  
  constantexpr: INTEGER | STRING;
  
  expressionlist: expression (',' expression)* | ;
  
  CONSTRUCTOR: 'constructor';
  CLASS: 'class';
  FUNCTION: 'function';
  COMMENT: '//'.*[\n];
  STRING: '"' CHAR* '"';
  CHAR: [ a-zA-Z0-9];
  INTEGER: [0-9]+;
  IDENT: [a-zA-Z]+;
  WS: [ \t\r\n]+ -&gt; skip;
  </code></pre>
  
  <p>Now if I parse this file:</p>
  
  <pre><code>z = "global variable";
  
  class Base
  {
      z = 10;
  }
  </code></pre>
  
  <p>everything is fine:</p>
  
  <pre><code>@0,0:0='z',&lt;16&gt;,1:0
  @1,2:2='=',&lt;1&gt;,1:2
  @2,4:20='"global variable"',&lt;14&gt;,1:4
  @3,21:21=';',&lt;2&gt;,1:21
  @4,26:30='class',&lt;11&gt;,3:0
  @5,32:35='Base',&lt;16&gt;,3:6
  @6,38:38='{',&lt;3&gt;,4:0
  @7,42:42='z',&lt;16&gt;,5:1
  @8,44:44='=',&lt;1&gt;,5:3
  @9,46:47='10',&lt;15&gt;,5:5
  @10,48:48=';',&lt;2&gt;,5:7
  @11,51:51='}',&lt;4&gt;,6:0
  @12,56:55='&lt;EOF&gt;',&lt;-1&gt;,8:0
  </code></pre>
  
  <p>But with this file:</p>
  
  <pre><code>z = "global variable";
  
  class Base
  {
      z = "10";
  }
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>@0,0:0='z',&lt;16&gt;,1:0
  @1,2:2='=',&lt;1&gt;,1:2
  @2,4:49='"global variable";\r\n\r\nclass Base\r\n{\r\n\tz = "10"',&lt;14&gt;,1:4
  @3,50:50=';',&lt;2&gt;,5:9
  @4,53:53='}',&lt;4&gt;,6:0
  @5,58:57='&lt;EOF&gt;',&lt;-1&gt;,8:0
  </code></pre>
  
  <p>So it seems like everything between the first " and last " in a file gets matched to one string literal.</p>
  
  <p>How do I prevent this ?</p>