Package br.com.caelum.vraptor.panettone.parser.rule

Source Code of br.com.caelum.vraptor.panettone.parser.rule.CommentRule

package br.com.caelum.vraptor.panettone.parser.rule;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import br.com.caelum.vraptor.panettone.parser.SourceCode;
import br.com.caelum.vraptor.panettone.parser.TextChunk;
import br.com.caelum.vraptor.panettone.parser.ast.CommentNode;
import br.com.caelum.vraptor.panettone.parser.ast.Node;

public class CommentRule implements Rule {

  @Override
  public List<TextChunk> getChunks(SourceCode sc) {
    List<TextChunk> chunks = new ArrayList<TextChunk>();
       
    Pattern p = Pattern.compile("@--(.*)--@");
    Matcher matcher = p.matcher(sc.getSource());
   
    while(matcher.find()) {
      chunks.add(new TextChunk(matcher.group()));
    }
   
    return chunks;
  }

  @Override
  public Node getNode(TextChunk chunk) {
    String comment = chunk.getText().substring(3);
    comment = comment.substring(0, comment.length()-3);
   
    return new CommentNode(comment);
  }

}
TOP

Related Classes of br.com.caelum.vraptor.panettone.parser.rule.CommentRule

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.