title: antlr return values as key-value
body: <p>I want to parse the sentence <code>"i am looking for a java developer from india"</code>.
  The output i need is language=java and place=india</p>
  
  <p>I created a grammar file as follows. </p>
  
  <pre><code>grammar Job;
  
  eval returns [String value]
      :    output=jobExp {System.out.println($output.text); $value = $output.text;}
      ;
  
  
  jobExp returns [String value]
      :    ind=indro whitespace var1=language ' developer from ' var2=place 
                              {
                              System.out.println($var1.text);
                              System.out.println($var2.text);
                              $value = $var1.text+$var2.text; }
      ;
  
  indro
      :
      'i am looking for a'
      |
      'i am searching for a'
      ;
  
  language :
      'java' | 'python' | 'cpp'
      ;
  
  place :
      'india' | 'america' | 'africa'
      ;
  
  whitespace :
      (' '|'\t')+
      ;
  </code></pre>
  
  <p>inside <code>jobExp</code> i am getting the values for <code>place</code> and <code>language</code>. And I am just returning only those two variables. But in <code>eval</code> i am getting the whole sentence(i am looking for a java developer from india). What should i need to get the exact matching output in <code>eval</code> ? Is it possible to get the output as <code>json</code> or <code>hashMap</code> in <code>antlr</code>? </p>
  
  <p>My <code>java</code> class for testing the grammar as follows:</p>
  
  <pre><code>import org.antlr.runtime.*;
  
  public class JobTest {
      public static void main(String[] args) throws Exception {
          ANTLRStringStream in = new ANTLRStringStream("i am looking for a java developer from india" );
          JobLexer lexer = new JobLexer(in);
          CommonTokenStream tokens = new CommonTokenStream(lexer);
          JobParser parser = new JobParser(tokens);
          System.out.println(parser.eval()); // print the value
      }
  }
  </code></pre>