diff --git a/Makefile.am b/Makefile.am index 41e716dc0..a227abcef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,8 @@ # Authors: # DP Chassin (dchassin@slac.stanford.edu) -AM_INIT_AUTOMAKE = subdir-objects +AM_INIT_AUTOMAKE = subdir-objects +AUTOMAKE_OPTIONS = -Wno-portability ACLOCAL_AMFLAGS = -I m4 CC = $(PTHREAD_CC) @@ -57,6 +58,7 @@ include $(top_srcdir)/third_party/Makefile.mk include $(top_srcdir)/gldcore/Makefile.mk include $(top_srcdir)/python_extras/Makefile.mk include $(top_srcdir)/cloud/Makefile.mk +include $(top_srcdir)/utilities/Makefile.mk # approved modules include $(top_srcdir)/modules.mk diff --git a/docs/Command/Sublime_syntax.md b/docs/Command/Sublime_syntax.md new file mode 100644 index 000000000..32210cc16 --- /dev/null +++ b/docs/Command/Sublime_syntax.md @@ -0,0 +1,19 @@ +[[/Command/Sublime_syntax]] -- Generates the SublimeText syntax for GLM files + +# Synopsis + +~~~ +bash$ gridlabd --sublime_syntax +~~~ + +# Description + +The `--sublime_syntax` option generates the syntax file required to enable syntax highlighting for GLM files. + +# Example + +The following example generates the syntax file and stores in the current user's package folder for Sublime Text 3. + +~~~ +% gridlabd --sublime_syntax > $(HOME)/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/GLM.sublime-syntax +~~~ diff --git a/gldcore/cmdarg.cpp b/gldcore/cmdarg.cpp index 345d5c739..3b91aaeff 100644 --- a/gldcore/cmdarg.cpp +++ b/gldcore/cmdarg.cpp @@ -2224,8 +2224,11 @@ DEPRECATED static int nprocs(void *main, int argc, const char *argv[]) return 0; } -#include "job.h" -#include "validate.h" +DEPRECATED static int sublime_syntax(void *main, int argc, const char *argv[]) +{ + ((GldMain*)main)->get_loader()->sublime_syntax(); + return 0; +} /*********************************************/ /* ADD NEW CMDARG PROCESSORS ABOVE THIS HERE */ @@ -2233,6 +2236,9 @@ DEPRECATED static int nprocs(void *main, int argc, const char *argv[]) /* CMDARG structure below */ /*********************************************/ +#include "job.h" +#include "validate.h" + DEPRECATED static CMDARG main_commands[] = { /* NULL,NULL,NULL,NULL, "Section heading */ @@ -2290,6 +2296,7 @@ DEPRECATED static CMDARG main_commands[] = { {"xsd", NULL, xsd, "[module[:class]]", "Prints the XSD of a module or class" }, {"xsl", NULL, xsl, "module[,module[,...]]]", "Create the XSL file for the module(s) listed" }, {"formats", NULL, formats, NULL, "get a list supported file formats"}, + {"sublime_syntax", NULL, sublime_syntax, NULL, "generate sublime syntax file"}, {NULL,NULL,NULL,NULL, "Help"}, {"help", "h", help, NULL, "Displays command line help" }, diff --git a/gldcore/load.cpp b/gldcore/load.cpp index a2b64d9c4..05b194bd3 100755 --- a/gldcore/load.cpp +++ b/gldcore/load.cpp @@ -1377,7 +1377,7 @@ int GldLoader::multiline_value(PARSER,char *result,int size) value += std::string("\t"); break; case 'b': - value += std::string("\b"); + value += std::string("\\b"); break; case 'f': value += std::string("\f"); @@ -8637,3 +8637,111 @@ void GldLoader::add_depend(const char *filename, const char *dependency) item.push_back(dependency); } } + +void GldLoader::sublime_syntax(void) +{ + output_message("%%YAML 1.2"); + output_message("---"); + output_message("# See http://www.sublimetext.com/docs/3/syntax.html"); + output_message("name: HiPAS GridLAB-D"); + output_message("file_extensions:"); + output_message(" - glm"); + output_message("scope: source"); + output_message(""); + output_message("contexts:"); + output_message(" # The prototype context is prepended to all contexts but those setting"); + output_message(" # meta_include_prototype: false."); + output_message(" prototype:"); + output_message(" - include: comments"); + output_message(""); + output_message(" main:"); + output_message(" # The main context is the initial starting point of our syntax."); + output_message(" # Include other contexts from here (or specify them directly)."); + output_message(" - include: strings"); + output_message(" - include: conditionals"); + output_message(" - include: macros"); + output_message(" - include: directives"); + output_message(" - include: units"); + output_message(" - include: numbers"); + output_message(" - include: keywords"); + output_message(" - include: names"); + output_message(""); + output_message(" conditionals:"); + output_message(" - match: '\\b#(if|ifdef|ifndef|for|end|begin|for|done)\\b'"); + output_message(" scope: keyword"); + output_message(""); + output_message(" macros:"); + output_message(" - match: '\\b#[a-z]+\\b'"); + output_message(" scope: keyword"); + output_message(""); + output_message(" directives:"); + output_message(" - match: '\\b(clock|module|class|object|modify|global|filter|intrinsic|import|export|script|library|link|dump|extension|instance|schedule)\\b'"); + output_message(" scope: keyword"); + output_message(""); + output_message(" names:"); + output_message(" - match: '\\b[A-Za-z_]+[-A-Za-z_:.0-9]*\\b'"); + output_message(" scope: entity.name"); + output_message(""); + output_message(" numbers:"); + output_message(" - include: complex"); + output_message(" - include: reals"); + output_message(" - include: integers"); + output_message(""); + output_message(" integers:"); + output_message(" - match: '\\b[-+]?[0-9]+\\b'"); + output_message(" scope: constant"); + output_message(""); + output_message(" reals:"); + output_message(" - match: '\\b[-+]?[0-9]+.[0-9]+(|[eE][-+]?[0-9]+)\\b'"); + output_message(" scope: constant"); + output_message(""); + output_message(" complex:"); + output_message(" - match: '\\b[-+]?[0-9]+.[0-9]+(|[eE][-+]?[0-9]+)[-+][0-9]+.[0-9]+(|[eE][-+]?[0-9]+)[ijrd]\\b'"); + output_message(" scope: constant"); + output_message(""); + output_message(" units:"); + output_message(" - include: real_units"); + output_message(" - include: complex_units"); + output_message(""); + output_message(" real_units:"); + output_message(" - match: '\\b[-+]?[0-9]+.[0-9]+(|[eE][-+]?[0-9]+) [A-Za-z/*]+\\b'"); + output_message(" scope: constant"); + output_message(""); + output_message(" complex_units:"); + output_message(" - match: '\\b[-+]?[0-9]+.[0-9]+(|[eE][-+]?[0-9]+)[-+][0-9]+.[0-9]+(|[eE][-+]?[0-9]+)[ijrd] [A-Za-z/*]+\\b'"); + output_message(" scope: constant"); + output_message(""); + output_message(" dates:"); + output_message(" - match: '\\b[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9](|[A-Z]+)\\b'"); + output_message(" scope: constant"); + output_message(""); + output_message(" keywords:"); + output_message(" - match: '\\b[A-Z0-9_]+\\b'"); + output_message(" scope: constant"); + output_message(""); + output_message(" strings:"); + output_message(" # Strings begin and end with quotes, and use backslashes as an escape character."); + output_message(" - match: '\"'"); + output_message(" scope: punctuation.definition.string.begin"); + output_message(" push: inside_string"); + output_message(""); + output_message(" inside_string:"); + output_message(" - meta_include_prototype: false"); + output_message(" - meta_scope: string.quoted.double"); + output_message(" - match: '\\.'"); + output_message(" scope: constant.character.escape"); + output_message(" - match: '\"'"); + output_message(" scope: punctuation.definition.string.end"); + output_message(" pop: true"); + output_message(""); + output_message(" comments:"); + output_message(" # Comments begin with a '//' and finish at the end of the line."); + output_message(" - match: '//'"); + output_message(" scope: punctuation.definition.comment"); + output_message(" push:"); + output_message(" # This is an anonymous context push for brevity."); + output_message(" - meta_scope: comment.line.double-slash"); + output_message(" - match: $\\n?"); + output_message(" pop: true"); + output_message(""); +} \ No newline at end of file diff --git a/gldcore/load.h b/gldcore/load.h index 35d7ebe44..61cab7a58 100644 --- a/gldcore/load.h +++ b/gldcore/load.h @@ -388,6 +388,8 @@ class GldLoader const char *get_last_term(void); private: void inc_linenum() { linenum++; global_loader_linenum = linenum; }; +public: + void sublime_syntax(void); }; #endif diff --git a/utilities/Makefile.mk b/utilities/Makefile.mk new file mode 100644 index 000000000..d5893d616 --- /dev/null +++ b/utilities/Makefile.mk @@ -0,0 +1,8 @@ +SUBLIME_SYNTAX = $(HOME)/Library/Application\ Support/Sublime\ Text\ 3/Packages/User/GLM.sublime-syntax +SUBLIME_SOURCE = utilities/sublime/GLM.sublime-syntax + +sublime-syntax: $(SUBLIME_SYNTAX) + +$(SUBLIME_SYNTAX): gldcore/load.cpp + @echo "Updating sublime syntax" + @gridlabd --sublime_syntax > "$@" || echo "ERROR: you need to install sublime package manager first" diff --git a/utilities/sublime/README.md b/utilities/sublime/README.md deleted file mode 100644 index 3c345130c..000000000 --- a/utilities/sublime/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Sublime 3 for macOS - -You will need to install the Sublime package control to install on the GridLAB-D syntax file. See https://packagecontrol.io/installation for details. - -Then you can install the Sublime package development using `Tools`-->`Command Palette` and choosing `PackageDev`. - -Choose `Tools`-->`Packages`-->`Package Development`-->`Create Package` and input `GridLAB-D`. - -Copy the GLM syntax file `GridLAB-D.sublime-syntax` should be installed in `$HOME/Library/Application\ Support/Sublime\ Text\ 3/Packages/GridLAB-D/`. diff --git a/utilities/sublime/gridlabd.sublime-syntax b/utilities/sublime/gridlabd.sublime-syntax deleted file mode 100644 index 9d1de611b..000000000 --- a/utilities/sublime/gridlabd.sublime-syntax +++ /dev/null @@ -1,62 +0,0 @@ -%YAML 1.2 ---- -# See http://www.sublimetext.com/docs/3/syntax.html -name: gridlabd -file_extensions: - - glm -scope: source.glm - -contexts: - # The prototype context is prepended to all contexts but those setting - # meta_include_prototype: false. - prototype: - - include: comments - - main: - # The main context is the initial starting point of our syntax. - # Include other contexts from here (or specify them directly). - - include: keywords - - include: macros - - include: numbers - - include: strings - - macros: - - match: '\b(#)?[a-z]+\b' - scope: keyword.macro.glm - - keywords: - - match: '\b(clock|module|class|object|modify|global|filter|intrinsic|set)\b' - scope: keyword.directive.glm - - names: - - match: '\b[A-Za-z_]+[-A-Za-z_:.]\b' - scope: constant.name.glm - - numbers: - - match: '\b(-+)?[0-9.]+(|[eE](-+)?[0-9]+)\b' - scope: constant.numeric.glm - - strings: - # Strings begin and end with quotes, and use backslashes as an escape character. - - match: '"' - scope: punctuation.definition.string.begin.glm - push: inside_string - - inside_string: - - meta_include_prototype: false - - meta_scope: string.quoted.double.glm - - match: '\.' - scope: constant.character.escape.glm - - match: '"' - scope: punctuation.definition.string.end.glm - pop: true - - comments: - # Comments begin with a '//' and finish at the end of the line. - - match: '//' - scope: punctuation.definition.comment.glm - push: - # This is an anonymous context push for brevity. - - meta_scope: comment.line.double-slash.glm - - match: $\n? - pop: true