module lang::sdf2::\syntax::Sdf2
rascal-0.40.16
Usage
import lang::sdf2::\syntax::Sdf2;
syntax Sort
lexical Sort
= OneChar: [A-Z] !>> [A-Za-z0-9]
| MoreChars: ([A-Z] [A-Za-z0-9\-]* [A-Za-z0-9] !>> [A-Za-z0-9]) \ "LAYOUT"
;
syntax Syms
syntax Syms = Sym*;
syntax NatCon
lexical NatCon = Digits: [0-9]+ !>> [0-9];
syntax NumChar
lexical NumChar = Digits: [\\] [0-9]+ !>> [0-9];
syntax SDF
start syntax SDF = Definition: "definition" Definition def;
syntax Character
syntax Character
= Numeric: NumChar
| short: ShortChar
| top: "\\TOP"
| eof: "\\EOF"
| bot: "\\BOT"
| label_start: "\\LABEL_START"
;
syntax ShortChar
lexical ShortChar
= Regular: [a-zA-Z0-9]
| Escaped: [\\] ![A-Za-mo-qsu-z0-9] // -\0-\31
;
syntax Renaming
syntax Renaming = Sym: Sym "=\>" Sym |
production: Prod "=\>" Prod
;
syntax Renamings
syntax Renamings = Renamings: "[" Renaming* "]"
;
syntax IdCon
lexical IdCon = Default: [A-Za-z] [A-Za-z\-0-9]* !>> [A-Za-z\-0-9];
syntax Class
syntax Class
= SimpleCharClass: "[" Range* "]"
| \bracket: "(" Class ")"
| Comp: "~" Class
> Diff: Class "/" Class
> left ISect: Class "/\\" Class
> left Union: Class "\\/" Class
;
syntax Range
syntax Range
= Character
| Range: Character "-" Character
;
syntax Attribute
syntax Attribute = Id: "id" "(" ModuleName ")" |
Term: ATermAttribute |
Reject: "reject" |
Prefer: "prefer" |
Avoid: "avoid" |
Bracket: "bracket" |
Assoc: Assoc
;
syntax ATermAttribute
syntax ATermAttribute = Default: ATerm a
\ "reject"
\ "prefer"
\ "avoid"
\ "bracket"
;
syntax Attrs
syntax Attrs = Attrs: "{" {Attribute ","}* "}" |
NoAttrs:
;
syntax Prod
syntax Prod = Prod: Syms "-\>" Sym Attrs ;
syntax Prods
syntax Prods = Prod*;
syntax Grammar
syntax Grammar = Aliases: "aliases" Aliases |
Sorts: "sorts" Syms |
ImpSection: ImpSection |
Syntax: "syntax" Prods |
KernalStartSyms: "start-symbols" Syms |
Variables: "variables" Prods |
Priorities: "priorities" Priorities |
Restrictions: "restrictions" Restrictions |
LexicalSyntax: "lexical" "syntax" Prods |
LexicalStartSyms: "lexical" "start-symbols" Syms |
LexicalVariables: "lexical" "variables" Prods |
LexicalPriorities: "lexical" "priorities" Priorities |
LexicalRestrictions: "lexical" "restrictions" Restrictions |
ContextFreeSyntax: "context-free" "syntax" Prods |
ContextFreeStartSyms: "context-free" "start-symbols" Syms |
ContextFreePriorities: "context-free" "priorities" Priorities |
ContextFreeRestrictions: "context-free" "restrictions" Restrictions
;
syntax Label
syntax Label = Quoted: StrCon |
IdCon: IdCon
\ "left"
\ "right"
\ "assoc"
\ "non-assoc"
;
syntax Sym
syntax Sym = Sort: Sort |
Lit: StrCon |
CILit: SingleQuotedStrCon |
Class: Class |
Layout: "LAYOUT" |
Empty: "(" ")" |
Bracket: "(" Sym ")" |
Seq: "(" Sym Sym+ ")" |
Opt: Sym "?" |
Iter: Sym "+" |
IterStar: Sym "*" |
IterSep: "{" Sym Sym "}" "+" |
IterStarSep: "{" Sym Sym "}" "*" |
CF: "\<" Sym "-CF" "\>" |
Lex: "\<" Sym "-LEX" "\>" |
Varsym: "\<" Sym "-VAR" "\>" |
ParameterizedSort: Sort "[[" {Sym ","}+ "]]" >
right Alt: Sym "|" Sym >
Label: Label ":" Sym
;
syntax LAYOUTLIST
layout LAYOUTLIST = LAYOUT* !>> [\ \t\n\r%]
;
syntax LAYOUT
lexical LAYOUT = Whitespace: [\ \t\n\r] |
@category="Comment" Line: "%%" ![\n]* [\n] |
@category="Comment" Nested: "%" ![%\n] "%"
;
syntax Alias
syntax Alias = Alias: Sym "-\>" Sym
;
syntax Aliases
syntax Aliases = Alias*
;
syntax StrChar
lexical StrChar = NewLine: [\\] [n]
| Tab: [\\] [t]
| Quote: [\\] [\"]
| Backslash: [\\] [\\]
| Decimal: [\\] [0-9] [0-9] [0-9]
| Normal: ![\n\t\"\\]
;
syntax StrCon
lexical StrCon = Default: [\"] StrChar* [\"]
;
syntax FunctionName
syntax FunctionName = UnquotedFun: IdCon |
QuotedFun: StrCon
;
syntax SingleQuotedStrCon
lexical SingleQuotedStrCon = Default: [\'] SingleQuotedStrChar* [\']
;
syntax SingleQuotedStrChar
lexical SingleQuotedStrChar = NewLine: [\\] [n] |
Tab: [\\] [t] |
Quote: [\\] [\'] |
Backslash: [\\] [\\] |
Decimal: [\\] [0-9] [0-9] [0-9] |
Normal: ![\n\t\'\\]
;
syntax RealCon
syntax RealCon = RealCon: IntCon "." NatCon OptExp
;
syntax OptExp
syntax OptExp = Present: "e" IntCon |
Absent:
;
syntax Module
start syntax Module = Module: "module" ModuleName ImpSection* Sections
;
syntax ModuleName
syntax ModuleName = Unparameterized: ModuleId id
\ "aliases"
\ "lexical"
\ "priorities"
\ "context-free"
\ "definition"
\ "syntax"
\ "variables"
\ "module"
\ "imports"
\ "exports"
\ "hiddens"
\ "left"
\ "right"
\ "assoc"
\ "non-assoc"
\ "bracket"
\ "sorts"
\ "restrictions"
!>> [A-Za-z0-9_\-]
| Parameterized: ModuleId id "[" Syms actuals "]"
;
syntax ModuleWord
lexical ModuleWord = Word: [A-Za-z0-9_\-]+
!>> [A-Za-z0-9_\-]
;
syntax ModuleId
lexical ModuleId = Leaf: ModuleWord !>> [/] |
Root: "/" ModuleId |
Path: ModuleWord "/" ModuleId
;
syntax Import
syntax Import = Module: ModuleName |
RenamedModule: ModuleName Renamings |
Bracket: "(" Import ")"
;
syntax Imports
syntax Imports = Import*
;
syntax Section
syntax Section = Exports: "exports" Grammar* |
Hiddens: "hiddens" Grammar*
;
syntax Sections
syntax Sections = Section*
;
syntax ImpSection
syntax ImpSection = Imports: "imports" Imports
;
syntax Definition
syntax Definition = Module* modules
;
syntax Lookahead
syntax Lookahead
= Class: Class!bracket class
| Seq: Class class "." Lookaheads!alt las
;
syntax Lookaheads
syntax Lookaheads
= Single: Lookahead
| right alt: Lookaheads "|" Lookaheads
| Bracket: "(" Lookaheads ")"
| List: "[[" {Lookahead ","}* "]]"
;
syntax Restriction
syntax Restriction = Follow: Syms "-/-" Lookaheads
;
syntax Assoc
syntax Assoc = Left: "left" |
Right: "right" |
NonAssoc: "non-assoc" |
Assoc: "assoc"
;
syntax Restrictions
syntax Restrictions = Default: Restriction* ;
syntax ArgumentIndicator
syntax ArgumentIndicator = Default: "\<" {NatCon ","}+ "\>"
;
syntax Group
syntax Group = non-assoc WithArguments: Group ArgumentIndicator |
non-assoc NonTransitive: Group "." |
ProdsGroup: "{" Prods "}" |
AssocGroup: "{" Assoc ":" Prods "}" |
SimpleGroup: Prod
;
syntax Priority
syntax Priority = Chain: {Group "\>"}+ |
Assoc: Group Assoc Group
;
syntax Priorities
syntax Priorities = {Priority ","}*
;
syntax AFun
syntax AFun = Quoted: StrCon |
Unquoted: IdCon
\ "left"
\ "right"
\ "assoc"
\ "non-assoc"
;
syntax ATerm
syntax ATerm = Int: IntCon |
Real: RealCon |
Fun: AFun |
Appl: AFun "(" {ATerm ","}+ ")" |
Placeholder: "\<" ATerm "\>" |
List: "[" {ATerm ","}* "]" |
Annotated: ATerm Annotation
;
syntax Annotation
syntax Annotation = Default: "{" {ATerm ","}+ "}"
;
syntax IntCon
syntax IntCon = Natural: NatCon |
Positive: "+" NatCon |
Negative: "-" NatCon
;