antlr3 1.8.8 → 1.8.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/java/RubyTarget.java +131 -0
- data/java/antlr-full-3.2.1.jar +0 -0
- data/lib/antlr3/main.rb +2 -8
- data/lib/antlr3/profile.rb +1 -1
- data/lib/antlr3/version.rb +1 -1
- data/templates/Ruby.stg +1 -1
- metadata +10 -5
data/java/RubyTarget.java
CHANGED
@@ -477,4 +477,135 @@ public class RubyTarget extends Target
|
|
477
477
|
|
478
478
|
return String.valueOf( intValue );
|
479
479
|
}
|
480
|
+
|
481
|
+
/** Convert from an ANTLR string literal found in a grammar file to
|
482
|
+
* an equivalent string literal in the target language. For Java, this
|
483
|
+
* is the translation 'a\n"' -> "a\n\"". Expect single quotes
|
484
|
+
* around the incoming literal. Just flip the quotes and replace
|
485
|
+
* double quotes with \"
|
486
|
+
*
|
487
|
+
* Note that we have decided to allow poeple to use '\"' without
|
488
|
+
* penalty, so we must build the target string in a loop as Utils.replae
|
489
|
+
* cannot handle both \" and " without a lot of messing around.
|
490
|
+
*
|
491
|
+
*/
|
492
|
+
public String getTargetStringLiteralFromANTLRStringLiteral(
|
493
|
+
CodeGenerator generator,
|
494
|
+
String literal)
|
495
|
+
{
|
496
|
+
StringBuilder sb = new StringBuilder();
|
497
|
+
StringBuffer is = new StringBuffer(literal);
|
498
|
+
int lastIndex = is.length() - 1;
|
499
|
+
|
500
|
+
// Opening quote
|
501
|
+
//
|
502
|
+
sb.append('"');
|
503
|
+
|
504
|
+
for ( int i = 1; i < lastIndex; i++ ) {
|
505
|
+
if (is.charAt(i) == '\\') {
|
506
|
+
// Anything escaped is what it is! We assume that
|
507
|
+
// people know how to escape characters correctly. However
|
508
|
+
// we catch anything that does not need an escape in Java (which
|
509
|
+
// is what the default implementation is dealing with and remove
|
510
|
+
// the escape. The C target does this for instance.
|
511
|
+
//
|
512
|
+
switch (is.charAt(i+1)) {
|
513
|
+
// Pass through any escapes that Java also needs
|
514
|
+
//
|
515
|
+
case '"':
|
516
|
+
case 'n':
|
517
|
+
case 'r':
|
518
|
+
case 't':
|
519
|
+
case 'b':
|
520
|
+
case 'f':
|
521
|
+
case '\\':
|
522
|
+
case 'u': // Assume unnnn
|
523
|
+
sb.append('\\'); // Pass the escape through
|
524
|
+
break;
|
525
|
+
default:
|
526
|
+
// Remove the escape by virtue of not adding it here
|
527
|
+
// Thus \' becomes ' and so on
|
528
|
+
//
|
529
|
+
break;
|
530
|
+
}
|
531
|
+
|
532
|
+
// Go past the \ character
|
533
|
+
//
|
534
|
+
i++;
|
535
|
+
} else {
|
536
|
+
|
537
|
+
// in ruby, double quoted strings have interpolation signifiers that
|
538
|
+
// will cause a syntax error in the output if they are not properly
|
539
|
+
// escaped
|
540
|
+
|
541
|
+
if ( is.charAt( i ) == '#' && i < lastIndex - 1 ) {
|
542
|
+
switch ( is.charAt( i + 1 ) ) {
|
543
|
+
case '{':
|
544
|
+
case '@':
|
545
|
+
case '$':
|
546
|
+
sb.append('\\');
|
547
|
+
break;
|
548
|
+
default:
|
549
|
+
break;
|
550
|
+
// pass through
|
551
|
+
}
|
552
|
+
} else if (is.charAt(i) == '"') {
|
553
|
+
sb.append('\\');
|
554
|
+
}
|
555
|
+
|
556
|
+
}
|
557
|
+
// Add in the next character, which may have been escaped
|
558
|
+
//
|
559
|
+
sb.append(is.charAt(i));
|
560
|
+
}
|
561
|
+
|
562
|
+
// Append closing " and return
|
563
|
+
//
|
564
|
+
sb.append('"');
|
565
|
+
|
566
|
+
return sb.toString();
|
567
|
+
}
|
568
|
+
|
569
|
+
|
570
|
+
public String getTargetStringLiteralFromString(String s, boolean quoted) {
|
571
|
+
if ( s == null ) { return null; }
|
572
|
+
|
573
|
+
StringBuffer buf = new StringBuffer();
|
574
|
+
|
575
|
+
if ( quoted ) { buf.append('"'); }
|
576
|
+
|
577
|
+
for ( int i = 0; i < s.length(); i++ ) {
|
578
|
+
int c = s.charAt( i );
|
579
|
+
|
580
|
+
if ( c != '\'' && // don't escape single quotes in strings for java
|
581
|
+
c < targetCharValueEscape.length &&
|
582
|
+
targetCharValueEscape[c] != null )
|
583
|
+
{
|
584
|
+
buf.append(targetCharValueEscape[c]);
|
585
|
+
}
|
586
|
+
else if ( c == '#' && i < s.length() - 1 )
|
587
|
+
{
|
588
|
+
switch ( s.charAt( i + 1 ) ) {
|
589
|
+
case '{':
|
590
|
+
case '@':
|
591
|
+
case '$':
|
592
|
+
buf.append( "\\#" );
|
593
|
+
break;
|
594
|
+
default:
|
595
|
+
buf.append( '#' );
|
596
|
+
break;
|
597
|
+
}
|
598
|
+
}
|
599
|
+
else
|
600
|
+
{
|
601
|
+
buf.append((char)c);
|
602
|
+
}
|
603
|
+
}
|
604
|
+
if ( quoted ) {
|
605
|
+
buf.append('"');
|
606
|
+
}
|
607
|
+
return buf.toString();
|
608
|
+
}
|
609
|
+
|
610
|
+
|
480
611
|
}
|
data/java/antlr-full-3.2.1.jar
CHANGED
Binary file
|
data/lib/antlr3/main.rb
CHANGED
@@ -145,19 +145,13 @@ class Main
|
|
145
145
|
ANTLR3::FileStream.new( args[ 0 ] )
|
146
146
|
else ANTLR3::FileStream.new( @input )
|
147
147
|
end
|
148
|
-
|
149
|
-
when @ruby_prof
|
148
|
+
if @ruby_prof
|
150
149
|
load_ruby_prof
|
151
150
|
profile = RubyProf.profile do
|
152
151
|
recognize( in_stream )
|
153
152
|
end
|
154
153
|
printer = RubyProf::FlatPrinter.new( profile )
|
155
154
|
printer.print( @output )
|
156
|
-
when @profile
|
157
|
-
require 'profiler'
|
158
|
-
Profiler__.start_profile
|
159
|
-
recognize( in_stream )
|
160
|
-
Profiler__.print_profile
|
161
155
|
else
|
162
156
|
recognize( in_stream )
|
163
157
|
end
|
@@ -457,7 +451,7 @@ class ParserMain < Main
|
|
457
451
|
# token_stream = CommonTokenStream.new( lexer )
|
458
452
|
parser = @parser_class.new( lexer, parser_options )
|
459
453
|
result = parser.send( @parser_rule ) and present( result )
|
460
|
-
@profile and puts( parser.generate_report )
|
454
|
+
@profile and puts( parser.profile.generate_report )
|
461
455
|
end
|
462
456
|
|
463
457
|
def present( return_value )
|
data/lib/antlr3/profile.rb
CHANGED
data/lib/antlr3/version.rb
CHANGED
data/templates/Ruby.stg
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: antlr3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 35
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 8
|
8
|
-
-
|
9
|
-
version: 1.8.
|
9
|
+
- 10
|
10
|
+
version: 1.8.10
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Kyle Yetter
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-
|
18
|
+
date: 2011-03-28 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -240,25 +241,29 @@ rdoc_options: []
|
|
240
241
|
require_paths:
|
241
242
|
- lib
|
242
243
|
required_ruby_version: !ruby/object:Gem::Requirement
|
244
|
+
none: false
|
243
245
|
requirements:
|
244
246
|
- - ">="
|
245
247
|
- !ruby/object:Gem::Version
|
248
|
+
hash: 57
|
246
249
|
segments:
|
247
250
|
- 1
|
248
251
|
- 8
|
249
252
|
- 7
|
250
253
|
version: 1.8.7
|
251
254
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
255
|
+
none: false
|
252
256
|
requirements:
|
253
257
|
- - ">="
|
254
258
|
- !ruby/object:Gem::Version
|
259
|
+
hash: 3
|
255
260
|
segments:
|
256
261
|
- 0
|
257
262
|
version: "0"
|
258
263
|
requirements:
|
259
264
|
- java
|
260
265
|
rubyforge_project: antlr3
|
261
|
-
rubygems_version: 1.
|
266
|
+
rubygems_version: 1.5.0
|
262
267
|
signing_key:
|
263
268
|
specification_version: 3
|
264
269
|
summary: Fully-featured ruby parser generation for ANTLR version 3.
|