Package org.intellij.grammar.psi

Examples of org.intellij.grammar.psi.BnfFile


    final PsiFile file = LangDataKeys.PSI_FILE.getData(e.getDataContext());
    if (!(file instanceof BnfFile)) return;

    final Project project = file.getProject();

    final BnfFile bnfFile = (BnfFile) file;
    final String flexFileName = getFlexFileName(bnfFile);

    Collection<VirtualFile> files = FilenameIndex.getVirtualFilesByName(project, flexFileName, ProjectScope.getAllScope(project));
    VirtualFile firstItem = ContainerUtil.getFirstItem(files);

    FileSaverDescriptor descriptor = new FileSaverDescriptor("Save JFlex Lexer", "", "flex");
    VirtualFile baseDir = firstItem != null ? firstItem.getParent() : bnfFile.getVirtualFile().getParent();
    VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance().createSaveFileDialog(descriptor, project).
      save(baseDir, firstItem != null ? firstItem.getName() : flexFileName);
    if (fileWrapper == null) return;
    final VirtualFile virtualFile = fileWrapper.getVirtualFile(true);
    if (virtualFile == null) return;
View Full Code Here


  public void actionPerformed(AnActionEvent e) {
    PsiFile file = LangDataKeys.PSI_FILE.getData(e.getDataContext());
    if (!(file instanceof BnfFile)) return;

    Project project = file.getProject();
    BnfFile bnfFile = (BnfFile) file;
    final String qualifiedName = createClass(
        bnfFile, "Create Parser Util Class", BnfConstants.GPUB_CLASS,
        getGrammarName(bnfFile) + "ParserUtil",
        getGrammarPackage(bnfFile));
    if (qualifiedName == null) return;

    final int anchorOffset;
    final String text;
    String definition = "\n  " + KnownAttribute.PARSER_UTIL_CLASS.getName() + "=\"" + qualifiedName + "\"";
    BnfAttr attrParser = bnfFile.findAttribute(null, KnownAttribute.PARSER_CLASS, null);
    if (attrParser == null) {
      BnfAttrs rootAttrs = ContainerUtil.getFirstItem(bnfFile.getAttributes());
      if (rootAttrs == null) {
        anchorOffset = 0;
        text = "{" + definition + "\n}";
      }
      else {
View Full Code Here

public class BnfFoldingBuilder extends FoldingBuilderEx implements DumbAware {
  @NotNull
  @Override
  public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
    if (!(root instanceof BnfFile)) return FoldingDescriptor.EMPTY;
    BnfFile file = (BnfFile)root;

    final ArrayList<FoldingDescriptor> result = new ArrayList<FoldingDescriptor>();
    for (BnfAttrs attrs : file.getAttributes()) {
      TextRange textRange = attrs.getTextRange();
      if (textRange.getLength() <= 2) continue;
      result.add(new FoldingDescriptor(attrs, textRange));
    }
    for (BnfRule rule : file.getRules()) {
      //result.add(new FoldingDescriptor(rule, rule.getTextRange()));
      BnfAttrs attrs = rule.getAttrs();
      if (attrs != null) {
        result.add(new FoldingDescriptor(attrs, attrs.getTextRange()));
      }
View Full Code Here

      String[] nextS = next.toArray(new String[next.size()]);
      Arrays.sort(nextS);
      docBuilder.append("<br><h1>Followed by:</h1>");
      docBuilder.append("<code>").append(StringUtil.escapeXml(StringUtil.join(nextS, " | "))).append("</code>");

      BnfFile file = (BnfFile)rule.getContainingFile();
      String recover = file.findAttributeValue(rule, KnownAttribute.RECOVER_WHILE, null);
      if (BnfConstants.RECOVER_AUTO.equals(recover)) {
        docBuilder.append("<br><h1>#auto recovery predicate:</h1>");
        docBuilder.append("<code>");
        docBuilder.append("private ").append(rule.getName()).append("_recover ::= !(");
        boolean f = true;
        for (String s : nextS) {
          if (s.startsWith("-") || s.startsWith("<")) continue;
          if (file.getRule(s) != null) continue;
          if (f) f = false;
          else docBuilder.append(" | ");
          docBuilder.append(StringUtil.escapeXml(s));
        }
        docBuilder.append(")");
View Full Code Here

    return null;
  }

  private static String getUpdatedDocumentation(final BnfRule rule, String prefix) {
    StringBuilder docBuilder = new StringBuilder(prefix);
    BnfFile file = (BnfFile)rule.getContainingFile();
    dumpPriorityTable(docBuilder, rule, file);
    dumpContents(docBuilder, rule, file);
    return docBuilder.toString();
  }
View Full Code Here

  }

  @Nullable
  public VirtualFile getGrammarFile() {
    if (myBnfFile != null) {
      BnfFile file = myBnfFile.get();
      return file == null? null : file.getVirtualFile();
    }
    else {
      return myFilePointer.getFile();
    }
  }
View Full Code Here

  private final Token[] myTokens;
  private Matcher[] myMatchers;

  public LivePreviewLexer(Project project, final LivePreviewLanguage language) {
    final BnfFile bnfFile = language.getGrammar(project);

    myTokens = bnfFile == null? new Token[0] : CachedValuesManager.getCachedValue(bnfFile, new CachedValueProvider<Token[]>() {
      @Nullable
      @Override
      public Result<Token[]> compute() {
View Full Code Here

  protected void doTest(String grammarFile) throws IOException {
    File grammarIOFile = new File(myFullDataPath, grammarFile);
    assertNotNull(grammarFile + "not found", grammarIOFile.exists());
    LightVirtualFile grammarVFile = new LightVirtualFile(grammarFile, FileUtil.loadFile(grammarIOFile));
    myLanguage = BnfLanguage.INSTANCE;
    BnfFile grammarPsi = (BnfFile) createFile(grammarVFile);
    myLanguage = LivePreviewHelper.getLanguageFor(grammarPsi);
    try {
      super.doTest(true);
    }
    finally {
View Full Code Here

public class BnfPinMarkerAnnotator implements Annotator, DumbAware {
  @Override
  public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
    if (!(psiElement instanceof BnfRule)) return;
    BnfRule rule = (BnfRule) psiElement;
    final BnfFile bnfFile = (BnfFile)rule.getContainingFile();
    final ArrayList<Pair<BnfExpression, BnfAttr>> pinned = new ArrayList<Pair<BnfExpression, BnfAttr>>();
    GrammarUtil.processPinnedExpressions(rule, new PairProcessor<BnfExpression, ParserGeneratorUtil.PinMatcher>() {
      @Override
      public boolean process(BnfExpression bnfExpression, ParserGeneratorUtil.PinMatcher pinMatcher) {
        BnfAttr attr = bnfFile.findAttribute(pinMatcher.rule, KnownAttribute.PIN, pinMatcher.funcName);
        return pinned.add(Pair.create(bnfExpression, attr));
      }
    });
    for (int i = 0, len = pinned.size(); i < len; i++) {
      BnfExpression e = pinned.get(i).first;
View Full Code Here

  private void doFirstTest(String text, String... expected) { doTest(text, true, expected); }
  private void doNextTest(String text, String... expected) { doTest(text, false, expected); }

  private void doTest(String text, boolean first, String... expected) {
    BnfFile f = (BnfFile)myFixture.configureByText("a.bnf", text);
    List<BnfRule> rules = f.getRules();
    assertFalse(rules.isEmpty());
    BnfFirstNextAnalyzer analyzer = new BnfFirstNextAnalyzer();
    Set<String> strings = analyzer.asStrings(first? analyzer.calcFirst(rules.get(0)) : analyzer.calcNext(rules.get(0)).keySet());
    String[] result = ArrayUtil.toStringArray(strings);
    Arrays.sort(result);
View Full Code Here

TOP

Related Classes of org.intellij.grammar.psi.BnfFile

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.