/
Root.sv
67 lines (55 loc) · 2.37 KB
/
Root.sv
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
grammar silver:compiler:definition:core;
{--
- Root represents one textual file of Silver source.
-}
tracked nonterminal Root with
-- Global-level inherited attributes
config, compiledGrammars,
-- Grammar-level inherited attributes
grammarName, env, globalImports, grammarDependencies,
-- File-level inherited attributes
-- Synthesized attributes
declaredName, unparse, errors, defs, occursDefs, moduleNames, importedDefs, importedOccursDefs,
exportedGrammars, optionalGrammars, condBuild, jarName;
flowtype Root = decorate {config, compiledGrammars, grammarName, env, globalImports, grammarDependencies, flowEnv};
tracked nonterminal GrammarDcl with
declaredName, grammarName, unparse, errors;
propagate errors on Root, GrammarDcl;
propagate config, compiledGrammars, grammarName, globalImports, grammarDependencies, moduleNames on Root;
concrete production root
top::Root ::= gdcl::GrammarDcl ms::ModuleStmts ims::ImportStmts ags::AGDcls
{
top.unparse = gdcl.unparse ++ "\n\n" ++ ms.unparse ++ "\n\n" ++ ims.unparse ++ "\n\n" ++ ags.unparse;
top.declaredName = gdcl.declaredName;
top.defs := ags.defs;
top.occursDefs := ags.occursDefs;
top.importedDefs := ms.defs;
top.importedOccursDefs := ms.occursDefs;
top.exportedGrammars := ms.exportedGrammars;
top.optionalGrammars := ms.optionalGrammars;
top.condBuild := ms.condBuild;
top.jarName := ags.jarName;
-- We have an mismatch in how the environment gets put together:
-- Outermost, we have grammar-wide imports in one scope. That's top.globalImports here.
-- THEN, we have this particular file's list of local imports. That's ims.defs here.
-- THEN, we have the grammar-wide definitions, from the whole grammr. That's top.env here.
-- So we're kind of injecting local imports in between two grammar-wide things there.
ags.env = appendEnv(top.env, newScopeEnv(ims.defs, occursEnv(ims.occursDefs, top.globalImports)));
}
concrete production noGrammarDcl
top::GrammarDcl ::=
{
top.unparse = "";
top.declaredName = top.grammarName;
}
concrete production grammarDcl_c
top::GrammarDcl ::= 'grammar' qn::QName ';'
{
top.unparse = "grammar " ++ qn.unparse ++ ";";
top.declaredName = qn.name;
top.errors <-
if qn.name == top.grammarName then []
else [errFromOrigin(top, "Grammar declaration is incorrect: " ++ qn.name)];
} action {
insert semantic token IdGrammarName_t at qn.nameLoc;
}