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

code completion #7

Open
danieldroit opened this issue Feb 20, 2018 · 1 comment
Open

code completion #7

danieldroit opened this issue Feb 20, 2018 · 1 comment
Labels

Comments

@danieldroit
Copy link

I have the following grammar:

{
  "RegExpID": "RE::",
  "Style": {
    "string": "string",
    "this": "keyword",
    "operator": "operator",
    "regex": "string-2",
    "atom": "atom",
    "identifier": "variable",
    "keyword": "keyword",
    "number": "number",
    "property": "attribute",
    "date": "string-2",
    "comment": "comment",
    "builtin": "builtin"
  },
  "Lex": {
    "boolean": {
      "autocomplete": true,
      "tokens": [
        "true",
        "false"
      ]
    },
    "string": {
      "type": "escaped-block",
      "escape": "\\",
      "tokens": [
        "RE::/(['\"])/",
        1
      ]
    },
    "this": "RE::/this\\b/",
    "operator": {
      "tokens": [
        "+",
        "-",
        "++",
        "--",
        "%",
        ">>",
        "<<",
        ">>>",
        "*",
        "/",
        "^",
        "|",
        "&",
        "!",
        "~",
        ">",
        "<",
        "<=",
        ">=",
        "!=",
        "!==",
        "=",
        "==",
        "===",
        "+=",
        "-=",
        "%=",
        ">>=",
        ">>>=",
        "<<=",
        "*=",
        "/=",
        "|=",
        "&="
      ]
    },
    "regex": {
      "type": "escaped-block",
      "escape": "\\",
      "tokens": [
        "/",
        "RE::#/[gimy]{0,4}#"
      ]
    },
    "atom": {
      "autocomplete": true,
      "tokens": [
        "null",
        "undefined",
        "NaN",
        "Infinity"
      ]
    },
    "delimiter": {
      "tokens": [
        "(",
        ")",
        "[",
        "]",
        "{",
        "}",
        ",",
        "=",
        ";",
        "?",
        " ",
        "+=",
        "-=",
        "*=",
        "/=",
        "%=",
        "&=",
        "|=",
        "^=",
        "++",
        "--",
        ">>=",
        "<<="
      ]
    },
    "identifier": "RE::/[_A-Za-z$][_A-Za-z0-9$]*/",
    "keyword": {
      "autocomplete": true,
      "tokens": [
        "if",
        "while",
        "with",
        "else",
        "do",
        "try",
        "finally",
        "return",
        "break",
        "continue",
        "new",
        "delete",
        "throw",
        "var",
        "const",
        "let",
        "function",
        "catch",
        "void",
        "for",
        "switch",
        "case",
        "default",
        "class",
        "import",
        "yield",
        "in",
        "typeof",
        "instanceof"
      ]
    },
    "number": [
      "RE::/\\d*\\.\\d+(e[\\+\\-]?\\d+)?/",
      "RE::/\\d+\\.\\d*/",
      "RE::/\\.\\d+/",
      "RE::/0x[0-9a-fA-F]+L?/",
      "RE::/0b[01]+L?/",
      "RE::/0o[0-7]+L?/",
      "RE::/[1-9]\\d*(e[\\+\\-]?\\d+)?L?/",
      "RE::/0(?![\\dx])/"
    ],
    "property": "RE::/[_A-Za-z$][_A-Za-z0-9$]*/",
    "date": "RE::/\\d{4}-\\d{2}-\\d{2}$]*/",
    "comment": {
      "type": "comment",
      "tokens": [
        [
          ";",
          "null"
        ],
        [
          "/*",
          "*/"
        ]
      ]
    },
    "builtin": {
      "autocomplete": true,
      "tokens": [
        "Object",
        "Function",
        "Array",
        "String",
        "Date",
        "Number",
        "RegExp",
        "Math",
        "Exception",
        "setTimeout",
        "setInterval",
        "parseInt",
        "parseFloat",
        "isFinite",
        "isNan",
        "alert",
        "prompt",
        "console",
        "window",
        "global",
        "this"
      ]
    }
  },
  "Syntax": {
    "json": "object | array | prim",
    "object": "'{' kv (',' kv)* '}'",
    "js": "comment | number | string | regex | keyword | operator | atom | (('}' | ')' | this | builtin | identifier | dot_property) dot_property*)",
    "kv": {
      "sequence": [
        "string",
        "':'",
        "json"
      ]
    },
    "top": "query",
    "prim": "number | string | boolean",
    "query": "'{' '\"query\"'    ':' string ',' '\"where\"' ':' criteria '}'",
    "operand": "identifier | date | string | number | boolean",
    "operator2": "'\"=\"' | '\">\"' | '\">=\"' | '\"<\"' | '\"<=\"'",
    "or" :          "\"or\" (',' criteria)+",
    "and":          "\"and\" (',' criteria)+",
    "criteria": "'[' (or | and | relation)    ']'",
    "dot_property": {
      "sequence": [
        ".",
        "property"
      ]
    },
    "array": "'[' json (',' json)* ']'",
    "relation": "'[' operator2 ',' operand ',' operand ']'"
  },
  "Parser": [
    [
      "top"
    ]
  ]
}

When I paste it to the grammar editor on http://foo123.github.io/examples/codemirror-grammar/ and clean the code editor the Ctrl+SPACE suggest true | false which is not valid language according to grammar as it must start with {.
Furthermore, if I type { and then Ctrl+SPACE it correctly suggests "query" but when I subsequently use Ctrl+SPACE instead of : or : " it suggests "where" which again results in incorrect syntax.

Please advise whether it is a bug or I'm doing something wrong.
Many thanks for your work.

@foo123
Copy link
Owner

foo123 commented Feb 20, 2018

If i am not mistaken, the tokens '{', '}', ':' are NOT marked as tokens for autocompletion, so they are skipped in the autocomplete suggest functionality. if you necessarily need these to be autocompleted try to insert them as separete tokens in LEX and mark them as autocomplete. Let me know how it goes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants