$ cd languages/ecmascript/src
$ cat main.pir
.include 'errors.pasm'
.sub _main :main
.param pmc args
.local string source_code, rule_to_match
source_code = args[1]
rule_to_match = args[2]
errorson .PARROT_ERRORS_PARAM_COUNT_FLAG
load_bytecode 'PGE.pbc'
load_bytecode 'dumper.pbc'
load_bytecode 'PGE/Dumper.pbc'
load_bytecode 'PGE/Text.pbc'
load_bytecode 'Getopt/Obj.pbc'
load_bytecode 'js.pir'
.local pmc start_rule
start_rule = get_global ['JS'], rule_to_match
if null start_rule goto e_global_not_found
.local pmc match
match = start_rule(source_code)
_dumper(match)
branch end
e_global_not_found:
say "global not found"
end:
.end
$ pgc js.pg >js.pir
$ parrot main.pir 'x' 'identifier'
Null PMC access in invoke()
current instr.: 'parrot;JS;identifier' pc 9096 (js.pir:3766)
called from Sub '_main' pc 38 (main.pir:24)
$ tail -n +3766 js.pir | line
captob = $P0(captob)
$ parrot main.pir '[1]' 'array_literal'
Null PMC access in invoke()
current instr.: 'parrot;JS;array_literal' pc 11560 (js.pir:4711)
called from Sub '_main' pc 38 (main.pir:24)
$ tail -n +4711 js.pir | line
captob = $P0(captob)
$ parrot main.pir '"test"' 'string_literal'
Null PMC access in invoke()
current instr.: 'parrot;JS;string_literal' pc 7460 (js.pir:3094)
called from Sub '_main' pc 38 (main.pir:24)
$ tail -n +3094 js.pir | line
captob = $P0(captob, "\"")
$ parrot main.pir '/* test */' 'multilinecomment'
Null PMC access in invoke()
current instr.: 'parrot;JS;multilinecomment' pc 816 (js.pir:349)
called from Sub '_main' pc 38 (main.pir:24)
$ tail -n +349 js.pir | line
captob = $P0(captob, "/* */")
--
Mehmet
you might have run into a Garbage-Collector bug. Try
parrot --no-gc main.pir 'x' 'identifier'
I had similar problems using PGE::P6Regex. '--no-gc' helped.
Regards,
Kiwi
I think that I now know the problem: the grammar is not complete. I
was thinking that pgc would refuse compiling in that case, but it
doesn't. It's probably to allow you define your own rules at runtime, but
some warnings would be handy.
--
Mehmet
For now, try adding a \b at the ends of the <keyword> rule:
token keyword { \b [ if | else | for | while | ... ] \b }
Then <keyword> will match only the exact keyword.
However, the "\b" metacharacter is disappearing soon, to be replaced
by <?wb> and <!wb>. In its place will be "<<" and ">>", making
the above:
token keyword { << [ if | else | for | while | ... ] >> }
I'll get << and >> added into PGE today/tomorrow.
> - I couldn't make comments work.
> - I don't know how to handle unicode,
> - How to accomplish semicolon insertion?
I'll have to look at the grammar a bit and see what I can come up
with here.
Pm
OOPS! I just looked at PGE, and apparently << and >>
(and their Unicode equivalents) have been been implemented
since late July. So, go ahead and use the above definition
for keyword. :-)
> > - I couldn't make comments work.
> > - I don't know how to handle unicode,
> > - How to accomplish semicolon insertion?
>
> I'll have to look at the grammar a bit and see what I can come up
> with here.
I'm still working on this one.
Pm