Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add highlighting support for Single-Assignment C #4625

Merged
merged 1 commit into from Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
75 changes: 75 additions & 0 deletions demo/kitchen-sink/docs/sac.sac
@@ -0,0 +1,75 @@
/*****************************************************************************
*
* SAC demo program
*
* This SAC demo program implements 2-dimensional relaxation on double
* precision floating point numbers applying a 4-point stencil and fixed
* boundary conditions.
*
* The vertical (SIZE1) and the horizontal (SIZE2) array size as well as
* the number of iterations to be performed (LOOP) may be set at compile
* time.
*
*****************************************************************************/

#ifndef LOOP
#define LOOP 100
#endif

#ifndef SIZE1
#define SIZE1 1000
#endif

#ifndef SIZE2
#define SIZE2 1000
#endif

use Array: all;
use StdIO: all;

inline
double[+] onestep(double[+] B)
{
A = with {
( . < x < . ) : 0.25*(B[x+[1,0]]
+ B[x-[1,0]]
+ B[x+[0,1]]
+ B[x-[0,1]]);
} : modarray( B );

return(A);
}

inline
double[+] relax(double[+] A, int steps)
{
for (k=0; k<steps; k++) {
A = onestep(A);
}

return(A);
}

int main ()
{
A = with {
( . <= x <= . ) : 0.0d;
} : genarray( [SIZE1,SIZE2] );

A = modarray(A, [0,1], 500.0d);
A = relax( A, LOOP);

z = with {
( 0*shape(A) <= x < shape(A) ) : A[x];
} : fold( +, 0d );

#if 0
printf("%.10g\n", z);
return(0);
#else
print( z);
return( 0);
#endif
}


1 change: 1 addition & 0 deletions lib/ace/ext/modelist.js
Expand Up @@ -171,6 +171,7 @@ var supportedModes = {
RST: ["rst"],
Ruby: ["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"],
Rust: ["rs"],
SaC: ["sac"],
SASS: ["sass"],
SCAD: ["scad"],
Scala: ["scala|sbt"],
Expand Down
23 changes: 23 additions & 0 deletions lib/ace/mode/sac.js
@@ -0,0 +1,23 @@
define(function(require, exports, module) {
"use strict";

var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var SaCHighlightRules = require("./sac_highlight_rules").sacHighlightRules;
var FoldMode = require("./folding/cstyle").FoldMode;

var Mode = function() {
this.HighlightRules = SaCHighlightRules;
this.foldingRules = new FoldMode();
this.$behaviour = this.$defaultBehaviour;
};
oop.inherits(Mode, TextMode);

(function() {
this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};
this.$id = "ace/mode/sac";
}).call(Mode.prototype);

exports.Mode = Mode;
});
193 changes: 193 additions & 0 deletions lib/ace/mode/sac_highlight_rules.js
@@ -0,0 +1,193 @@
define(function(require, exports, module) {
"use strict";

var oop = require("../lib/oop");
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;

var sacHighlightRules = function() {

var keywordControls = (
"break|continue|do|else|for|if|" +
"return|with|while|use|class|all|void"
);

var storageType = (
"bool|char|complex|double|float|" +
"byte|int|short|long|longlong|" +
"ubyte|uint|ushort|ulong|ulonglong|" +
"struct|typedef"
);

var storageModifiers = (
"inline|external|specialize"
);

var keywordOperators = (
"step|width"
);

var builtinConstants = (
"true|false"
);

var keywordMapper = this.$keywords = this.createKeywordMapper({
"keyword.control" : keywordControls,
"storage.type" : storageType,
"storage.modifier" : storageModifiers,
"keyword.operator" : keywordOperators,
"constant.language": builtinConstants
}, "identifier");

var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b";
var escapeRe = /\\(?:['"?\\abfnrtv]|[0-7]{1,3}|x[a-fA-F\d]{2}|u[a-fA-F\d]{4}U[a-fA-F\d]{8}|.)/.source;
var formatRe = "%"
+ /(\d+\$)?/.source // field (argument #)
+ /[#0\- +']*/.source // flags
+ /[,;:_]?/.source // separator character (AltiVec)
+ /((-?\d+)|\*(-?\d+\$)?)?/.source // minimum field width
+ /(\.((-?\d+)|\*(-?\d+\$)?)?)?/.source // precision
+ /(hh|h|ll|l|j|t|z|q|L|vh|vl|v|hv|hl)?/.source // length modifier
+ /(\[[^"\]]+\]|[diouxXDOUeEfFgGaACcSspn%])/.source; // conversion type

// regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used

this.$rules = {
"start" : [
{
token : "comment",
regex : "//$",
next : "start"
}, {
token : "comment",
regex : "//",
next : "singleLineComment"
},
DocCommentHighlightRules.getStartRule("doc-start"),
{
token : "comment", // multi line comment
regex : "\\/\\*",
next : "comment"
}, {
token : "string", // character
regex : "'(?:" + escapeRe + "|.)?'"
}, {
token : "string.start",
regex : '"',
stateName: "qqstring",
next: [
{ token: "string", regex: /\\\s*$/, next: "qqstring" },
{ token: "constant.language.escape", regex: escapeRe },
{ token: "constant.language.escape", regex: formatRe },
{ token: "string.end", regex: '"|$', next: "start" },
{ defaultToken: "string"}
]
}, {
token : "string.start",
regex : 'R"\\(',
stateName: "rawString",
next: [
{ token: "string.end", regex: '\\)"', next: "start" },
{ defaultToken: "string"}
]
}, {
token : "constant.numeric", // hex
regex : "0[xX][0-9a-fA-F]+(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
}, {
token : "constant.numeric", // float
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
}, {
token : "keyword", // pre-compiler directives
regex : "#\\s*(?:include|import|pragma|line|define|undef)\\b",
next : "directive"
}, {
token : "keyword", // special case pre-compiler directive
regex : "#\\s*(?:endif|if|ifdef|else|elif|ifndef)\\b"
}, {
token : "support.function",
regex : "fold|foldfix|genarray|modarray|propagate"
}, {
token : keywordMapper,
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*"
}, {
token : "keyword.operator",
regex : /--|\+\+|<<=|>>=|>>>=|<>|&&|\|\||\?:|[*%\/+\-&\^|~!<>=]=?/
}, {
token : "punctuation.operator",
regex : "\\?|\\:|\\,|\\;|\\."
}, {
token : "paren.lparen",
regex : "[[({]"
}, {
token : "paren.rparen",
regex : "[\\])}]"
}, {
token : "text",
regex : "\\s+"
}
],
"comment" : [
{
token : "comment", // closing comment
regex : "\\*\\/",
next : "start"
}, {
defaultToken : "comment"
}
],
"singleLineComment" : [
{
token : "comment",
regex : /\\$/,
next : "singleLineComment"
}, {
token : "comment",
regex : /$/,
next : "start"
}, {
defaultToken: "comment"
}
],
"directive" : [
{
token : "constant.other.multiline",
regex : /\\/
},
{
token : "constant.other.multiline",
regex : /.*\\/
},
{
token : "constant.other",
regex : "\\s*<.+?>",
next : "start"
},
{
token : "constant.other", // single line
regex : '\\s*["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]',
next : "start"
},
{
token : "constant.other", // single line
regex : "\\s*['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']",
next : "start"
},
// "\" implies multiline, while "/" implies comment
{
token : "constant.other",
regex : /[^\\\/]+/,
next : "start"
}
]
};

this.embedRules(DocCommentHighlightRules, "doc-",
[ DocCommentHighlightRules.getEndRule("start") ]);
this.normalizeRules();
};

oop.inherits(sacHighlightRules, TextHighlightRules);

exports.sacHighlightRules = sacHighlightRules;
});