foo123 / ace-grammar Goto Github PK
View Code? Open in Web Editor NEWTransform a JSON grammar into a syntax-highlight parser for ACE Editor
Home Page: https://foo123.github.io/examples/ace-grammar/
Transform a JSON grammar into a syntax-highlight parser for ACE Editor
Home Page: https://foo123.github.io/examples/ace-grammar/
My App has a few grammar modes defined in global vars:
var ins_mode = AceGrammar.getMode({
"RegExpID": "RE::",
"Style": {
//...
});
var ycd_mode = AceGrammar.getMode({
"RegExpID": "RE::",
"Style": {
//...
});
var aoi3_mode = AceGrammar.getMode({
"RegExpID": "RE::",
"Style": {
//...
});
var mmd_mode = AceGrammar.getMode({
"RegExpID": "RE::",
"Style": {
//...
});
When I try to set the editor to a different mode, ace.js
gave me this error:
let modeStr = getMode() //This return either "ins_mode", "ycd_mode" ... in string
myAceEditor.session.setMode(window[modeStr]);
ace.js?nocache=nonce_1_1657893450835_623:11570
Uncaught ReferenceError: window is not defined
at ace.js?nocache=nonce_1_1657893450835_623:11570:5
at ace.js?nocache=nonce_1_1657893450835_623:11585:3
(anonymous) @ ace.js?nocache=nonce_1_1657893450835_623:11570
(anonymous) @ ace.js?nocache=nonce_1_1657893450835_623:11585
I think it is because I pass global value to the editor.session.setMode()
, and somehow it would mess with ace.js
window global object.
Is there anyway that I can set editor to a different AceGrammar
mode without produce this error?
My use case is as such. Given a json schema of some (static, pre-defined) variable names and what types of data they can contain (floats, strings, ints, bools), I need to have ace show the user that assigning an int to a string-type variable is wrong.
I am currently parsing the json and adding identifiers to the lexer with a regex showing options of specific variable names like so:
"Lex" :
"identifier_float" : "R::/(x1|xn|y1|yn|z1|zn|grid_motion_rate|pert_rms|pert_peak|pert_band|TKE)/"
And in the syntax part I state that the correct syntax for float-type variables is:
"Syntax":
"literal_property_float" : "(identifier_float) '=' (float | number)"
(where float and number are defined in Lex)
Ace seems to understand that I require '=' and then a float/number, but it doesn't recognize the identifier_float
name requirement.
How do I use ace-grammar to have Ace understand that a given variable name has a given data-type requirement?
If this isn't the correct place to ask a question, please point me in the right direction.
It would be nice to publish your library for easy use.
Since the Style Model
seems a bit... plain, so I think you could make it as optional by adding the style
property to the Lex Model.
So instead of:
{
"Style": {
"identifier": "style1",
"property": "style2"
},
"Lex": {
"identifier": {"tokens": ["key1", "key2"]},
"property": {
"extend": "identifier"
}
}
}
Do this...
{
//No need `Style` now...
"Lex": {
"identifier": {"style": "style1", "tokens": ["key1", "key2"]},
"property:style2": { //<= Maybe like this
"extend": "identifier"
},
"property:block:style2": { //<= Or make the `style` value as the third anotation?
"extend": "identifier"
}
}
}
This is just an idea. Do you think if it is possible?
Thanks for the great extension!
What's the license to use and extend this project (it works great, by the way)?
It would make simpler contribution, versioning and publishing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.