Package com.github.jknack.antlr4ide.lang

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


    URI resourceURI = URI.createURI("platform:/resource/project/G.g4");
    Resource resource = createMock(Resource.class);
    expect(resource.getURI()).andReturn(resourceURI);

    Grammar grammar = createMock(Grammar.class);
    expect(grammar.eResource()).andReturn(resource);

    Rule rule = createMock(Rule.class);
    expect(rule.getName()).andReturn(ruleName);
    expect(rule.eContainer()).andReturn(grammar);
View Full Code Here


    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);

    Class[] prequelTypes = {Imports.class, Options.class, V3Tokens.class, V4Tokens.class,
        EmptyTokens.class, GrammarAction.class };
    for (Class prequelType : prequelTypes) {
      PrequelConstruct prequel = createMock(prequelType);
      prequels.add(prequel);
      scopeProvider.scopeFor(eq(prequel), isA(List.class), eq(Rule.class));
    }

    rules.add(ref);

    scopes.add(ref);

    expect(rule.eContainer()).andReturn(grammar);

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

    PowerMock.mockStatic(Scopes.class);

    expect(Scopes.scopeFor(eq(scopes), eq(Antlr4NameProvider.nameFn), eq(IScope.NULLSCOPE)))
        .andReturn(scope);
View Full Code Here

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

    EList<LexerRule> modeRules = new BasicEList<LexerRule>();
    EList<Mode> modes = new BasicEList<Mode>();

    Grammar grammar = createMock(Grammar.class);
    LexerRule rule = createMock(LexerRule.class);
    LexerRule ref = createMock(LexerRule.class);
    IScope scope = createMock(IScope.class);
    Mode mode = createMock(Mode.class);
    LexerRule modeRule = createMock(LexerRule.class);

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

    Class[] prequelTypes = {Imports.class, Options.class, V3Tokens.class, V4Tokens.class,
        EmptyTokens.class, GrammarAction.class };
    for (Class prequelType : prequelTypes) {
      PrequelConstruct prequel = createMock(prequelType);
      prequels.add(prequel);
      scopeProvider.scopeFor(eq(prequel), isA(List.class), eq(LexerRule.class));
    }

    rules.add(ref);

    modeRules.add(modeRule);
    modes.add(mode);

    scopes.add(ref);
    scopes.add(mode);
    scopes.add(modeRule);

    expect(rule.eContainer()).andReturn(grammar);

    expect(grammar.eContainer()).andReturn(null);
    expect(grammar.getRules()).andReturn(rules);
    expect(grammar.getPrequels()).andReturn(prequels);
    expect(grammar.getModes()).andReturn(modes);

    expect(mode.getRules()).andReturn(modeRules);

    PowerMock.mockStatic(Scopes.class);
View Full Code Here

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

    Imports imports = createMock(Imports.class);
    Import delegate = createMock(Import.class);
    Grammar grammar = createMock(Grammar.class);
    Rule r1 = createMock(ParserRule.class);
    Rule r2 = createMock(LexerRule.class);

    expect(imports.getImports()).andReturn(importList).times(3);

    expect(delegate.getImportURI()).andReturn(grammar).times(3);

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

    importList.add(delegate);

    rules.add(r1);
    rules.add(r2);
View Full Code Here

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

    Options options = createMock(Options.class);
    TokenVocab tokenVocab = createMock(TokenVocab.class);
    Grammar grammar = createMock(Grammar.class);
    Rule r1 = createMock(LexerRule.class);
    Mode mode = createMock(Mode.class);
    LexerRule mr1 = createMock(LexerRule.class);

    expect(options.getOptions()).andReturn(optionList);

    expect(tokenVocab.getImportURI()).andReturn(grammar);

    expect(grammar.getRules()).andReturn(rules);
    expect(grammar.getModes()).andReturn(modes);
    expect(grammar.getPrequels()).andReturn(prequels);

    expect(mode.getRules()).andReturn(mRules);

    optionList.add(tokenVocab);
View Full Code Here

  @Test
  public void actionOnDiffScopesMustNotFail() throws Exception {
    EList<PrequelConstruct> prequels = new BasicEList<PrequelConstruct>();

    Grammar grammar = createMock(Grammar.class);
    GrammarAction action1 = createMock(GrammarAction.class);
    GrammarAction action2 = createMock(GrammarAction.class);
    Antlr4Validator validator = PowerMock.createPartialMock(Antlr4Validator.class, "error");

    expect(grammar.getPrequels()).andReturn(prequels);

    expect(action1.getScope()).andReturn("lexer");
    expect(action1.getName()).andReturn("header");

    expect(action2.getScope()).andReturn("parser");
View Full Code Here

  @Test
  public void ruleMapWithoutLiterals() {
    EList<Rule> rules = rules(parserRule("prog", null), lexerRule("WS", null));

    Grammar grammar = createMock(Grammar.class);
    expect(grammar.getRules()).andReturn(rules);

    Object[] mocks = {grammar };

    replay(mocks);
    replayRules(rules);
View Full Code Here

  @Test
  public void ruleMapWithLiterals() {
    EList<Rule> rules = rules(parserRule("prog", literal("hello")),
        lexerRule("WS", lexerBlock("\"")));

    Grammar grammar = createMock(Grammar.class);
    expect(grammar.getRules()).andReturn(rules);

    Object[] mocks = {grammar };

    replay(mocks);
    replayRules(rules);
View Full Code Here

  @Test
  public void literals() {
    EList<Rule> rules = rules(parserRule("prog", literal("hello")),
        lexerRule("WS", lexerBlock("\"")));

    Grammar grammar = createMock(Grammar.class);
    expect(grammar.getRules()).andReturn(rules);

    Object[] mocks = {grammar };

    replay(mocks);
    replayRules(rules);
View Full Code Here

  @Test
  public void hash() {
    Rule e1 = createMock(ParserRule.class);
    Rule e2 = createMock(ParserRule.class);

    Grammar source1 = createMock(Grammar.class);
    expect(source1.eAllContents()).andReturn(newTreeIterator(elist(e1)));
    expect(source1.eAllContents()).andReturn(newTreeIterator(elist(e1)));
    expect(source1.eAllContents()).andReturn(newTreeIterator(elist(e1)));
    expect(source1.eAllContents()).andReturn(newTreeIterator(elist(e1)));

    Grammar source2 = createMock(Grammar.class);
    expect(source2.eAllContents()).andReturn(newTreeIterator(elist(e1, e2)));
    expect(source2.eAllContents()).andReturn(newTreeIterator(elist(e1, e2)));
    expect(source2.eAllContents()).andReturn(newTreeIterator(elist(e1, e2)));
    expect(source2.eAllContents()).andReturn(newTreeIterator(elist(e1, e2)));

    Object[] mocks = {source1, source2, e1, e2 };

    replay(mocks);
View Full Code Here

TOP

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

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.