Skip to content

Commit

Permalink
Add ability to support embedded comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Apr 4, 2009
1 parent 0e8b7a4 commit 68ea385
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/parser/grammar.pg
Expand Up @@ -94,7 +94,11 @@ token nofun { <!before '(' | '.(' | '\\' > }
token unv {
|| \h+
|| ^^ <.pod_comment>
|| '#' \N*
|| ^^ '#' <?opener> <.panic: "Can't use embedded columns in column 1">
|| '#' [
| <?opener> <quote_expression: >
| \N*
]
}

## The <afterws> rule returns true if we're immediate after
Expand Down
30 changes: 29 additions & 1 deletion src/parser/quote_expression.pir
Expand Up @@ -5,11 +5,39 @@

.namespace ['Perl6';'Grammar']

.sub '' :anon :load :init
.local pmc brackets
brackets = box unicode:"<>[](){}\xab\xbb\u0f3a\u0f3b\u0f3c\u0f3d\u169b\u169c\u2045\u2046\u207d\u207e\u208d\u208e\u2329\u232a\u2768\u2769\u276a\u276b\u276c\u276d\u276e\u276f\u2770\u2771\u2772\u2773\u2774\u2775\u27c5\u27c6\u27e6\u27e7\u27e8\u27e9\u27ea\u27eb\u2983\u2984\u2985\u2986\u2987\u2988\u2989\u298a\u298b\u298c\u298d\u298e\u298f\u2990\u2991\u2992\u2993\u2994\u2995\u2996\u2997\u2998\u29d8\u29d9\u29da\u29db\u29fc\u29fd\u3008\u3009\u300a\u300b\u300c\u300d\u300e\u300f\u3010\u3011\u3014\u3015\u3016\u3017\u3018\u3019\u301a\u301b\u301d\u301e\ufd3e\ufd3f\ufe17\ufe18\ufe35\ufe36\ufe37\ufe38\ufe39\ufe3a\ufe3b\ufe3c\ufe3d\ufe3e\ufe3f\ufe40\ufe41\ufe42\ufe43\ufe44\ufe47\ufe48\ufe59\ufe5a\ufe5b\ufe5c\ufe5d\ufe5e\uff08\uff09\uff3b\uff3d\uff5b\uff5d\uff5f\uff60\uff62\uff63"
set_global '$!brackets', brackets
.end

.sub 'opener' :method
.local string brackets
$P0 = get_global '$!brackets'
brackets = $P0

.local pmc mob
.local string target
.local int pos
(mob, pos, target) = self.'new'(self)
$S0 = substr target, pos, 1
$I0 = index brackets, $S0
if $I0 < 0 goto fail
$I0 = $I0 % 2
if $I0 goto fail
inc pos
mob.'to'(pos)
fail:
.return (mob)
.end

.sub 'peek_brackets' :method
.param string target
.param int pos
.local string brackets, start, stop
brackets = unicode:"<>[](){}\xab\xbb\u0f3a\u0f3b\u0f3c\u0f3d\u169b\u169c\u2045\u2046\u207d\u207e\u208d\u208e\u2329\u232a\u2768\u2769\u276a\u276b\u276c\u276d\u276e\u276f\u2770\u2771\u2772\u2773\u2774\u2775\u27c5\u27c6\u27e6\u27e7\u27e8\u27e9\u27ea\u27eb\u2983\u2984\u2985\u2986\u2987\u2988\u2989\u298a\u298b\u298c\u298d\u298e\u298f\u2990\u2991\u2992\u2993\u2994\u2995\u2996\u2997\u2998\u29d8\u29d9\u29da\u29db\u29fc\u29fd\u3008\u3009\u300a\u300b\u300c\u300d\u300e\u300f\u3010\u3011\u3014\u3015\u3016\u3017\u3018\u3019\u301a\u301b\u301d\u301e\ufd3e\ufd3f\ufe17\ufe18\ufe35\ufe36\ufe37\ufe38\ufe39\ufe3a\ufe3b\ufe3c\ufe3d\ufe3e\ufe3f\ufe40\ufe41\ufe42\ufe43\ufe44\ufe47\ufe48\ufe59\ufe5a\ufe5b\ufe5c\ufe5d\ufe5e\uff08\uff09\uff3b\uff3d\uff5b\uff5d\uff5f\uff60\uff62\uff63"

$P0 = get_global '$!brackets'
brackets = $P0

start = substr target, pos, 1
if start == ':' goto err_colon_delim
Expand Down
1 change: 1 addition & 0 deletions t/spectest.data
Expand Up @@ -77,6 +77,7 @@ S02-names_and_variables/fmt.t
S02-names_and_variables/varnames.t
S02-one-pass-parsing/less-than.t
S02-polymorphic_types/subset.t
S02-whitespace_and_comments/comments.t
S02-whitespace_and_comments/minimal-whitespace.t
S02-whitespace_and_comments/one-pass-parsing.t
S02-whitespace_and_comments/pod-in-multi-line-exprs.t
Expand Down

0 comments on commit 68ea385

Please sign in to comment.