Macaulay2 » Documentation
Packages » Style :: generateGrammar
next | previous | forward | backward | up | index | toc

generateGrammar -- generate a grammar file from a template

Description

This method generates a grammar file for use in syntax highlighting Macaulay2 code in a text editor or web browser.

The file template may contain any of the following special strings:

  • @M2BANNER@, for placing a banner mentioning that the resulting file was automatically generated.
  • @M2VERSION@, for the current version of Macaulay2.
  • @M2SYMBOLS@, for a list of all Macaulay2 symbols, e.g., for automatic completion.
  • @M2KEYWORDS@, for a list of Macaulay2 keywords.
  • @M2DATATYPES@, for a list of Macaulay2 types.
  • @M2FUNCTIONS@, for a list of Macaulay2 functions.
  • @M2CONSTANTS@, for a list of Macaulay2 symbols and packages.
  • @M2STRINGS@, for a regular expression that matches Macaulay2 strings.

The function demarkf indicates how the elements of each of the lists will be demarked in the resulting file. The file outfile will then be generated, replacing each of these strings as indicated above.

i1 : outfile = temporaryFileName()

o1 = /tmp/M2-28934-0/0
i2 : template = outfile | ".in"

o2 = /tmp/M2-28934-0/0.in
i3 : template << "@M2BANNER@" << endl << endl;
i4 : template << "This is an example file for the generateGrammar method!";
i5 : template << endl;
i6 : template << "String regex: @M2STRINGS@" << endl;
i7 : template << "List of keywords: {" << endl;
i8 : template << "    @M2KEYWORDS@" << endl;
i9 : template << "}" << endl << close;
i10 : get template

o10 = @M2BANNER@

      This is an example file for the generateGrammar method!
      String regex: @M2STRINGS@
      List of keywords: {
          @M2KEYWORDS@
      }
i11 : generateGrammar(template, outfile, x -> demark(",\n    ", x))
 -- generating /tmp/M2-28934-0/0
i12 : get outfile

o12 = Auto-generated for Macaulay2-1.25.05. Do not modify this file manually.

      This is an example file for the generateGrammar method!
      String regex: "///\\(/?/?[^/]\\|\\(//\\)*////[^/]\\)*\\(//\\)*///"
      List of keywords: {
          SPACE,
          TEST,
          and,
          break,
          breakpoint,
          catch,
          continue,
          do,
          elapsedTime,
          elapsedTiming,
          else,
          for,
          from,
          global,
          if,
          in,
          list,
          local,
          new,
          not,
          of,
          or,
          profile,
          return,
          shield,
          step,
          symbol,
          then,
          threadLocal,
          threadVariable,
          throw,
          time,
          timing,
          to,
          try,
          when,
          while,
          xor
      }

If template is omitted, then it defaults to currentFileDirectory | outfile | ".in".

Ways to use generateGrammar:

  • generateGrammar(String,Function)
  • generateGrammar(String,String,Function)

For the programmer

The object generateGrammar is a method function.


The source of this document is in Style.m2:182:0.