Skip to main content

module examples::ql::Syntax

rascal-0.34.0
typepal-0.8.10

Usage

import examples::ql::Syntax;

Source code

http://github.com/usethesource/typepal/src/examples/ql/Syntax.rsc

syntax Form

start syntax Form
= form: "form" Id name "{" Question* questions "}"
;

syntax Question

syntax Question
= question: Label label Var var ":" Type type Value? value
| computed: Label label Var var ":" Type type "=" Expr expr Value? value
| ifThen: "if" "(" Expr cond ")" Question () !>> "else"
| ifThenElse: "if" "(" Expr cond ")" Question question "else" Question elseQuestion
| @Foldable group: "{" Question* questions "}"
| @Foldable @category="Comment" invisible: "(" Question* questions ")"
;

syntax Value

syntax Value
= "[" Const "]"
;

syntax Const

syntax Const
= @category="MetaAmbiguity" Expr!var!not!mul!div!add!sub!lt!leq!gt!geq!eq!neq!and!or
;

syntax Expr

syntax Expr
= var: Id name
| integer: Integer
| string: String
| money: Money
| boolean: Boolean
| bracket "(" Expr ")"
> not: "!" Expr
> left (
mul: Expr "*" Expr
| div: Expr "/" Expr
)
> left (
add: Expr "+" Expr
| sub: Expr "-" Expr
)
> non-assoc (
lt: Expr "\<" Expr
| leq: Expr "\<=" Expr
| gt: Expr "\>" Expr
| geq: Expr "\>=" Expr
| eq: Expr "==" Expr
| neq: Expr "!=" Expr
)
> left and: Expr "&&" Expr
> left or: Expr "||" Expr
;

syntax Keywords

keyword Keywords = "true" | "false" ;

syntax Var

lexical Var = Id;

syntax Label

lexical Label = @category="Constant" label: String;

syntax Type

syntax Type
= "boolean"
| "string"
| "integer"
| "money"
;

syntax String

lexical String = [\"] StrChar* [\"];

syntax StrChar

lexical StrChar
= ![\"\\]
| [\\][\\\"nfbtr]
;

syntax Boolean

lexical Boolean = "true" | "false";

syntax Integer

lexical Integer =  [\-]? [0-9]+ !>> [0-9];

syntax Money

lexical Money =  [\-]? [0-9]+ "." [0-9]* !>> [0-9] ;

syntax Standard

layout Standard = WhitespaceOrComment* !>> [\ \t\n\f\r] !>> "//" !>> "/*";

syntax Comment

syntax Comment 
= LineComment
| CStart CommentChar* CEnd
;

syntax LineComment

lexical LineComment
= @category="Comment" "//" ![\n\r]* $;

syntax CStart

syntax CStart = @category="Comment" "/*";

syntax CEnd

syntax CEnd = @category="Comment" "*/";

syntax CommentChar

syntax CommentChar 
= @category="Comment" ![*{}\ \t\n\f\r]
| @category="Comment" [*] !>> [/]
| Embed
;

syntax Embed

syntax Embed
= "{" Expr expr "}"
;

syntax WhitespaceOrComment

syntax WhitespaceOrComment 
= whitespace: Whitespace
| comment: Comment
;

syntax Whitespace

lexical Whitespace 
= [\u0009-\u000D \u0020 \u0085 \u00A0 \u1680 \u180E \u2000-\u200A \u2028 \u2029 \u202F \u205F \u3000]
;

syntax Id

lexical Id 
= ([a-z A-Z 0-9 _] !<< [a-z A-Z][\-a-z A-Z 0-9 _]* !>> [a-z A-Z 0-9 _]) \ Keywords
;