Created
June 8, 2018 11:54
-
-
Save miho/dc6193f3b11c78f5ed320fa4130b1dd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar org.xtext.example.mydsl.take1.MyDsl with org.eclipse.xtext.common.Terminals | |
generate myDsl "http://www.xtext.org/example/mydsl/take1/MyDsl" | |
Json: value=Val; | |
Obj: | |
'{' | |
pairs+=Pair (',' pairs+=Pair)* | |
'}' | |
| | |
'{' '}' | |
; | |
Pair: | |
key=STRING ':' value=Val; | |
Val: ObjectValue | StringValue | ArrayValue | BooleanValue | NullValue | NumberValue; | |
Array: | |
'[' values+=Val (',' values+=Val)* ']' | |
| | |
'[' ']' | |
; | |
StringValue: | |
value=STRING; | |
ObjectValue: | |
value=Obj; | |
BooleanValue: | |
value='true' | value='false'; | |
NullValue: | |
'null'; | |
NumberValue: | |
value=Number; | |
ArrayValue: | |
value=Array; | |
terminal Number: | |
'-'? INT ('.' INT)? (('E'|'e') '-'? INT)?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Setup and serializer | |
this.injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration(); | |
this.serializer = injector.getInstance(Serializer.class); | |
// parsing is done via | |
IParser parser = injector.getInstance(IParser.class); | |
IParseResult result = parser.parse(new StringReader(input)); | |
// serialization is done via | |
String code = serializer.serialize(object); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment