Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Develop fix sublime syntax (#1074)
Browse files Browse the repository at this point in the history
* Create Makefile.mk

* Update Makefile.am

* Update syntax for sublime

* Add support for generating sublime syntax file

* Remove static sublime syntax files

* Update load.cpp

* Create Sublime_syntax.md
  • Loading branch information
David P. Chassin authored Jan 13, 2022
1 parent 29b9270 commit 5a127ba
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 75 deletions.
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions docs/Command/Sublime_syntax.md
Original file line number Diff line number Diff line change
@@ -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
~~~
11 changes: 9 additions & 2 deletions gldcore/cmdarg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2256,15 +2256,21 @@ 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 */
/* Then make the appropriate entry in the */
/* CMDARG structure below */
/*********************************************/

#include "job.h"
#include "validate.h"

DEPRECATED static CMDARG main_commands[] = {

/* NULL,NULL,NULL,NULL, "Section heading */
Expand Down Expand Up @@ -2322,6 +2328,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" },
Expand Down
110 changes: 109 additions & 1 deletion gldcore/load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -8667,3 +8667,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("");
}
2 changes: 2 additions & 0 deletions gldcore/load.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ class GldLoader
const char *get_last_term(void);
private:
void inc_linenum() { linenum++; global_loader_linenum = linenum; };
public:
void sublime_syntax(void);
};

#endif
8 changes: 8 additions & 0 deletions utilities/Makefile.mk
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 0 additions & 9 deletions utilities/sublime/README.md

This file was deleted.

62 changes: 0 additions & 62 deletions utilities/sublime/gridlabd.sublime-syntax

This file was deleted.

0 comments on commit 5a127ba

Please sign in to comment.