Advertisement
Guest User

Untitled

a guest
Nov 9th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 2.39 KB | None | 0 0
  1. module metac.parser.ast.nodes;
  2.  
  3. import metac.parser.ast : IAstNode, TAstNode;
  4. import metac.parser.ast.rules;
  5. import std.container.array : Array;
  6. import std.traits : getSymbolsByUDA;
  7. import std.meta : AliasSeq;
  8.  
  9. alias AllNodes = getSymbolsByUDA!(metac.parser.ast.nodes, IAstNode);
  10.  
  11. interface IIntegerLiteral : IAstNode {
  12. }
  13.  
  14. @IAstNode:
  15.  
  16. class HexIntegerLiteral : TAstNode!HexIntegerLiteral, IIntegerLiteral {
  17.     alias syntax = Seq!(Str!"0x", Plus!Hex, NotAt!Alnum);
  18.     @Pop string digits;
  19. }
  20.  
  21. class BinIntegerLiteral : TAstNode!BinIntegerLiteral, IIntegerLiteral {
  22.     alias syntax = Seq!(Str!"0b", Plus!Binary);
  23.     @Pop string digits;
  24. }
  25.  
  26. class OctIntegerLiteral : TAstNode!OctIntegerLiteral, IIntegerLiteral {
  27.     alias syntax = Seq!(Str!"0", Plus!Octal);
  28.     @Pop string digits;
  29. }
  30.  
  31. class DecIntegerLiteral : TAstNode!DecIntegerLiteral, IIntegerLiteral {
  32.     alias syntax = Plus!Digit;
  33.     @Pop string digits;
  34. }
  35.  
  36. class IntegerLiteral : TAstNode!IntegerLiteral {
  37.     alias syntax = Sor!(HexIntegerLiteral, BinIntegerLiteral,
  38.             OctIntegerLiteral, DecIntegerLiteral);
  39.     @Pop IIntegerLiteral digits;
  40. }
  41.  
  42. class BasicType : TAstNode!BasicType {
  43.     alias syntax = SorString!("void", "half", "float", "double", "byte", "ubyte",
  44.             "short", "ushort", "int", "uint", "long", "ulong", "char", "wchar", "dchar");
  45.     @Pop string name;
  46. }
  47.  
  48. class Identifier : TAstNode!Identifier {
  49.     alias syntax = Seq!(Alpha, Star!(Alnum));
  50.     @Pop string identifier;
  51. }
  52.  
  53. class QualifiedIdentifier : TAstNode!QualifiedIdentifier {
  54.     alias syntax = Seq!(Identifier, Star!(Sep, Str!".", Sep, Identifier));
  55.     @Pop Array!Identifier identifiers;
  56. }
  57.  
  58. class Type : TAstNode!Type {
  59.     alias syntax = Sor!(BasicType, QualifiedIdentifier);
  60.     @Pop IAstNode element;
  61. }
  62.  
  63. class VariableDeclaration : TAstNode!VariableDeclaration {
  64.     alias syntax = Seq!(Type, Space, Identifier);
  65.     @Pop Type type;
  66.     @Pop Identifier identifier;
  67. }
  68.  
  69. class UnitHeader : TAstNode!UnitHeader {
  70.     alias syntax = Seq!(Str!"unit", Space, QualifiedIdentifier, Sep, Str!";");
  71.     @Pop QualifiedIdentifier identifier;
  72. }
  73.  
  74. class UnitBody : TAstNode!UnitBody {
  75.     alias syntax = Star!(Sep, IntegerLiteral);
  76.     @Pop Array!IAstNode children;
  77. }
  78.  
  79. class Unit : TAstNode!Unit {
  80.     alias syntax = Seq!(BoF, Sep, UnitHeader, Sep, UnitBody, Sep, EoF);
  81.     @Pop UnitHeader header;
  82.     @Pop UnitBody body;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement