Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
refactor with load_language
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Sep 20, 2009
1 parent 37bf6f5 commit 76b5856
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 92 deletions.
13 changes: 8 additions & 5 deletions config/makefiles/root.in
Expand Up @@ -42,8 +42,7 @@ SOURCES := \
src/Node.pir \
src/gen_grammar.pir \
src/gen_actions.pir \
src/gen_builtins.pir \
markdown.pir
src/gen_builtins.pir

BUILTINS_PIR := \
src/builtins/is_strict.pir \
Expand All @@ -53,6 +52,7 @@ DOCS := README

BUILD_CLEANUPS := \
man \
markdown/markdown.pbc \
markdown.pbc \
"src/gen_*.pir" \
"*.c" \
Expand All @@ -69,11 +69,14 @@ TEST_CLEANUPS := \
"t/*.text"

# the default target
build: markdown.pbc
build: markdown/markdown.pbc markdown.pbc

all: build markdown@exe@ installable

markdown.pbc: $(SOURCES)
markdown/markdown.pbc: $(SOURCES)
$(PARROT) $(PARROT_ARGS) -o markdown/markdown.pbc src/Compiler.pir

markdown.pbc: markdown.pir
$(PARROT) $(PARROT_ARGS) -o markdown.pbc markdown.pir

markdown@exe@: markdown.pbc
Expand Down Expand Up @@ -175,7 +178,7 @@ install: installable
$(CP) installable_markdown@exe@ $(BIN_DIR)/parrot-markdown@exe@
$(CHMOD) 0755 $(BIN_DIR)/parrot-markdown@exe@
-$(MKPATH) $(LIB_DIR)/languages/markdown
$(CP) markdown.pbc $(LIB_DIR)/languages/markdown/markdown.pbc
$(CP) markdown/markdown.pbc $(LIB_DIR)/languages/markdown/markdown.pbc
-$(MKPATH) $(MANDIR)/man1
$(POD2MAN) markdown.pir > $(MANDIR)/man1/parrot-markdown.1
-$(MKPATH) $(DOC_DIR)/languages/markdown
Expand Down
91 changes: 7 additions & 84 deletions markdown.pir
Expand Up @@ -7,14 +7,14 @@

as a command line (without interactive mode) :

$ parrot markdown.pbc document.text
$ parrot markdown.pbc --target=parse document.text
PAST
HTML
$ parrot-markdown document.text
$ parrot-markdown --target=parse document.text
PAST
HTML

or as a library from PIR code :

load_bytecode 'markdown.pbc'
load_language 'markdown'
$P0 = compreg 'markdown'
$S0 = <<'MARKDOWN'
Title
Expand All @@ -38,86 +38,18 @@ or as a compiler from Rakudo :

=head2 Description

This is the base file for the Markdown compiler.

This file includes the parsing and grammar rules from
the src/ directory, loads the relevant PGE libraries,
and registers the compiler under the name 'Markdown'.

=head3 Functions

=over 4

=item onload()

Creates the Markdown compiler using a C<PCT::HLLCompiler>
object.

=cut

.namespace [ 'Markdown';'Compiler' ]

.sub 'onload' :anon :load :init
load_bytecode 'PCT.pbc'

.local pmc p6meta
p6meta = new 'P6metaclass'
$P0 = p6meta.'new_class'('Markdown::Compiler', 'parent'=>'PCT::HLLCompiler')
$P1 = $P0.'new'()
$P1.'language'('markdown')
$P1.'parsegrammar'('Markdown::Grammar')
$P1.'parseactions'('Markdown::Grammar::Actions')
$P1.'removestage'('post')
$P1.'addstage'('html', 'before' => 'pir')
.end
=item html(source [, adverbs :slurpy :named])
Transform MAST C<source> into a String containing HTML.
This is the entry file for the Markdown compiler.

=cut

.sub 'html' :method
.param pmc source
.param pmc adverbs :slurpy :named
$P0 = new ['Markdown';'HTML';'Compiler']
.tailcall $P0.'to_html'(source, adverbs :flat :named)
.end
.sub 'pir' :method
.param pmc source
.param pmc adverbs :slurpy :named
new $P0, 'CodeString'
$P0 = <<'PIRCODE'
.sub 'main' :anon
$S0 = <<'PIR'
PIRCODE
$P0 .= source
$P0 .= <<'PIRCODE'
PIR
.return ($S0)
.end
PIRCODE
.return ($P0)
.end
=item main(args :slurpy) :main
Start compilation by passing any command line C<args>
to the Markdown compiler.
=cut

.sub 'main' :main
.param pmc args

load_bytecode 'dumper.pbc'
load_bytecode 'PGE/Dumper.pbc'

load_language 'markdown'
$P0 = compreg 'markdown'

.local pmc opts
Expand All @@ -128,15 +60,6 @@ to the Markdown compiler.
.end


.include 'src/gen_grammar.pir'
.include 'src/gen_actions.pir'
.include 'src/gen_builtins.pir'
.include 'src/Compiler.pir'
.include 'src/Node.pir'
=back
=head2 See Also

L<http://daringfireball.net/projects/markdown/>
Expand Down
69 changes: 66 additions & 3 deletions src/Compiler.pir
@@ -1,11 +1,68 @@
# Copyright (C) 2008-2009, Parrot Foundation.
# $Id$

=head1 Markdown::HTML::Compiler - MAST Compiler
=head1 Markdown::Compiler

=head2 Functions & Methods
=over 4

=item onload()

Creates the Markdown compiler using a C<PCT::HLLCompiler>
object.

=cut

.namespace [ 'Markdown';'Compiler' ]

=head2 Description
.sub 'onload' :anon :load :init
load_bytecode 'PCT.pbc'

Markdown::HTML::Compiler implements a compiler for MAST nodes.
.local pmc p6meta
p6meta = new 'P6metaclass'
$P0 = p6meta.'new_class'('Markdown::Compiler', 'parent'=>'PCT::HLLCompiler')
$P1 = $P0.'new'()
$P1.'language'('markdown')
$P1.'parsegrammar'('Markdown::Grammar')
$P1.'parseactions'('Markdown::Grammar::Actions')
$P1.'removestage'('post')
$P1.'addstage'('html', 'before' => 'pir')
.end
=item html(source [, adverbs :slurpy :named])
Transform MAST C<source> into a String containing HTML.
=cut
.sub 'html' :method
.param pmc source
.param pmc adverbs :slurpy :named
$P0 = new ['Markdown';'HTML';'Compiler']
.tailcall $P0.'to_html'(source, adverbs :flat :named)
.end
.sub 'pir' :method
.param pmc source
.param pmc adverbs :slurpy :named
new $P0, 'CodeString'
$P0 = <<'PIRCODE'
.sub 'main' :anon
$S0 = <<'PIR'
PIRCODE
$P0 .= source
$P0 .= <<'PIRCODE'
PIR
.return ($S0)
.end
PIRCODE
.return ($P0)
.end
=head1 Markdown::HTML::Compiler - MAST Compiler
=head2 Methods
Expand Down Expand Up @@ -591,6 +648,12 @@ Return generated HTML for all of its children.

=cut

.include 'src/gen_grammar.pir'
.include 'src/gen_actions.pir'
.include 'src/gen_builtins.pir'
.include 'src/Node.pir'


# Local Variables:
# mode: pir
# fill-column: 100
Expand Down

0 comments on commit 76b5856

Please sign in to comment.