forked from russlank/lang-forge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvehicle.lf
More file actions
104 lines (97 loc) · 3.5 KB
/
Copy pathvehicle.lf
File metadata and controls
104 lines (97 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
%target cpp
%package LangForge::Examples::VehicleReport::Generated
%semantic cpp mode reducer
%semantic cpp type Program std::nullptr_t
%semantic cpp type VehicleInfo std::nullptr_t
%semantic cpp type ModelField std::nullptr_t
%semantic cpp type LicenseField std::nullptr_t
%semantic cpp type DistanceField std::nullptr_t
%semantic cpp type FeaturesField std::nullptr_t
%semantic cpp type FeatureItems std::nullptr_t
%semantic cpp type FeatureTail std::nullptr_t
%semantic cpp type Feature std::nullptr_t
%semantic cpp type RepairsField std::nullptr_t
%semantic cpp type RepairItems std::nullptr_t
%semantic cpp type RepairTail std::nullptr_t
%semantic cpp type Repair std::nullptr_t
%start Program
%token Car Model License Distance Features Repairs Date Description Ident Number String LicenseString DateString Assign Comma LBrace RBrace LParen RParen
%% lexer
DIGIT = [0-9];
LETTER = [A-Za-z];
IDENT = [A-Za-z_] ( [A-Za-z0-9_] | "-" )*;
NUMBER = DIGIT+;
LICENSE_STRING = \" DIGIT+ "-" ( [A-Za-z0-9_] | "-" )+ \";
DATE_STRING = \" [0-3] DIGIT "-" [0-1] DIGIT "-" DIGIT DIGIT DIGIT DIGIT \";
STRING = \" ( [1-33] | [35-91] | [93-127] )* \";
LINE_COMMENT = "//" ( [1-9] | [11-12] | [14-127] )*;
"car" => token(Car);
"model" => token(Model);
"license" => token(License);
"distance" => token(Distance);
"features" => token(Features);
"repairs" => token(Repairs);
"reparations" => token(Repairs);
"date" => token(Date);
"description" => token(Description);
"=" => token(Assign);
"," => token(Comma);
"{" => token(LBrace);
"}" => token(RBrace);
"(" => token(LParen);
")" => token(RParen);
DATE_STRING => token(DateString);
LICENSE_STRING => token(LicenseString);
STRING => token(String);
NUMBER => token(Number);
IDENT => token(Ident);
LINE_COMMENT => skip;
[1-32]+ => skip;
%% parser
Program : Car Assign LBrace info=VehicleInfo RBrace
{cpp: vehicle}
;
VehicleInfo : model=ModelField Comma license=LicenseField Comma distance=DistanceField Comma features=FeaturesField Comma repairs=RepairsField
{cpp: info}
;
ModelField : Model Assign literal=String
{cpp: field.model}
;
LicenseField : License Assign literal=LicenseString
{cpp: field.license}
;
DistanceField : Distance Assign literal=Number
{cpp: field.distance}
;
FeaturesField : Features Assign LBrace items=FeatureItems RBrace
{cpp: field.features}
;
FeatureItems : head=Feature tail=FeatureTail
{cpp: feature.items}
| %empty
{cpp: feature.empty}
;
FeatureTail : Comma head=Feature tail=FeatureTail
{cpp: feature.tail.more}
| %empty
{cpp: feature.tail.empty}
;
Feature : name=Ident Assign value=String
{cpp: feature}
;
RepairsField : Repairs Assign LBrace items=RepairItems RBrace
{cpp: field.repairs}
;
RepairItems : head=Repair tail=RepairTail
{cpp: repair.items}
| %empty
{cpp: repair.empty}
;
RepairTail : Comma head=Repair tail=RepairTail
{cpp: repair.tail.more}
| %empty
{cpp: repair.tail.empty}
;
Repair : LParen Date Assign date=DateString Comma Description Assign description=String RParen
{cpp: repair}
;