Tabnine Logo
Parser
Code IndexAdd Tabnine to your IDE (free)

How to use
Parser
in
de.neuland.jade4j.parser

Best Java code snippets using de.neuland.jade4j.parser.Parser (Showing top 20 results out of 315)

origin: HubSpot/Singularity

private JadeTemplate getJadeTemplate(String name) throws IOException {
 Parser parser = new Parser("templates/" + name, JadeTemplateLoader.JADE_LOADER);
 Node root = parser.parse();
 final JadeTemplate jadeTemplate = new JadeTemplate();
 jadeTemplate.setTemplateLoader(JadeTemplateLoader.JADE_LOADER);
 jadeTemplate.setRootNode(root);
 return jadeTemplate;
}
origin: neuland/jade4j

private Node parseASTFilter() {
  Token token = expect(Filter.class);
  Filter filterToken = (Filter) token;
  AttributeList attr = (AttributeList) accept(AttributeList.class);
  token = expect(Colon.class);
  FilterNode node = new FilterNode();
  node.setValue(filterToken.getValue());
  node.setBlock(block());
  node.setLineNumber(line());
  node.setFileName(filename);
  node.setAttributes(convertToNodeAttributes(attr));
  return node;
}
origin: neuland/jade4j

  Token incomingToken = peek();
  if (incomingToken instanceof CssId) {
    Token tok = advance();
    tagNode.setAttribute("id", tok.getValue(),false);
    continue;
  } else if (incomingToken instanceof CssClass) {
    Token tok = advance();
    tagNode.setAttribute("class", tok.getValue(),false);
    continue;
  } else if (incomingToken instanceof AttributeList) {
    if (seenAttrs) {
      throw new JadeParserException(filename,line(),templateLoader,this.filename + ", line " + this.peek().getLineNumber() + ":\nYou should not have jade tags with multiple attributes.");
    AttributeList tok = (AttributeList) advance();
    List<Attribute> attrs = tok.getAttributes();
    tagNode.setSelfClosing(tok.isSelfClosing());
    Token tok = this.advance();
    tagNode.addAttributes(tok.getValue());
  } else {
if (peek() instanceof Dot) {
  dot = true;
  tagNode.setTextOnly(true);
  advance();
if (peek() instanceof Text) {
  tagNode.getBlock().push(parseText());
} else if (peek() instanceof Expression) {
origin: neuland/jade4j

private List<CaseConditionNode> whenBlock() {
  expect(Indent.class);
  List<CaseConditionNode> caseConditionalNodes = new LinkedList<CaseConditionNode>();
  while (!(peek() instanceof Outdent) && !(peek() instanceof Eos)) {
    if (peek() instanceof Newline) {
      advance();
    } else {
      caseConditionalNodes.add(this.parseCaseCondition());
    }
  }
  if (peek() instanceof Outdent) {
    expect(Outdent.class);
  }
  return caseConditionalNodes;
}
origin: neuland/jade4j

private Node parseBlockExpansion(){
 if (this.peek() instanceof Colon) {
  this.advance();
   BlockNode blockNode = new BlockNode();
   blockNode.push(this.parseExpr());
   return blockNode;
 } else {
  return this.block();
 }
}
origin: neuland/jade4j

private Node parseExtends() {
  Token token = expect(ExtendsToken.class);
  ExtendsToken extendsToken = (ExtendsToken) token;
  String templateName = extendsToken.getValue().trim();
  Parser parser = createParser(templateName);
  parser.setBlocks(blocks);
  parser.setContexts(contexts);
  extending = parser;
  LiteralNode node = new LiteralNode();
  node.setValue("");
  return node;
}
origin: neuland/jade4j

private Node parseInclude() {
  Token token = expect(Include.class);
  Include includeToken = (Include) token;
  String templateName = includeToken.getValue().trim();
      FilterNode node = new FilterNode();
      node.setValue(includeToken.getFilter());
      node.setLineNumber(line());
      node.setFileName(filename);
      TextNode text = new TextNode();
  Parser parser = createParser(templateName);
  parser.setBlocks(new LinkedHashMap<String,BlockNode>(blocks));
  parser.setMixins(mixins);
  contexts.push(parser);
  Node ast = parser.parse();
  contexts.pop();
  ast.setFileName(path);
  if (peek() instanceof Indent && ast != null) {
    ((BlockNode) ast).getIncludeBlock().push(block());
origin: neuland/jade4j

private Node[] parseInlineTagsInText(String str) {
  int line = this.line();
  Matcher matcher = Pattern.compile("(\\\\)?#\\[((?:.|\\n)*)$").matcher(str);
  TextNode text = new TextNode();
    if (matcher.group(1) != null) { // escape
      text.setValue(str.substring(0, matcher.start()) + "#[");//Not sure if Matcher.end() is correct
      Node[] rest = this.parseInlineTagsInText(matcher.group(2));
      if (rest[0] instanceof TextNode) {
        text.setValue(text.getValue() + rest[0].getValue());
        inner = new Parser(range.getSrc(), this.filename,this.basePath, this.templateLoader,this.expressionHandler); //Need to be reviewed
      } catch (IOException e) {
        throw new JadeParserException(this.filename,line,templateLoader,"Could not parse text");
      buffer = ArrayUtils.add(buffer,inner.parse());
      return ArrayUtils.addAll(buffer, this.parseInlineTagsInText(rest.substring(range.getEnd() + 1)));
origin: neuland/jade4j

public Node parse() {
  BlockNode block = new BlockNode();
  block.setLineNumber(lexer.getLineno());
  block.setFileName(filename);
  while (!(peek() instanceof Eos)) {
    if (peek() instanceof Newline) {
      advance();
    } else {
      Node expr = parseExpr();
      if (expr != null) {
        block.push(expr);
      }
    }
  }
  if (extending != null) {
    getContexts().push(extending);
    Node rootNode = extending.parse();
    getContexts().pop();
    // hoist mixins
    Set<String> keySet = this.mixins.keySet();
    for (String name : keySet) {
      rootNode.getNodes().push(this.mixins.get(name));
    }
    return rootNode;
  }
  return block;
}
origin: neuland/jade4j

private Node parseCase() {
  String val = expect(CaseToken.class).getValue();
  Node node = new CaseNode();
  node.setValue(val);
  node.setLineNumber(line());
  Node block = new BlockNode();
  block.setLineNumber(line());
  block.setFileName(filename);
  expect(Indent.class);
  while (!(peek() instanceof Outdent)) {
    if (peek() instanceof Comment) {
      advance();
    } else if (peek() instanceof Newline) {
      advance();
    } else if (peek() instanceof When) {
      block.push(parseWhen());
    } else if (peek() instanceof Default) {
      block.push(parseDefault());
    } else {
      throw new JadeParserException(filename,lexer.getLineno(),templateLoader,"Unexpected token \"" + this.peek() + "\", expected \"when\", \"default\" or \"newline\"");
    }
  }
  expect(Outdent.class);
  node.setBlock(block);
  return node;
}
/**
origin: neuland/jade4j

private Node parseConditional() {
  If conditionalToken = (If) expect(If.class);
  ConditionalNode conditional = new ConditionalNode();
  conditional.setLineNumber(conditionalToken.getLineNumber());
  main.setBlock(block());
  conditions.add(main);
  while (peek() instanceof ElseIf) {
    ElseIf token = (ElseIf) expect(ElseIf.class);
    IfConditionNode elseIf = new IfConditionNode(token.getValue(), token.getLineNumber());
    elseIf.setBlock(block());
    conditions.add(elseIf);
  if (peek() instanceof Else) {
    Else token = (Else) expect(Else.class);
    IfConditionNode elseNode = new IfConditionNode(null, token.getLineNumber());
    elseNode.setDefault(true);
    elseNode.setBlock(block());
    conditions.add(elseNode);
origin: neuland/jade4j

private Node parseFilter() {
  Token token = expect(Filter.class);
  Filter filterToken = (Filter) token;
  AttributeList attr = (AttributeList) accept(AttributeList.class);
  lexer.setPipeless(true);
  Node tNode = parseTextBlock();
  lexer.setPipeless(false);
  FilterNode node = new FilterNode();
  node.setValue(filterToken.getValue());
  node.setLineNumber(line());
  node.setFileName(filename);
  if(tNode!=null)
    node.setTextBlock(tNode);
  else{
    node.setTextBlock(new BlockNode());
  }
  if (attr != null) {
    node.setAttributes(convertToNodeAttributes(attr));
  }
  return node;
}
origin: neuland/jade4j

private Parser createParser(String templateName) {
  templateName = ensureJadeExtension(templateName);
  try {
    return new Parser(pathHelper.resolvePath(filename,templateName, basePath, templateLoader.getExtension()), basePath, templateLoader, expressionHandler);
  } catch (IOException e) {
    throw new JadeParserException(filename, lexer.getLineno(), templateLoader, "the template [" + templateName
        + "] could not be opened\n" + e.getMessage());
  }
}
origin: neuland/jade4j

private Node blockExpansion() {
  if (peek() instanceof Colon) {
    Token token = expect(Colon.class);
    Colon colon = (Colon) token;
    BlockNode block = new BlockNode();
    block.setLineNumber(colon.getLineNumber());
    block.setFileName(filename);
    block.getNodes().add(parseExpr());
    return block;
  }
  return block();
}
origin: neuland/jade4j

private Node parseEach() {
  Token token = expect(Each.class);
  Each eachToken = (Each) token;
  EachNode node = new EachNode();
  node.setValue(eachToken.getValue());
  node.setKey(eachToken.getKey());
  node.setCode(eachToken.getCode());
  node.setLineNumber(eachToken.getLineNumber());
  node.setFileName(filename);
  node.setBlock(block());
  if (peek() instanceof Else) {
    advance();
    node.setElseNode(block());
  }
  return node;
}
origin: neuland/jade4j

private Node parseTextBlock() {
  BlockNode blockNode = new BlockNode();
  blockNode.setLineNumber(line());
  blockNode.setFileName(filename);
  Token body  = peek();
  if(!(body instanceof PipelessText)){
    return null;
  }
  this.advance();
  ArrayList<String> values = body.getValues();
  Node[] textNodes = {};
  for (String value : values) {
    textNodes = ArrayUtils.addAll(textNodes,parseInlineTagsInText(value));
  }
  blockNode.setNodes(new LinkedList<Node>(Arrays.asList(textNodes)));
  return blockNode;
}
origin: neuland/jade4j

private BlockNode block() {
  BlockNode block = new BlockNode();
  block.setLineNumber(lexer.getLineno());
  block.setFileName(filename);
  expect(Indent.class);
  while (!(peek() instanceof Outdent)) {
    if (peek() instanceof Newline) {
      advance();
    } else {
      Node parseExpr = this.parseExpr();
      parseExpr.setFileName(filename);
      if (parseExpr != null) {
        block.push(parseExpr);
      }
    }
  }
  expect(Outdent.class);
  return block;
}
origin: neuland/jade4j

private Node parseBlock() {
  Token token = expect(Block.class);
  Block block = (Block) token;
  String mode = block.getMode();
  if (peek() instanceof Indent) {
    blockNode = block();
  } else {
    blockNode = new BlockNode();
  blockNode.setLineNumber(line());
origin: neuland/jade4j

private Node parseCssClassOrId() {
  Token tok = advance();
  Tag div = new Tag("div", line());
  lexer.defer(div);
  lexer.defer(tok);
  return parseExpr();
}
private Node parseBlock() {
origin: neuland/jade4j

private CaseConditionNode parseCaseCondition() {
  CaseConditionNode node = new CaseConditionNode();
  Token token = null;
  if (peek() instanceof When) {
    token = expect(When.class);
  } else {
    token = expect(Default.class);
    node.setDefault(true);
  }
  node.setLineNumber(token.getLineNumber());
  node.setFileName(filename);
  node.setValue(token.getValue());
  node.setBlock(blockExpansion());
  return node;
}
de.neuland.jade4j.parserParser

Most used methods

  • <init>
  • parse
  • accept
  • advance
  • block
  • blockExpansion
  • convertToNodeAttributes
  • createParser
  • ensureJadeExtension
  • expect
  • getContexts
  • line
  • getContexts,
  • line,
  • lookahead,
  • parseAssignment,
  • parseBlock,
  • parseBlockCode,
  • parseBlockExpansion,
  • parseCall,
  • parseCase,
  • parseCaseCondition

Popular in Java

  • Parsing JSON documents to java classes using gson
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getApplicationContext (Context)
  • compareTo (BigDecimal)
  • Permission (java.security)
    Legacy security code; do not use.
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now