xtext - How to simulate a user's input (only internally)? -


i need parse during runtime of eclipse plugin (created xtext) treated if user has typed in without popping , beeing visible user input of himself.
exmample have input:

for "i" 1 3 {}; 

my problem woth input variable not declared normal declaration "=" need parser tell one. want let parser parse

i = 1; 

so recognizes normal declaration , allows cross-references it.

greeting krzmbrzl

edit:
in thing want add statement i=1; ast

i want have eclipse support existing language i'm not writing interpreter nor generator. problem when have for-loop above actual interpreter of language declares variable (or it's named in loop header) , therefore variable available in loop body. in case parser doesn't recognise variable because knows declaration done via "=" can't use in loop body (if try error declaration cannot resolved). why want add declaration manually when such loop created. don't need worry compiling or interpreting difficulties because don't myself. said want have cool eclipse features language.

ok, understand problem. still no idea add element ast resolve cross reference! don't that! instead should try refactor grammar in way "i" in for "i" ... compatible declaration of variable. there several tricks that. have read xtext documentation? have read xtext book? both documents tell lot how make xtext things not expect.

anyway, 2 tricks use are:

  1. introduce unused, abstract parser rule can use destination of cross reference, never used attribute (containment reference).

    abstractdecl:     vardecl | forvardecl; vardecl:     name=id ...; forvardecl:     '"' name=id '"'; for:     'for' decl=forvardecl 'from' from=int 'to' to=int 'do' block=block; ... statementwithcr:     ref=[abstractdecl] ...; 
  2. define parserrule, returns other type.

    fordecl returns vardecl:      '"' name=id '"'; 

if post grammar corresponds specific problem, develop solution safe. adding ast during live processing content of editor lead faulty state can destroy document.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -