GithubHelp home page GithubHelp logo

foo123 / ace-grammar Goto Github PK

View Code? Open in Web Editor NEW
35.0 7.0 8.0 5.88 MB

Transform a JSON grammar into a syntax-highlight parser for ACE Editor

Home Page: https://foo123.github.io/examples/ace-grammar/

JavaScript 98.61% HTML 1.30% Batchfile 0.08%
bnf peg ace-editor grammar-parser syntax-highlighter

ace-grammar's People

Contributors

foo123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ace-grammar's Issues

Ace ``window`` (Global Object) is Not Defined When Using ``editor.session.setMode()``

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

Capture

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?

How would I use this to verify variables match up with data types?

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.

Minimize the Grammar JSON by Adding ``style`` Property or Using Annotated Inside Token_ID as Style to Lex Object

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!

License missing

What's the license to use and extend this project (it works great, by the way)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.