Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 138 lines (113 sloc) 3.594 kB
71f331d @sorear [v6] Conceptually translate Niecza::Frontend::STD
authored
1 class NieczaFrontendSTD;
2
3 use STD;
4 use Stash;
5 use NieczaGrammar;
6 use NieczaActions;
7
8 use MONKEY_TYPING;
9 augment class Match {
10 method CURSOR() { Q:CgOp { (ns (rawcall UnMatch (cast cursor (@ {self})))) } }
11 method cursor() { Q:CgOp { (ns (rawcall UnMatch (cast cursor (@ {self})))) } }
12 method reduced() { Q:CgOp { (box Str (rawcall Reduced (cast cursor (@ {self})))) } }
13 method trim_heredoc () { self } # NYI
14 }
15
16 augment class STD {
17 our $ALL;
18
19 method lineof ($p) {
20 return 1 unless defined $p;
21 my $line = @*LINEMEMOS[$p];
22 return $line if $line;
23 $line = 1; my $pos = 0;
24 my $lm = @*LINEMEMOS;
25 self.orig ~~ / :r [ \n { $lm[$pos++] = $line++ } ||
26 . { $lm[$pos++] = $line } ]* /;
27 $lm[$pos++] = $line;
28 return $lm[$p] // 0;
29 }
30
31 method lookup_dynvar($name) { Any } # NYI
32 method check_old_cclass($text) { } # NYI
33 method do_use($module,$args) {
34 self.do_need($module);
35 self.do_import($module,$args);
36 self;
37 }
38
39 method do_need($mo) {
40 my $module = $mo.Str;
41 my $topsym;
ad19fad @sorear [v6] First port of NieczaCompiler
authored
42 $topsym = self.sys_load_modinfo($module);
43 if !defined $topsym {
71f331d @sorear [v6] Conceptually translate Niecza::Frontend::STD
authored
44 self.panic("Could not load $module");
45 }
46 self.add_my_name($module);
47 $*DECLARAND<really> = $topsym;
48 self;
49 }
50
51 method sys_load_modinfo($module) {
52 # These are handled within the grammar
53 if $module eq 'MONKEY_TYPING' || $module eq 'lib' ||
54 $module eq 'fatal' {
55 return { };
56 }
57 $*module_loader.($module).create_syml;
58 }
59
60 method load_lex($setting) {
61 if $setting eq 'NULL' {
62 my $id = "MY:file<NULL.pad>:line(1):pos(0)";
63 my $core = Stash.new('!id' => [$id], '!file' => 'NULL.pad',
64 '!line' => 1);
65 return Stash.new('CORE' => $core, 'MY:file<NULL.pad>' => $core,
66 'SETTING' => $core, $id => $core);
67 }
68
69 $*module_loader.($setting).create_syml;
70 }
71 }
72
73 augment class Cursor {
74 our $RED = "\e[31m";
75 our $GREEN = "\e[32m";
76 our $YELLOW = "\e[33m";
d8d1eb9 @pmurias fixed reseting the term
pmurias authored
77 our $CLEAR = "\e[0m";
78
71f331d @sorear [v6] Conceptually translate Niecza::Frontend::STD
authored
79 }
80
81 has $.lang;
82 has $.safemode;
83
ad19fad @sorear [v6] First port of NieczaCompiler
authored
84 method parse(:$unitname, :$filename, :$modtime, :$source) {
71f331d @sorear [v6] Conceptually translate Niecza::Frontend::STD
authored
85
86 my $*SETTINGNAME = $.lang;
87 my $*SAFEMODE = $.safemode;
ad19fad @sorear [v6] First port of NieczaCompiler
authored
88 my $*UNITNAME = $unitname;
89 my $*modtime = $modtime;
90
91 if $unitname eq 'SAFE' {
92 $*SETTINGNAME = 'NULL';
93 $*SAFEMODE = False;
94 }
95
96 if $unitname eq 'CORE' {
97 $*SETTINGNAME = 'SAFE';
98 $*SAFEMODE = False;
99 }
71f331d @sorear [v6] Conceptually translate Niecza::Frontend::STD
authored
100
101 # XXX temp() or should be contextuals
102 my @save_herestub = @STD::herestub_queue;
103 my $save_all = $STD::ALL;
104
105 $STD::ALL = {};
106 @STD::herestub_queue = ();
107
108 my @*MEMOS;
109 my @*LINEMEMOS;
110 my $*FILE = { name => $filename };
111 my @*ACTIVE;
112 my $*HIGHWATER = 0;
113 my $*HIGHEXPECT = {};
114 my $*HIGHMESS = "";
115 my $*LASTSTATE = 0;
116 my $*IN_PANIC = 0;
117 my $*IN_SUPPOSE = 0;
118 my $*FATALS = 0;
119
4e9a91d @sorear [v6] Fix my @foo = 1; my $bar = @foo[0] = True misparse
authored
120 $DEBUG::EXPR = $STD::DEBUG::EXPR = $STD::DEBUG::symtab =
121 $*verbose > 1;
71f331d @sorear [v6] Conceptually translate Niecza::Frontend::STD
authored
122
123 my $*LAST_NIBBLE = 0;
124 my $*LAST_NIBBLE_START = 0;
125 my $*LAST_NIBBLE_MULTILINE = 0;
126 my $*LAST_NIBBLE_MULTILINE_START = 0;
127 my $*GOAL = "(eof)";
128 my $*SETTING; my $*CORE; my $*GLOBAL; my $*UNIT; my $*YOU_WERE_HERE;
129 my $*CCSTATE; my $*BORG; my %*RX; my $*XACT; my $*VAR; my $*IN_REDUCE;
130
131 my $ast = NieczaGrammar.parse($source, actions => NieczaActions).ast;
132
133 $STD::ALL = $save_all;
134 @STD::herestub_queue = @save_herestub;
135
136 $ast;
137 }
Something went wrong with that request. Please try again.