Package com.github.jknack.antlr4ide.lang

Examples of com.github.jknack.antlr4ide.lang.ParserRule


    EList<Rule> rules = new BasicEList<Rule>();

    EList<PrequelConstruct> prequels = new BasicEList<PrequelConstruct>();

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule = createMock(ParserRule.class);
    ParserRule ref = createMock(ParserRule.class);
    IScope scope = createMock(IScope.class);

    Antlr4ScopeProvider scopeProvider = PowerMock.createPartialMock(Antlr4ScopeProvider.class,
        "scopeFor", PrequelConstruct.class, List.class, Class.class);
View Full Code Here


    EList<EObject> ruleBodyList = new BasicEList<EObject>();

    String localsBody = "{\n$ctx.tree;\n}";

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule1 = createMock(ParserRule.class);
    Return returns = createMock(Return.class);
    LocalVars locals = createMock(LocalVars.class);
    RuleBlock ruleBody = createMock(RuleBlock.class);
    ActionElement actionElement = createMock(ActionElement.class);

    expect(grammar.getRules()).andReturn(rules);

    expect(rule1.getArgs()).andReturn(null);
    expect(rule1.getReturn()).andReturn(returns);
    expect(rule1.getLocals()).andReturn(locals);
    expect(rule1.getBody()).andReturn(ruleBody).times(2);

    expect(returns.getBody()).andReturn(null);

    expect(locals.getBody()).andReturn(localsBody);
View Full Code Here

      verify(rule);
    }
  }

  private Rule parserRule(final String name, final RuleBlock block) {
    ParserRule rule = createMock(ParserRule.class);

    expect(rule.getName()).andReturn(name);
    if (block != null) {
      expect(rule.getBody()).andReturn(block);
    }

    return rule;
  }
View Full Code Here

  public void ruleRefAttributeIsOK() throws Exception {
    EList<Rule> rules = new BasicEList<Rule>();
    EList<EObject> ruleBodyList = new BasicEList<EObject>();

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule1 = createMock(ParserRule.class);
    Return returns = createMock(Return.class);
    LocalVars locals = createMock(LocalVars.class);
    RuleBlock ruleBody = createMock(RuleBlock.class);
    RuleRef ruleRef = createMock(RuleRef.class);
    ParserRule expr = createMock(ParserRule.class);
    ActionElement actionElement = createMock(ActionElement.class);
    Antlr4Validator validator = PowerMock.createPartialMock(Antlr4Validator.class, "error");

    expect(grammar.getRules()).andReturn(rules);

    expect(rule1.getArgs()).andReturn(null);
    expect(rule1.getReturn()).andReturn(returns);
    expect(rule1.getLocals()).andReturn(locals);
    expect(rule1.getBody()).andReturn(ruleBody).times(2);

    expect(returns.getBody()).andReturn(null);

    expect(locals.getBody()).andReturn(null);

    ruleBodyList.add(ruleRef);
    ruleBodyList.add(actionElement);

    expect(ruleBody.eAllContents()).andReturn(newTreeIterator(ruleBodyList));
    expect(ruleBody.eAllContents()).andReturn(newTreeIterator(ruleBodyList));

    expect(ruleRef.getReference()).andReturn(expr);

    expect(expr.getName()).andReturn("expr");

    expect(actionElement.getBody()).andReturn("{int v = $expr.v;}");

    rules.add(rule1);
View Full Code Here

  public void ruleRefAttributeIsMissing() throws Exception {
    EList<Rule> rules = new BasicEList<Rule>();
    EList<EObject> ruleBodyList = new BasicEList<EObject>();

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule1 = createMock(ParserRule.class);
    Return returns = createMock(Return.class);
    LocalVars locals = createMock(LocalVars.class);
    RuleBlock ruleBody = createMock(RuleBlock.class);
    ActionElement actionElement = createMock(ActionElement.class);
    Antlr4Validator validator = PowerMock.createPartialMock(Antlr4Validator.class, "error");

    expect(grammar.getRules()).andReturn(rules);

    expect(rule1.getArgs()).andReturn(null);
    expect(rule1.getReturn()).andReturn(returns);
    expect(rule1.getLocals()).andReturn(locals);
    expect(rule1.getBody()).andReturn(ruleBody).times(2);

    expect(returns.getBody()).andReturn(null);

    expect(locals.getBody()).andReturn(null);
View Full Code Here

  @Test
  public void parserRulesNotAllowed() throws Exception {

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule = createMock(ParserRule.class);
    EClass eClass = createMock(EClass.class);
    EStructuralFeature feature = createMock(EStructuralFeature.class);
    Antlr4Validator validator = PowerMock.createPartialMock(Antlr4Validator.class, "error");

    expect(grammar.getType()).andReturn(GrammarType.LEXER);

    expect(rule.eContainer()).andReturn(grammar);
    expect(rule.eClass()).andReturn(eClass);
    expect(rule.getName()).andReturn("rule");
    expect(eClass.getEStructuralFeature("name")).andReturn(feature);

    PowerMock.expectPrivate(validator, "error", "parser rule 'rule' not allowed in lexer",
        rule, feature);
View Full Code Here

    String args = "[Arg a, Arg b]";
    String returnBody = "[Return r;]";
    String localsBody = "{\nLocal l;\n}";

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule1 = createMock(ParserRule.class);
    Return returns = createMock(Return.class);
    LocalVars locals = createMock(LocalVars.class);
    RuleBlock ruleBody = createMock(RuleBlock.class);
    LabeledElement labeledElement = createMock(LabeledElement.class);
    Terminal terminal = createMock(Terminal.class);
    LexerRule ID = createMock(LexerRule.class);
    ActionElement actionElement = createMock(ActionElement.class);
    ActionOption actionOption = createMock(ActionOption.class);
    Antlr4Validator validator = PowerMock.createPartialMock(Antlr4Validator.class, "error");

    expect(grammar.getRules()).andReturn(rules);

    expect(rule1.getArgs()).andReturn(args);
    expect(rule1.getReturn()).andReturn(returns);
    expect(rule1.getLocals()).andReturn(locals);
    expect(rule1.getBody()).andReturn(ruleBody).times(2);

    expect(returns.getBody()).andReturn(returnBody);

    expect(locals.getBody()).andReturn(localsBody);
View Full Code Here

    String args = "[Arg a, Arg b]";
    String returnBody = "[Return r;]";
    String localsBody = "{\nLocal l;\n}";

    Grammar grammar = createMock(Grammar.class);
    ParserRule rule1 = createMock(ParserRule.class);
    Return returns = createMock(Return.class);
    LocalVars locals = createMock(LocalVars.class);
    RuleBlock ruleBody = createMock(RuleBlock.class);
    LabeledElement labeledElement = createMock(LabeledElement.class);
    Terminal terminal = createMock(Terminal.class);
    LexerRule ID = createMock(LexerRule.class);
    ActionElement actionElement = createMock(ActionElement.class);
    ActionOption actionOption = createMock(ActionOption.class);
    Antlr4Validator validator = PowerMock.createPartialMock(Antlr4Validator.class, "error");

    expect(grammar.getRules()).andReturn(rules);

    expect(rule1.getArgs()).andReturn(args);
    expect(rule1.getReturn()).andReturn(returns);
    expect(rule1.getLocals()).andReturn(locals);
    expect(rule1.getBody()).andReturn(ruleBody).times(2);

    expect(returns.getBody()).andReturn(returnBody);

    expect(locals.getBody()).andReturn(localsBody);
View Full Code Here

    verify(mocks);
  }

  @Test
  public void missingArgumentsOnRuleReference() throws Exception {
    ParserRule reference = createMock(ParserRule.class);
    RuleRef ruleRef = createMock(RuleRef.class);
    EClass eClass = createMock(EClass.class);
    EStructuralFeature feature = createMock(EStructuralFeature.class);
    Antlr4Validator validator = PowerMock.createPartialMock(Antlr4Validator.class, "error");

    expect(ruleRef.getReference()).andReturn(reference);
    expect(ruleRef.getArgs()).andReturn(null);
    expect(ruleRef.eClass()).andReturn(eClass);

    expect(reference.getName()).andReturn("rule");
    expect(reference.getArgs()).andReturn("[int a, int b]");

    expect(eClass.getEStructuralFeature("reference")).andReturn(feature);

    PowerMock.expectPrivate(validator, "error", "missing arguments(s) on rule reference: rule",
        ruleRef, feature);
View Full Code Here

    verify(mocks);
  }

  @Test
  public void ruleHasNoDefinedParameters() throws Exception {
    ParserRule reference = createMock(ParserRule.class);
    RuleRef ruleRef = createMock(RuleRef.class);
    EClass eClass = createMock(EClass.class);
    EStructuralFeature feature = createMock(EStructuralFeature.class);
    Antlr4Validator validator = PowerMock.createPartialMock(Antlr4Validator.class, "error");

    expect(ruleRef.getReference()).andReturn(reference);
    expect(ruleRef.getArgs()).andReturn("[a, b]");
    expect(ruleRef.eClass()).andReturn(eClass);

    expect(reference.getName()).andReturn("rule");
    expect(reference.getArgs()).andReturn(null);

    expect(eClass.getEStructuralFeature("args")).andReturn(feature);

    PowerMock.expectPrivate(validator, "error", "rule 'rule' has no defined parameters",
        ruleRef, feature);
View Full Code Here

TOP

Related Classes of com.github.jknack.antlr4ide.lang.ParserRule

Copyright © 2018 www.massapicom. 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.