1------------------------------------------------------------------------------ 2-- -- 3-- Matreshka Project -- 4-- -- 5-- Localization, Internationalization, Globalization for Ada -- 6-- -- 7-- Runtime Library Component -- 8-- -- 9------------------------------------------------------------------------------ 10-- -- 11-- Copyright © 2010-2011, Vadim Godunko <vgodunko@gmail.com> -- 12-- All rights reserved. -- 13-- -- 14-- Redistribution and use in source and binary forms, with or without -- 15-- modification, are permitted provided that the following conditions -- 16-- are met: -- 17-- -- 18-- * Redistributions of source code must retain the above copyright -- 19-- notice, this list of conditions and the following disclaimer. -- 20-- -- 21-- * Redistributions in binary form must reproduce the above copyright -- 22-- notice, this list of conditions and the following disclaimer in the -- 23-- documentation and/or other materials provided with the distribution. -- 24-- -- 25-- * Neither the name of the Vadim Godunko, IE nor the names of its -- 26-- contributors may be used to endorse or promote products derived from -- 27-- this software without specific prior written permission. -- 28-- -- 29-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -- 30-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -- 31-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -- 32-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -- 33-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -- 34-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -- 35-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -- 36-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -- 37-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -- 38-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -- 39-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -- 40-- -- 41------------------------------------------------------------------------------ 42-- $Revision: 1538 $ $Date: 2011-02-26 15:11:48 +0300 (Sat, 26 Feb 2011) $ 43------------------------------------------------------------------------------ 44with Matreshka.Internals.Regexps.Compiler.Parser.Tables; 45with Matreshka.Internals.Regexps.Compiler.Scanner; 46 47package body Matreshka.Internals.Regexps.Compiler.Parser is 48 49 use Matreshka.Internals.Regexps.Compiler.Parser.Tables; 50 use Matreshka.Internals.Regexps.Compiler.Scanner; 51 use Matreshka.Internals.Unicode.Ucd; 52 53 function Process_Alternation 54 (Pattern : not null Shared_Pattern_Access; 55 Alternative_1 : Positive; 56 Alternative_2 : Positive) return Positive; 57 58 function Process_Multiplicity 59 (Pattern : not null Shared_Pattern_Access; 60 Expression : Positive; 61 Lower : Natural; 62 Upper : Natural; 63 Greedy : Boolean) return Positive; 64 65 function Process_Match_Any 66 (Pattern : not null Shared_Pattern_Access) return Positive; 67 68 function Process_Code_Point 69 (Pattern : not null Shared_Pattern_Access; 70 Character : Wide_Wide_Character) return Positive; 71 72 function Process_Negate_Character_Class 73 (Pattern : not null Shared_Pattern_Access; 74 Class : Positive) return Positive; 75 76 function Process_Character_Class_Range 77 (Pattern : not null Shared_Pattern_Access; 78 Class : Positive; 79 Low : Wide_Wide_Character; 80 High : Wide_Wide_Character) return Positive; 81 82 function Process_Character_Class_Code_Point 83 (Pattern : not null Shared_Pattern_Access; 84 Class : Positive; 85 Code : Wide_Wide_Character) return Positive; 86 87 function Process_New_Character_Class 88 (Pattern : not null Shared_Pattern_Access) return Positive; 89 90 function Process_Subexpression 91 (Pattern : not null Shared_Pattern_Access; 92 Expression : Positive; 93 Capture : Boolean) return Positive; 94 95 function Process_Binary_Property 96 (Pattern : not null Shared_Pattern_Access; 97 Keyword : Property_Specification_Keyword; 98 Negative : Boolean) return Positive; 99 100 function Process_Character_Class_Binary_Property 101 (Pattern : not null Shared_Pattern_Access; 102 Class : Positive; 103 Keyword : Property_Specification_Keyword; 104 Negative : Boolean) return Positive; 105 106 function Process_Start_Of_Line 107 (Pattern : not null Shared_Pattern_Access) return Positive; 108 109 function Process_End_Of_Line 110 (Pattern : not null Shared_Pattern_Access) return Positive; 111 112 procedure Process_Expression 113 (Pattern : not null Shared_Pattern_Access; 114 Expression : Positive); 115 116 Binary_To_Ucd : constant 117 array (Property_Specification_Keyword range <>) of Boolean_Properties := 118 (ASCII_Hex_Digit => ASCII_Hex_Digit, 119 Alphabetic => Alphabetic, 120 Bidi_Control => Bidi_Control, 121-- Bidi_Mirrored => Bidi_Mirrored, 122 Composition_Exclusion => Composition_Exclusion, 123 Cased => Cased, 124 Case_Ignorable => Case_Ignorable, 125 Changes_When_Lowercased => Changes_When_Lowercased, 126 Changes_When_Uppercased => Changes_When_Uppercased, 127 Changes_When_Titlecased => Changes_When_Titlecased, 128 Changes_When_Casefolded => Changes_When_Casefolded, 129 Changes_When_Casemapped => Changes_When_Casemapped, 130 Changes_When_NFKC_Casefolded => Changes_When_NFKC_Casefolded, 131 Full_Composition_Exclusion => Full_Composition_Exclusion, 132 Dash => Dash, 133 Deprecated => Deprecated, 134 Default_Ignorable_Code_Point => Default_Ignorable_Code_Point, 135 Diacritic => Diacritic, 136 Extender => Extender, 137 Grapheme_Base => Grapheme_Base, 138 Grapheme_Extend => Grapheme_Extend, 139 Grapheme_Link => Grapheme_Link, 140 Hex_Digit => Hex_Digit, 141 Hyphen => Hyphen, 142 ID_Continue => ID_Continue, 143 Ideographic => Ideographic, 144 ID_Start => ID_Start, 145 IDS_Binary_Operator => IDS_Binary_Operator, 146 IDS_Trinary_Operator => IDS_Trinary_Operator, 147 Join_Control => Join_Control, 148 Logical_Order_Exception => Logical_Order_Exception, 149 Lowercase => Lowercase, 150 Math => Math, 151 Noncharacter_Code_Point => Noncharacter_Code_Point, 152 Other_Alphabetic => Other_Alphabetic, 153 Other_Default_Ignorable_Code_Point => 154 Other_Default_Ignorable_Code_Point, 155 Other_Grapheme_Extend => Other_Grapheme_Extend, 156 Other_ID_Continue => Other_ID_Continue, 157 Other_ID_Start => Other_ID_Start, 158 Other_Lowercase => Other_Lowercase, 159 Other_Math => Other_Math, 160 Other_Uppercase => Other_Uppercase, 161 Pattern_Syntax => Pattern_Syntax, 162 Pattern_White_Space => Pattern_White_Space, 163 Quotation_Mark => Quotation_Mark, 164 Radical => Radical, 165 Soft_Dotted => Soft_Dotted, 166 STerm => STerm, 167 Terminal_Punctuation => Terminal_Punctuation, 168 Unified_Ideograph => Unified_Ideograph, 169 Uppercase => Uppercase, 170 Variation_Selector => Variation_Selector, 171 White_Space => White_Space, 172 XID_Continue => XID_Continue, 173 XID_Start => XID_Start, 174 Expands_On_NFC => Expands_On_NFC, 175 Expands_On_NFD => Expands_On_NFD, 176 Expands_On_NFKC => Expands_On_NFKC, 177 Expands_On_NFKD => Expands_On_NFKD); 178 179 GC_To_Ucd : constant 180 array (Property_Specification_Keyword range <>) 181 of General_Category_Flags := 182 (Other => 183 (Control | Format | Unassigned | Private_Use | Surrogate => True, 184 others => False), 185 Control => (Control => True, others => False), 186 Format => (Format => True, others => False), 187 Unassigned => (Unassigned => True, others => False), 188 Private_Use => (Private_Use => True, others => False), 189 Surrogate => (Surrogate => True, others => False), 190 Letter => 191 (Lowercase_Letter 192 | Modifier_Letter 193 | Other_Letter 194 | Titlecase_Letter 195 | Uppercase_Letter => True, 196 others => False), 197 Cased_Letter => 198 (Lowercase_Letter | Titlecase_Letter | Uppercase_Letter => True, 199 others => False), 200 Lowercase_Letter => (Lowercase_Letter => True, others => False), 201 Modifier_Letter => (Modifier_Letter => True, others => False), 202 Other_Letter => (Other_Letter => True, others => False), 203 Titlecase_Letter => (Titlecase_Letter => True, others => False), 204 Uppercase_Letter => (Uppercase_Letter => True, others => False), 205 Mark => 206 (Spacing_Mark | Enclosing_Mark | Nonspacing_Mark => True, 207 others => False), 208 Spacing_Mark => (Spacing_Mark => True, others => False), 209 Enclosing_Mark => (Enclosing_Mark => True, others => False), 210 Nonspacing_Mark => (Nonspacing_Mark => True, others => False), 211 Number => 212 (Decimal_Number | Letter_Number | Other_Number => True, 213 others => False), 214 Decimal_Number => (Decimal_Number => True, others => False), 215 Letter_Number => (Letter_Number => True, others => False), 216 Other_Number => (Other_Number => True, others => False), 217 Punctuation => 218 (Connector_Punctuation 219 | Dash_Punctuation 220 | Close_Punctuation 221 | Final_Punctuation 222 | Initial_Punctuation 223 | Other_Punctuation 224 | Open_Punctuation => True, 225 others => False), 226 Connector_Punctuation => 227 (Connector_Punctuation => True, others => False), 228 Dash_Punctuation => (Dash_Punctuation => True, others => False), 229 Close_Punctuation => (Close_Punctuation => True, others => False), 230 Final_Punctuation => (Final_Punctuation => True, others => False), 231 Initial_Punctuation => 232 (Initial_Punctuation => True, others => False), 233 Other_Punctuation => (Other_Punctuation => True, others => False), 234 Open_Punctuation => (Open_Punctuation => True, others => False), 235 Symbol => 236 (Currency_Symbol 237 | Modifier_Symbol 238 | Math_Symbol 239 | Other_Symbol => True, 240 others => False), 241 Currency_Symbol => (Currency_Symbol => True, others => False), 242 Modifier_Symbol => (Modifier_Symbol => True, others => False), 243 Math_Symbol => (Math_Symbol => True, others => False), 244 Other_Symbol => (Other_Symbol => True, others => False), 245 Separator => 246 (Line_Separator | Paragraph_Separator | Space_Separator => True, 247 others => False), 248 Line_Separator => (Line_Separator => True, others => False), 249 Paragraph_Separator => 250 (Paragraph_Separator => True, others => False), 251 Space_Separator => (Space_Separator => True, others => False)); 252 253 ------------------------- 254 -- Process_Alternation -- 255 ------------------------- 256 257 function Process_Alternation 258 (Pattern : not null Shared_Pattern_Access; 259 Alternative_1 : Positive; 260 Alternative_2 : Positive) return Positive is 261 begin 262 return Create_Alternative (Pattern, Alternative_1, Alternative_2); 263 end Process_Alternation; 264 265 ----------------------------- 266 -- Process_Binary_Property -- 267 ----------------------------- 268 269 function Process_Binary_Property 270 (Pattern : not null Shared_Pattern_Access; 271 Keyword : Property_Specification_Keyword; 272 Negative : Boolean) return Positive is 273 begin 274 if Keyword in Binary_To_Ucd'Range then 275 return 276 Create_Match_Property (Pattern, Binary_To_Ucd (Keyword), Negative); 277 278 elsif Keyword in GC_To_Ucd'Range then 279 return Create_Match_Property (Pattern, GC_To_Ucd (Keyword), Negative); 280 281 else 282 raise Program_Error; 283 end if; 284 end Process_Binary_Property; 285 286 --------------------------------------------- 287 -- Process_Character_Class_Binary_Property -- 288 --------------------------------------------- 289 290 function Process_Character_Class_Binary_Property 291 (Pattern : not null Shared_Pattern_Access; 292 Class : Positive; 293 Keyword : Property_Specification_Keyword; 294 Negative : Boolean) return Positive is 295 begin 296 if Keyword in Binary_To_Ucd'Range then 297 Create_Member_Property 298 (Pattern, Class, Binary_To_Ucd (Keyword), Negative); 299 300 elsif Keyword in GC_To_Ucd'Range then 301 Create_Member_Property 302 (Pattern, Class, GC_To_Ucd (Keyword), Negative); 303 304 else 305 raise Program_Error; 306 end if; 307 308 return Class; 309 end Process_Character_Class_Binary_Property; 310 311 ---------------------------------------- 312 -- Process_Character_Class_Code_Point -- 313 ---------------------------------------- 314 315 function Process_Character_Class_Code_Point 316 (Pattern : not null Shared_Pattern_Access; 317 Class : Positive; 318 Code : Wide_Wide_Character) return Positive is 319 begin 320 Create_Member_Character (Pattern, Class, Wide_Wide_Character'Pos (Code)); 321 322 return Class; 323 end Process_Character_Class_Code_Point; 324 325 ----------------------------------- 326 -- Process_Character_Class_Range -- 327 ----------------------------------- 328 329 function Process_Character_Class_Range 330 (Pattern : not null Shared_Pattern_Access; 331 Class : Positive; 332 Low : Wide_Wide_Character; 333 High : Wide_Wide_Character) return Positive is 334 begin 335 Create_Member_Range 336 (Pattern, 337 Class, 338 Wide_Wide_Character'Pos (Low), 339 Wide_Wide_Character'Pos (High)); 340 341 return Class; 342 end Process_Character_Class_Range; 343 344 ------------------------ 345 -- Process_Code_Point -- 346 ------------------------ 347 348 function Process_Code_Point 349 (Pattern : not null Shared_Pattern_Access; 350 Character : Wide_Wide_Character) return Positive is 351 begin 352 return 353 Create_Match_Character (Pattern, Wide_Wide_Character'Pos (Character)); 354 end Process_Code_Point; 355 356 ------------------------- 357 -- Process_End_Of_Line -- 358 ------------------------- 359 360 function Process_End_Of_Line 361 (Pattern : not null Shared_Pattern_Access) return Positive is 362 begin 363 return Create_Anchor_End_Of_Line (Pattern); 364 end Process_End_Of_Line; 365 366 ------------------------ 367 -- Process_Expression -- 368 ------------------------ 369 370 procedure Process_Expression 371 (Pattern : not null Shared_Pattern_Access; 372 Expression : Positive) is 373 begin 374 if Pattern.AST (Expression).List = 0 then 375 Pattern.Last_List := Pattern.Last_List + 1; 376 Pattern.List (Pattern.Last_List) := (0, Expression, Expression); 377 Pattern.Start := Pattern.Last_List; 378 Pattern.AST (Expression).List := Pattern.Last_List; 379 380 else 381 Pattern.Start := Pattern.AST (Expression).List; 382 end if; 383 end Process_Expression; 384 385 ----------------------- 386 -- Process_Match_Any -- 387 ----------------------- 388 389 function Process_Match_Any 390 (Pattern : not null Shared_Pattern_Access) return Positive is 391 begin 392 return Create_Match_Any (Pattern); 393 end Process_Match_Any; 394 395 -------------------------- 396 -- Process_Multiplicity -- 397 -------------------------- 398 399 function Process_Multiplicity 400 (Pattern : not null Shared_Pattern_Access; 401 Expression : Positive; 402 Lower : Natural; 403 Upper : Natural; 404 Greedy : Boolean) return Positive is 405 begin 406 return Create_Repetition (Pattern, Expression, Lower, Upper, Greedy); 407 end Process_Multiplicity; 408 409 ------------------------------------ 410 -- Process_Negate_Character_Class -- 411 ------------------------------------ 412 413 function Process_Negate_Character_Class 414 (Pattern : not null Shared_Pattern_Access; 415 Class : Positive) return Positive is 416 begin 417 Pattern.AST (Class).Negated := True; 418 419 return Class; 420 end Process_Negate_Character_Class; 421 422 --------------------------------- 423 -- Process_New_Character_Class -- 424 --------------------------------- 425 426 function Process_New_Character_Class 427 (Pattern : not null Shared_Pattern_Access) return Positive is 428 begin 429 return Create_Character_Class (Pattern); 430 end Process_New_Character_Class; 431 432 --------------------------- 433 -- Process_Start_Of_Line -- 434 --------------------------- 435 436 function Process_Start_Of_Line 437 (Pattern : not null Shared_Pattern_Access) return Positive is 438 begin 439 return Create_Anchor_Start_Of_Line (Pattern); 440 end Process_Start_Of_Line; 441 442 --------------------------- 443 -- Process_Subexpression -- 444 --------------------------- 445 446 function Process_Subexpression 447 (Pattern : not null Shared_Pattern_Access; 448 Expression : Positive; 449 Capture : Boolean) return Positive is 450 begin 451 return Create_Subexpression (Pattern, Expression, Capture); 452 end Process_Subexpression; 453 454 ------------- 455 -- YYParse -- 456 ------------- 457 458 function YYParse 459 (Self : not null access Compiler_State) 460 return not null Shared_Pattern_Access 461 is 462 463 -- The size of the value and state stacks 464 465 YY_Stack_Size : constant Natural := 300; 466 467 package YY is 468 -- Stack data used by the parser 469 470 TOS : Natural := 0; 471 Value_Stack : array (0 .. YY_Stack_Size) of YYSType; 472 State_Stack : array (0 .. YY_Stack_Size) of Integer; 473 474 -- Current input symbol and action the parser is on 475 476 Input_Symbol : Token; 477 Look_Ahead : Boolean := True; 478 end YY; 479 480 YYVal : YYSType renames Self.YYVal; 481 482 YY_Action : Integer; 483 YY_Rule_Id : Integer; 484 YY_Index : Integer; 485 Pattern : Shared_Pattern_Access 486 := new Shared_Pattern 487 (Self.Data.Length, Node_List_Count (Self.Data.Length)); 488 489 begin 490 YY.TOS := 0; 491 -- Initialize by pushing state 0 and getting the first input symbol 492 YY.State_Stack (YY.TOS) := 0; 493 YY.Look_Ahead := True; 494 495 loop 496 YY_Index := YY_Shift_Reduce_Offset (YY.State_Stack (YY.TOS)); 497 498 if YY_Shift_Reduce_Matrix (YY_Index).T = YY_Default then 499 YY_Action := YY_Shift_Reduce_Matrix (YY_Index).Act; 500 501 else 502 if YY.Look_Ahead then 503 YY.Input_Symbol := YYLex (Self); 504 YY.Look_Ahead := False; 505 end if; 506 507 YY_Index := YY_Shift_Reduce_Offset (YY.State_Stack (YY.TOS)); 508 509 while YY_Shift_Reduce_Matrix (YY_Index).T 510 /= Token'Pos (YY.Input_Symbol) 511 and then YY_Shift_Reduce_Matrix (YY_Index).T /= YY_Default 512 loop 513 YY_Index := YY_Index + 1; 514 end loop; 515 516 YY_Action := YY_Shift_Reduce_Matrix (YY_Index).Act; 517 end if; 518 519 if YY_Action >= YY_First_Shift_Entry then -- SHIFT 520 -- Enter new state 521 522 YY.TOS := YY.TOS + 1; 523 YY.State_Stack (YY.TOS) := YY_Action; 524 YY.Value_Stack (YY.TOS) := Self.YYLVal; 525 526 -- Advance lookahead 527 528 YY.Look_Ahead := True; 529 530 elsif YY_Action = YY_Error_Code then -- ERROR 531 Dereference (Pattern); 532 533 raise Constraint_Error 534 with "Syntax error: " 535 & YY_Errors'Image (Self.YY_Error.Error) 536 & " at" 537 & Integer'Image (Self.YY_Error.Index); 538 539 elsif YY_Action = YY_Accept_Code then 540 -- Grammar is accepted 541 542 return Pattern; 543 544 else 545 -- Reduce Action 546 547 -- Convert action into a rule 548 YY_Rule_Id := -1 * YY_Action; 549 550 -- Execute User Action 551 552 case YY_Rule_Id is 553 pragma Style_Checks ("M127"); 554 555 when 1 => 556 Process_Expression (Pattern, YY.Value_Stack (YY.TOS).Node); 557 558 when 2 => 559 -- Alternation 560 561 YYVal := 562 (AST_Node, 563 Process_Alternation (Pattern, YY.Value_Stack (YY.TOS - 2).Node, YY.Value_Stack (YY.TOS).Node)); 564 565 when 3 => 566 YYVal := YY.Value_Stack (YY.TOS); 567 568 when 4 => 569 Matreshka.Internals.Regexps.Compiler.Attach 570 (Pattern.all, YY.Value_Stack (YY.TOS - 1).Node, YY.Value_Stack (YY.TOS).Node); 571 YYVal := YY.Value_Stack (YY.TOS - 1); 572 573 when 5 => 574 YYVal := YY.Value_Stack (YY.TOS); 575 576 when 6 => 577 -- Optional, greedy 578 579 YYVal := (AST_Node, Process_Multiplicity (Pattern, YY.Value_Stack (YY.TOS - 1).Node, 0, 1, True)); 580 581 when 7 => 582 -- Optional, lazy 583 584 YYVal := (AST_Node, Process_Multiplicity (Pattern, YY.Value_Stack (YY.TOS - 1).Node, 0, 1, False)); 585 586 when 8 => 587 -- Zero or more, greedy 588 589 YYVal := (AST_Node, Process_Multiplicity (Pattern, YY.Value_Stack (YY.TOS - 1).Node, 0, Natural'Last, True)); 590 591 when 9 => 592 -- Zero or more, lazy 593 594 YYVal := (AST_Node, Process_Multiplicity (Pattern, YY.Value_Stack (YY.TOS - 1).Node, 0, Natural'Last, False)); 595 596 when 10 => 597 -- One or more, greedy 598 599 YYVal := (AST_Node, Process_Multiplicity (Pattern, YY.Value_Stack (YY.TOS - 1).Node, 1, Natural'Last, True)); 600 601 when 11 => 602 -- One or more, lazy 603 604 YYVal := (AST_Node, Process_Multiplicity (Pattern, YY.Value_Stack (YY.TOS - 1).Node, 1, Natural'Last, False)); 605 606 when 12 => 607 -- Multiplicity range, greedy 608 609 YYVal := 610 (AST_Node, 611 Process_Multiplicity 612 (Pattern, 613 YY.Value_Stack (YY.TOS - 5).Node, 614 YY.Value_Stack (YY.TOS - 3).Value, 615 YY.Value_Stack (YY.TOS - 1).Value, 616 True)); 617 618 when 13 => 619 -- Multiplicity range, lazy 620 621 YYVal := 622 (AST_Node, 623 Process_Multiplicity 624 (Pattern, 625 YY.Value_Stack (YY.TOS - 5).Node, 626 YY.Value_Stack (YY.TOS - 3).Value, 627 YY.Value_Stack (YY.TOS - 1).Value, 628 False)); 629 630 when 14 => 631 -- Multiplicity zero .. upper, greedy 632 633 YYVal := 634 (AST_Node, 635 Process_Multiplicity 636 (Pattern, 637 YY.Value_Stack (YY.TOS - 4).Node, 638 0, 639 YY.Value_Stack (YY.TOS - 1).Value, 640 True)); 641 642 when 15 => 643 -- Multiplicity zero .. upper, lazy 644 645 YYVal := 646 (AST_Node, 647 Process_Multiplicity 648 (Pattern, 649 YY.Value_Stack (YY.TOS - 4).Node, 650 0, 651 YY.Value_Stack (YY.TOS - 1).Value, 652 False)); 653 654 when 16 => 655 -- Multiplicity lower .. infinity, greedy 656 657 YYVal := 658 (AST_Node, 659 Process_Multiplicity 660 (Pattern, 661 YY.Value_Stack (YY.TOS - 4).Node, 662 YY.Value_Stack (YY.TOS - 2).Value, 663 Integer'Last, 664 True)); 665 666 when 17 => 667 -- Multiplicity lower .. infinity, lazy 668 669 YYVal := 670 (AST_Node, 671 Process_Multiplicity 672 (Pattern, 673 YY.Value_Stack (YY.TOS - 4).Node, 674 YY.Value_Stack (YY.TOS - 2).Value, 675 Integer'Last, 676 False)); 677 678 when 18 => 679 -- Multiplicity, greedy 680 681 YYVal := 682 (AST_Node, 683 Process_Multiplicity 684 (Pattern, 685 YY.Value_Stack (YY.TOS - 3).Node, 686 YY.Value_Stack (YY.TOS - 1).Value, 687 YY.Value_Stack (YY.TOS - 1).Value, 688 True)); 689 690 when 19 => 691 -- Multiplicity, lazy 692 693 YYVal := 694 (AST_Node, 695 Process_Multiplicity 696 (Pattern, 697 YY.Value_Stack (YY.TOS - 3).Node, 698 YY.Value_Stack (YY.TOS - 1).Value, 699 YY.Value_Stack (YY.TOS - 1).Value, 700 False)); 701 702 when 20 => 703 YYVal := (AST_Node, Process_Subexpression (Pattern, YY.Value_Stack (YY.TOS - 1).Node, True)); 704 705 when 21 => 706 YYVal := (AST_Node, Process_Subexpression (Pattern, YY.Value_Stack (YY.TOS - 1).Node, False)); 707 708 when 22 => 709 -- Any code point 710 711 YYVal := (AST_Node, Process_Match_Any (Pattern)); 712 713 when 23 => 714 -- Code point 715 716 YYVal := (AST_Node, Process_Code_Point (Pattern, YY.Value_Stack (YY.TOS).Code)); 717 718 when 24 => 719 -- Character with binary property 720 721 YYVal := (AST_Node, Process_Binary_Property (Pattern, YY.Value_Stack (YY.TOS - 1).Keyword, False)); 722 723 when 25 => 724 -- Character with binary property, negative 725 726 YYVal := (AST_Node, Process_Binary_Property (Pattern, YY.Value_Stack (YY.TOS - 1).Keyword, True)); 727 728 when 26 => 729 -- Character class 730 731 YYVal := YY.Value_Stack (YY.TOS); 732 733 when 27 => 734 -- Start of line anchor 735 736 YYVal := (AST_Node, Process_Start_Of_Line (Pattern)); 737 738 when 28 => 739 -- End of line anchor 740 741 YYVal := (AST_Node, Process_End_Of_Line (Pattern)); 742 743 when 29 => 744 YYVal := YY.Value_Stack (YY.TOS - 1); 745 746 when 30 => 747 YYVal := (AST_Node, Process_Negate_Character_Class (Pattern, YY.Value_Stack (YY.TOS - 1).Node)); 748 749 when 31 => 750 -- Add range of code points to character class 751 752 YYVal := 753 (AST_Node, 754 Process_Character_Class_Range 755 (Pattern, YY.Value_Stack (YY.TOS - 3).Node, YY.Value_Stack (YY.TOS - 2).Code, YY.Value_Stack (YY.TOS).Code)); 756 757 when 32 => 758 -- Add code point to character class 759 760 YYVal := 761 (AST_Node, 762 Process_Character_Class_Code_Point 763 (Pattern, YY.Value_Stack (YY.TOS - 1).Node, YY.Value_Stack (YY.TOS).Code)); 764 765 when 33 => 766 -- Character with binary property 767 768 YYVal := 769 (AST_Node, 770 Process_Character_Class_Binary_Property 771 (Pattern, YY.Value_Stack (YY.TOS - 3).Node, YY.Value_Stack (YY.TOS - 1).Keyword, False)); 772 773 when 34 => 774 -- Character with binary property, negative 775 776 YYVal := 777 (AST_Node, 778 Process_Character_Class_Binary_Property 779 (Pattern, YY.Value_Stack (YY.TOS - 3).Node, YY.Value_Stack (YY.TOS - 1).Keyword, True)); 780 781 when 35 => 782 -- Initialize new character class node 783 784 YYVal := (AST_Node, Process_New_Character_Class (Pattern)); 785 pragma Style_Checks ("M79"); 786 787 when others => 788 Dereference (Pattern); 789 790 raise Program_Error; 791 end case; 792 793 -- Pop RHS states and goto next state 794 795 YY.TOS := YY.TOS - YY_Rule_Length (YY_Rule_Id) + 1; 796 797 YY_Index := YY_Goto_Offset (YY.State_Stack (YY.TOS - 1)); 798 799 while YY_Goto_Matrix (YY_Index).Nonterm 800 /= YY_Get_LHS_Rule (YY_Rule_Id) 801 loop 802 YY_Index := YY_Index + 1; 803 end loop; 804 805 YY.State_Stack (YY.TOS) := YY_Goto_Matrix (YY_Index).Newstate; 806 YY.Value_Stack (YY.TOS) := YYVal; 807 end if; 808 end loop; 809 end YYParse; 810 811end Matreshka.Internals.Regexps.Compiler.Parser; 812