From cd3f68645c17a378a22863a94f7f969765d690c5 Mon Sep 17 00:00:00 2001 From: ydah Date: Tue, 11 Jun 2024 23:15:43 +0900 Subject: [PATCH] wip --- lib/lrama/parser.rb | 678 ++++++++++-------- parser.y | 21 +- spec/fixtures/inlining/basic.y | 6 +- .../parameterizing_rules/user_defined/basic.y | 6 +- 4 files changed, 388 insertions(+), 323 deletions(-) diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index 27045924..ce6649c8 100644 --- a/lib/lrama/parser.rb +++ b/lib/lrama/parser.rb @@ -654,7 +654,7 @@ def token_to_str(t) module Lrama class Parser < Racc::Parser -module_eval(<<'...end parser.y/module_eval...', 'parser.y', 534) +module_eval(<<'...end parser.y/module_eval...', 'parser.y', 551) include Lrama::Report::Duration @@ -728,184 +728,198 @@ def raise_parse_error(error_message, location) ##### State transition tables begin ### racc_action_table = [ - 100, 52, 101, 167, 89, 80, 52, 52, 184, 167, - 80, 80, 52, 3, 184, 52, 80, 51, 169, 160, - 71, 8, 161, 185, 169, 6, 52, 7, 51, 185, - 80, 76, 40, 52, 52, 51, 51, 46, 83, 83, - 47, 52, 90, 51, 49, 170, 83, 52, 102, 51, - 186, 170, 83, 52, 55, 51, 186, 20, 24, 25, + 107, 55, 108, 180, 92, 83, 55, 55, 188, 180, + 83, 83, 55, 3, 188, 55, 83, 54, 182, 163, + 74, 8, 162, 189, 182, 6, 55, 7, 54, 189, + 83, 79, 176, 40, 55, 162, 54, 49, 47, 86, + 50, 55, 93, 54, 52, 183, 86, 55, 109, 54, + 190, 183, 86, 55, 58, 54, 190, 22, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 46, 52, 52, 51, 51, 94, 80, - 202, 52, 52, 51, 51, 80, 202, 52, 52, 51, - 51, 80, 202, 20, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 33, 34, 35, 36, 37, 38, 9, - 187, 46, 124, 161, 12, 13, 14, 15, 16, 17, - 55, 55, 18, 19, 20, 24, 25, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, - 52, 52, 51, 51, 80, 202, 52, 52, 51, 51, - 80, 202, 52, 52, 51, 51, 80, 202, 52, 52, - 51, 51, 80, 80, 52, 52, 51, 51, 80, 80, - 52, 52, 51, 51, 80, 80, 52, 52, 51, 213, - 80, 80, 52, 52, 213, 213, 80, 80, 52, 52, - 51, 51, 80, 192, 193, 194, 98, 192, 193, 194, - 98, 224, 229, 237, 225, 225, 225, 52, 52, 51, - 51, 52, 58, 51, 192, 193, 194, 59, 60, 61, - 62, 63, 64, 65, 66, 67, 68, 91, 47, 96, - 98, 103, 103, 103, 105, 111, 114, 116, 119, 119, - 119, 119, 122, 127, 128, 130, 132, 133, 134, 135, - 136, 80, 143, 144, 145, 146, 147, 150, 151, 152, - 154, 164, 143, 166, 172, 174, 175, 176, 177, 178, - 179, 181, 182, 150, 189, 197, 198, 205, 164, 209, - 212, 98, 217, 164, 221, 164, 223, 179, 182, 182, - 98, 234, 179, 236, 179, 98, 98, 179 ] + 36, 37, 49, 47, 49, 105, 48, 97, 55, 55, + 54, 54, 55, 86, 54, 192, 83, 225, 162, 55, + 58, 54, 22, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 9, 55, 58, + 54, 48, 14, 15, 16, 17, 18, 19, 49, 131, + 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 55, 55, + 54, 54, 83, 225, 55, 55, 54, 54, 83, 225, + 55, 55, 54, 54, 83, 225, 55, 55, 54, 54, + 83, 225, 55, 55, 54, 54, 83, 225, 55, 55, + 54, 54, 83, 83, 55, 55, 54, 54, 83, 83, + 55, 55, 54, 54, 83, 83, 55, 55, 54, 230, + 83, 83, 55, 55, 230, 230, 83, 83, 55, 61, + 54, 202, 83, 62, 162, 207, 208, 209, 102, 207, + 208, 209, 102, 243, 248, 256, 244, 244, 244, 55, + 55, 54, 54, 207, 208, 209, 63, 64, 65, 66, + 67, 68, 69, 70, 71, 94, 50, 50, 100, 102, + 103, 110, 110, 110, 112, 118, 121, 123, 126, 126, + 126, 126, 129, 134, 135, 136, 138, 139, 141, 143, + 144, 145, 146, 147, 83, 136, 154, 155, 156, 157, + 160, 161, 166, 136, 168, 170, 166, 136, 179, 184, + 185, 191, 194, 196, 197, 198, 199, 200, 185, 191, + 160, 204, 212, 215, 166, 219, 220, 221, 228, 229, + 102, 234, 166, 237, 166, 166, 166, 242, 185, 191, + 191, 191, 191, 102, 253, 185, 255, 185, 102, 102, + 185 ] racc_action_check = [ - 50, 149, 50, 149, 38, 149, 163, 188, 163, 188, - 163, 188, 206, 1, 206, 32, 206, 32, 149, 142, - 32, 3, 142, 163, 188, 2, 33, 2, 33, 206, - 33, 33, 7, 34, 35, 34, 35, 9, 34, 35, - 10, 36, 38, 36, 12, 149, 36, 37, 50, 37, - 163, 188, 37, 13, 14, 13, 206, 9, 9, 9, + 53, 159, 53, 159, 38, 159, 164, 203, 164, 203, + 164, 203, 218, 1, 218, 32, 218, 32, 159, 137, + 32, 3, 137, 164, 203, 2, 33, 2, 33, 218, + 33, 33, 153, 7, 34, 153, 34, 9, 9, 34, + 10, 35, 38, 35, 14, 159, 35, 36, 53, 36, + 164, 203, 36, 15, 16, 15, 218, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 41, 70, 176, 70, 176, 41, 176, - 176, 177, 71, 177, 71, 177, 177, 178, 82, 178, - 82, 178, 178, 41, 41, 41, 41, 41, 41, 41, - 41, 41, 41, 41, 41, 41, 41, 41, 41, 4, - 165, 90, 90, 165, 4, 4, 4, 4, 4, 4, - 15, 16, 4, 4, 4, 4, 4, 4, 4, 4, + 9, 9, 41, 41, 48, 48, 9, 41, 37, 73, + 37, 73, 198, 37, 198, 167, 198, 198, 167, 74, + 17, 74, 41, 41, 41, 41, 41, 41, 41, 41, + 41, 41, 41, 41, 41, 41, 41, 4, 85, 18, + 85, 41, 4, 4, 4, 4, 4, 4, 93, 93, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 199, 83, 199, 83, 199, 199, 203, 111, 203, 111, - 203, 203, 204, 113, 204, 113, 204, 204, 75, 76, - 75, 76, 75, 76, 116, 118, 116, 118, 116, 118, - 140, 170, 140, 170, 140, 170, 186, 189, 186, 189, - 186, 189, 209, 223, 209, 223, 209, 223, 225, 119, - 225, 119, 225, 168, 168, 168, 168, 183, 183, 183, - 183, 214, 220, 231, 214, 220, 231, 121, 137, 121, - 137, 141, 17, 141, 215, 215, 215, 18, 20, 24, - 25, 26, 27, 28, 29, 30, 31, 39, 43, 44, - 45, 54, 56, 57, 58, 69, 73, 74, 81, 86, - 87, 88, 89, 97, 98, 104, 106, 107, 108, 109, - 110, 115, 122, 123, 124, 125, 126, 127, 128, 129, - 131, 144, 145, 148, 153, 155, 156, 157, 158, 159, - 160, 161, 162, 166, 167, 171, 173, 180, 182, 184, - 187, 191, 195, 205, 210, 212, 213, 216, 219, 222, - 224, 228, 229, 230, 232, 234, 236, 239 ] + 4, 4, 4, 4, 4, 4, 4, 4, 199, 86, + 199, 86, 199, 199, 200, 118, 200, 118, 200, 200, + 222, 120, 222, 120, 222, 222, 226, 126, 226, 126, + 226, 226, 227, 128, 227, 128, 227, 227, 78, 79, + 78, 79, 78, 79, 123, 125, 123, 125, 123, 125, + 151, 183, 151, 183, 151, 183, 190, 204, 190, 204, + 190, 204, 215, 242, 215, 242, 215, 242, 244, 19, + 244, 178, 244, 20, 178, 181, 181, 181, 181, 187, + 187, 187, 187, 231, 236, 250, 231, 236, 250, 148, + 152, 148, 152, 232, 232, 232, 22, 24, 25, 26, + 27, 28, 29, 30, 31, 39, 43, 44, 45, 46, + 47, 57, 59, 60, 61, 72, 76, 77, 84, 89, + 90, 91, 92, 101, 102, 103, 104, 105, 111, 113, + 114, 115, 116, 117, 122, 129, 130, 131, 132, 133, + 134, 135, 138, 139, 140, 142, 154, 155, 158, 162, + 163, 165, 169, 171, 172, 173, 174, 175, 176, 177, + 179, 180, 186, 188, 191, 192, 193, 195, 201, 202, + 206, 210, 212, 216, 219, 228, 229, 230, 233, 235, + 238, 240, 241, 243, 247, 248, 249, 251, 253, 255, + 258 ] racc_action_pointer = [ - nil, 13, 15, 21, 100, nil, nil, 25, nil, 33, - 27, nil, 38, 50, 34, 100, 101, 207, 197, nil, - 198, nil, nil, nil, 199, 200, 201, 217, 218, 219, - 220, 221, 12, 23, 30, 31, 38, 44, -1, 225, - nil, 69, nil, 215, 216, 179, nil, nil, nil, nil, - -5, nil, nil, nil, 211, nil, 212, 213, 214, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, 227, - 71, 79, nil, 230, 229, 155, 156, nil, nil, nil, - nil, 230, 85, 138, nil, nil, 231, 232, 233, 202, - 107, nil, nil, nil, nil, nil, nil, 201, 239, nil, - nil, nil, nil, nil, 243, nil, 244, 245, 246, 247, - 248, 144, nil, 150, nil, 244, 161, nil, 162, 186, - nil, 204, 247, 211, 214, 244, 254, 211, 206, 257, - nil, 258, nil, nil, nil, nil, nil, 205, nil, nil, - 167, 208, -22, nil, 215, 257, nil, nil, 218, -2, - nil, nil, nil, 243, nil, 244, 245, 246, 247, 248, - 262, 266, 227, 3, nil, 69, 227, 234, 145, nil, - 168, 254, nil, 255, nil, nil, 72, 78, 84, nil, - 235, nil, 232, 149, 239, nil, 173, 238, 4, 174, - nil, 230, nil, nil, nil, 280, nil, nil, nil, 137, - nil, nil, nil, 143, 149, 237, 9, nil, nil, 179, - 282, nil, 239, 246, 160, 166, 279, nil, nil, 243, - 161, nil, 244, 180, 239, 185, nil, nil, 270, 284, - 272, 162, 286, nil, 244, nil, 245, nil, nil, 289, - nil, nil ] + nil, 13, 15, 21, 98, nil, nil, 26, nil, 33, + 27, nil, nil, nil, 38, 50, 34, 70, 89, 194, + 183, nil, 206, nil, 207, 208, 209, 225, 226, 227, + 228, 229, 12, 23, 31, 38, 44, 75, -1, 233, + nil, 68, nil, 223, 224, 225, 188, 200, 70, nil, + nil, nil, nil, -5, nil, nil, nil, 221, nil, 222, + 223, 224, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, 237, 76, 86, nil, 240, 239, 165, 166, + nil, nil, nil, nil, 240, 105, 136, nil, nil, 241, + 242, 243, 212, 114, nil, nil, nil, nil, nil, nil, + nil, 211, 249, 250, 214, 217, nil, nil, nil, nil, + nil, 256, nil, 257, 258, 259, 260, 261, 142, nil, + 148, nil, 257, 171, nil, 172, 154, nil, 160, 260, + 224, 227, 257, 267, 224, 219, nil, -22, 226, 268, + 272, nil, 273, nil, nil, nil, nil, nil, 216, nil, + nil, 177, 217, -9, 230, 272, nil, nil, 233, -2, + nil, nil, 274, 272, 3, 236, nil, 44, nil, 261, + nil, 262, 263, 264, 265, 266, 280, 244, 160, 244, + 251, 157, nil, 178, nil, nil, 250, 161, 253, nil, + 183, 248, 253, 275, nil, 276, nil, nil, 79, 135, + 141, 256, 257, 4, 184, nil, 249, nil, nil, nil, + 299, nil, 256, nil, nil, 189, 301, nil, 9, 258, + nil, nil, 147, nil, nil, nil, 153, 159, 259, 260, + 267, 172, 175, 300, nil, 264, 173, nil, 265, nil, + 266, 267, 190, 262, 195, nil, nil, 293, 307, 295, + 174, 309, nil, 267, nil, 268, nil, nil, 312, nil, + nil ] racc_action_default = [ - -2, -139, -10, -139, -139, -3, -4, -139, 242, -139, - -8, -12, -139, -139, -139, -139, -139, -139, -139, -24, - -139, -28, -29, -30, -139, -139, -139, -139, -139, -139, - -139, -139, -139, -139, -139, -139, -139, -139, -139, -139, - -7, -126, -100, -8, -139, -123, -125, -9, -11, -13, - -130, -98, -99, -129, -15, -89, -16, -17, -139, -21, - -25, -31, -34, -37, -40, -41, -42, -43, -44, -45, - -51, -139, -54, -56, -46, -79, -139, -82, -84, -85, - -138, -47, -92, -139, -95, -97, -48, -49, -50, -139, - -139, -5, -1, -101, -127, -102, -103, -139, -139, -14, - -131, -132, -133, -86, -139, -18, -139, -139, -139, -139, - -139, -139, -55, -52, -57, -77, -139, -83, -80, -139, - -96, -93, -139, -139, -139, -139, -139, -107, -139, -139, - -90, -139, -22, -26, -32, -35, -38, -53, -58, -78, - -81, -94, -139, -64, -68, -139, -6, -128, -104, -105, - -108, -124, -87, -139, -19, -139, -139, -139, -139, -139, - -59, -139, -62, -66, -69, -139, -107, -98, -123, -112, - -139, -139, -91, -139, -23, -27, -139, -139, -139, -60, - -139, -65, -68, -123, -98, -73, -139, -139, -106, -139, - -109, -123, -116, -117, -118, -139, -115, -88, -20, -33, - -134, -136, -137, -36, -39, -68, -67, -70, -71, -139, - -139, -76, -68, -98, -139, -119, -59, -113, -135, -61, - -139, -74, -63, -139, -123, -139, -121, -110, -139, -59, - -139, -139, -59, -120, -123, -72, -123, -122, -111, -59, - -75, -114 ] + -2, -143, -10, -143, -143, -3, -4, -143, 261, -143, + -8, -12, -13, -14, -143, -143, -143, -143, -143, -143, + -143, -26, -143, -30, -143, -143, -143, -143, -143, -143, + -143, -143, -143, -143, -143, -143, -143, -143, -143, -143, + -7, -130, -100, -8, -8, -143, -127, -143, -143, -129, + -9, -11, -15, -134, -98, -99, -133, -17, -89, -18, + -19, -143, -23, -27, -31, -34, -37, -40, -41, -42, + -43, -44, -45, -51, -143, -54, -56, -46, -79, -143, + -82, -84, -85, -142, -47, -92, -143, -95, -97, -48, + -49, -50, -143, -143, -5, -1, -101, -131, -102, -103, + -104, -143, -143, -143, -143, -143, -16, -135, -136, -137, + -86, -143, -20, -143, -143, -143, -143, -143, -143, -55, + -52, -57, -77, -143, -83, -80, -143, -96, -93, -143, + -143, -143, -143, -143, -108, -143, -64, -143, -68, -143, + -143, -90, -143, -24, -28, -32, -35, -38, -53, -58, + -78, -81, -94, -143, -68, -143, -6, -132, -105, -106, + -109, -128, -143, -59, -66, -118, -69, -143, -87, -143, + -21, -143, -143, -143, -143, -143, -59, -62, -143, -108, + -98, -127, -113, -143, -65, -60, -143, -127, -98, -73, + -143, -68, -143, -143, -91, -143, -25, -29, -143, -143, + -143, -143, -143, -107, -143, -110, -127, -120, -121, -122, + -143, -116, -68, -70, -71, -143, -143, -76, -67, -68, + -88, -22, -33, -138, -140, -141, -36, -39, -68, -68, + -98, -143, -123, -59, -114, -117, -143, -74, -119, -139, + -61, -63, -143, -127, -143, -125, -111, -143, -59, -143, + -143, -59, -124, -127, -72, -127, -126, -112, -59, -75, + -115 ] racc_goto_table = [ - 77, 75, 97, 53, 112, 191, 162, 70, 180, 120, - 149, 214, 142, 1, 121, 54, 56, 57, 48, 2, - 208, 42, 73, 4, 85, 85, 85, 85, 218, 41, - 92, 220, 218, 218, 5, 165, 81, 86, 87, 88, - 39, 125, 117, 77, 118, 231, 113, 112, 120, 188, - 141, 95, 226, 93, 199, 203, 204, 10, 11, 50, - 73, 73, 99, 131, 227, 173, 106, 219, 120, 155, - 107, 112, 85, 85, 222, 156, 108, 235, 157, 109, - 238, 158, 110, 77, 140, 117, 137, 241, 159, 69, - 74, 138, 115, 123, 206, 210, 230, 139, 129, 171, - 104, 73, 153, 73, 148, 195, 228, 117, 126, 85, - nil, 85, nil, nil, nil, nil, 168, nil, nil, nil, - nil, nil, nil, nil, nil, 190, nil, 73, nil, nil, - 183, 85, nil, nil, nil, nil, nil, 196, nil, nil, - 207, nil, nil, nil, nil, nil, nil, nil, 216, nil, - nil, nil, nil, 211, nil, 168, 215, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, 183, nil, nil, 215, nil, nil, nil, - nil, 232, nil, nil, nil, nil, nil, nil, nil, nil, - 215, 239, 233, 240 ] + 80, 101, 56, 78, 165, 73, 119, 127, 206, 104, + 159, 128, 137, 186, 214, 57, 59, 60, 231, 76, + 177, 88, 88, 88, 88, 42, 201, 1, 2, 236, + 239, 4, 51, 41, 239, 239, 95, 5, 153, 84, + 89, 90, 91, 39, 132, 124, 80, 120, 167, 125, + 127, 152, 10, 119, 130, 203, 250, 96, 11, 245, + 76, 76, 12, 13, 178, 98, 99, 222, 226, 227, + 53, 106, 88, 88, 127, 142, 195, 113, 235, 171, + 114, 119, 172, 246, 115, 238, 173, 116, 174, 117, + 80, 148, 124, 151, 240, 241, 175, 72, 254, 77, + 149, 257, 122, 218, 216, 76, 249, 76, 260, 150, + 140, 193, 111, 88, 169, 88, 158, 210, 124, 247, + 133, nil, nil, nil, nil, nil, 181, nil, nil, nil, + nil, 187, nil, nil, nil, 76, 205, nil, nil, 88, + nil, nil, 213, nil, nil, nil, nil, nil, nil, nil, + 211, nil, nil, nil, nil, nil, nil, 217, nil, nil, + nil, 233, nil, nil, nil, nil, nil, nil, nil, nil, + 181, 232, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, 232, nil, nil, 187, nil, nil, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, 251, nil, + nil, nil, nil, nil, nil, nil, nil, nil, 258, 232, + 259, 252 ] racc_goto_check = [ - 44, 51, 45, 36, 35, 46, 40, 34, 41, 57, - 61, 47, 39, 1, 56, 14, 14, 14, 10, 2, - 46, 58, 36, 3, 36, 36, 36, 36, 65, 4, - 5, 47, 65, 65, 6, 39, 33, 33, 33, 33, - 7, 8, 44, 44, 51, 47, 34, 35, 57, 61, - 56, 10, 46, 58, 22, 22, 22, 9, 11, 12, - 36, 36, 13, 15, 41, 16, 17, 40, 57, 18, - 23, 35, 36, 36, 40, 24, 25, 41, 26, 27, - 41, 28, 29, 44, 51, 44, 34, 41, 30, 31, - 32, 37, 38, 42, 43, 48, 49, 50, 52, 53, - 54, 36, 55, 36, 60, 62, 63, 44, 64, 36, - nil, 36, nil, nil, nil, nil, 44, nil, nil, nil, - nil, nil, nil, nil, nil, 45, nil, 36, nil, nil, - 44, 36, nil, nil, nil, nil, nil, 44, nil, nil, - 45, nil, nil, nil, nil, nil, nil, nil, 45, nil, - nil, nil, nil, 44, nil, 44, 44, nil, nil, nil, - nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, 44, nil, nil, 44, nil, nil, nil, + 44, 45, 36, 51, 40, 34, 35, 57, 46, 42, + 62, 56, 39, 41, 46, 16, 16, 16, 47, 36, + 40, 36, 36, 36, 36, 58, 41, 1, 2, 47, + 66, 3, 10, 4, 66, 66, 5, 6, 39, 33, + 33, 33, 33, 7, 8, 44, 44, 34, 39, 51, + 57, 56, 9, 35, 42, 62, 47, 58, 11, 46, + 36, 36, 12, 13, 39, 10, 10, 22, 22, 22, + 14, 15, 36, 36, 57, 17, 18, 19, 40, 20, + 23, 35, 24, 41, 25, 40, 26, 27, 28, 29, + 44, 34, 44, 51, 40, 40, 30, 31, 41, 32, + 37, 41, 38, 43, 48, 36, 49, 36, 41, 50, + 52, 53, 54, 36, 55, 36, 61, 63, 44, 64, + 65, nil, nil, nil, nil, nil, 44, nil, nil, nil, + nil, 44, nil, nil, nil, 36, 45, nil, nil, 36, + nil, nil, 45, nil, nil, nil, nil, nil, nil, nil, + 44, nil, nil, nil, nil, nil, nil, 44, nil, nil, nil, 45, nil, nil, nil, nil, nil, nil, nil, nil, - 44, 45, 44, 45 ] + 44, 44, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, 44, nil, nil, 44, nil, nil, nil, nil, + nil, nil, nil, nil, nil, nil, nil, nil, 45, nil, + nil, nil, nil, nil, nil, nil, nil, nil, 45, 44, + 45, 44 ] racc_goto_pointer = [ - nil, 13, 19, 21, 20, -11, 32, 34, -50, 53, - 8, 54, 46, 12, 1, -42, -89, 7, -63, nil, - nil, nil, -122, 10, -58, 15, -56, 17, -54, 19, - -48, 57, 57, 2, -25, -66, -10, -24, 19, -110, - -138, -152, 3, -88, -33, -43, -163, -178, -90, -125, - -18, -32, -5, -53, 45, -28, -69, -73, 12, nil, - -23, -117, -64, -111, 14, -171 ] + nil, 27, 28, 29, 24, -5, 35, 37, -50, 48, + 22, 54, 58, 59, 55, 18, -1, -37, -94, 15, + -64, nil, -131, 17, -62, 20, -59, 22, -58, 23, + -51, 65, 66, 5, -27, -67, -13, -22, 26, -91, + -134, -150, -39, -88, -33, -45, -173, -186, -85, -131, + -13, -30, 0, -57, 54, -27, -75, -78, 16, nil, + nil, -18, -124, -65, -115, 23, -192 ] racc_goto_default = [ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, - nil, 44, nil, nil, nil, nil, nil, nil, nil, 21, - 22, 23, nil, nil, nil, nil, nil, nil, nil, nil, - nil, nil, nil, nil, nil, 72, 78, nil, nil, nil, - nil, nil, 45, 163, 201, nil, nil, nil, nil, nil, - 79, nil, nil, nil, nil, nil, 82, 84, nil, 43, - nil, nil, nil, nil, nil, 200 ] + nil, 45, nil, nil, nil, nil, nil, nil, nil, nil, + nil, 23, nil, nil, nil, nil, nil, nil, nil, nil, + nil, nil, nil, nil, nil, 75, 81, nil, nil, nil, + nil, nil, 46, 164, 224, nil, nil, nil, nil, nil, + 82, nil, nil, nil, nil, nil, 85, 87, nil, 43, + 44, nil, nil, nil, nil, nil, 223 ] racc_reduce_table = [ 0, 0, :racc_error, @@ -921,23 +935,23 @@ def raise_parse_error(error_message, location) 0, 57, :_reduce_10, 3, 57, :_reduce_none, 1, 63, :_reduce_none, - 2, 63, :_reduce_13, + 1, 63, :_reduce_none, + 1, 63, :_reduce_none, + 2, 63, :_reduce_15, 3, 63, :_reduce_none, 2, 63, :_reduce_none, - 2, 63, :_reduce_16, - 2, 63, :_reduce_17, - 0, 69, :_reduce_18, - 0, 70, :_reduce_19, - 7, 63, :_reduce_20, - 0, 71, :_reduce_21, - 0, 72, :_reduce_22, - 6, 63, :_reduce_23, - 1, 63, :_reduce_24, - 0, 77, :_reduce_25, - 0, 78, :_reduce_26, - 6, 65, :_reduce_27, - 1, 65, :_reduce_none, - 1, 65, :_reduce_none, + 2, 63, :_reduce_18, + 2, 63, :_reduce_19, + 0, 71, :_reduce_20, + 0, 72, :_reduce_21, + 7, 63, :_reduce_22, + 0, 73, :_reduce_23, + 0, 74, :_reduce_24, + 6, 63, :_reduce_25, + 1, 63, :_reduce_26, + 0, 77, :_reduce_27, + 0, 78, :_reduce_28, + 6, 65, :_reduce_29, 1, 65, :_reduce_none, 0, 79, :_reduce_31, 0, 80, :_reduce_32, @@ -953,12 +967,12 @@ def raise_parse_error(error_message, location) 2, 65, :_reduce_42, 2, 65, :_reduce_43, 2, 65, :_reduce_44, - 2, 73, :_reduce_none, - 2, 73, :_reduce_46, - 2, 73, :_reduce_47, - 2, 73, :_reduce_48, - 2, 73, :_reduce_49, - 2, 73, :_reduce_50, + 2, 75, :_reduce_none, + 2, 75, :_reduce_46, + 2, 75, :_reduce_47, + 2, 75, :_reduce_48, + 2, 75, :_reduce_49, + 2, 75, :_reduce_50, 1, 85, :_reduce_51, 2, 85, :_reduce_52, 3, 85, :_reduce_53, @@ -969,9 +983,9 @@ def raise_parse_error(error_message, location) 3, 89, :_reduce_58, 0, 95, :_reduce_none, 1, 95, :_reduce_none, - 8, 74, :_reduce_61, - 5, 75, :_reduce_62, - 8, 75, :_reduce_63, + 8, 66, :_reduce_61, + 5, 67, :_reduce_62, + 8, 67, :_reduce_63, 1, 93, :_reduce_64, 3, 93, :_reduce_65, 1, 94, :_reduce_66, @@ -996,10 +1010,10 @@ def raise_parse_error(error_message, location) 1, 98, :_reduce_none, 0, 106, :_reduce_86, 0, 107, :_reduce_87, - 6, 68, :_reduce_88, + 6, 70, :_reduce_88, 0, 108, :_reduce_89, 0, 109, :_reduce_90, - 5, 68, :_reduce_91, + 5, 70, :_reduce_91, 1, 87, :_reduce_92, 2, 87, :_reduce_93, 3, 87, :_reduce_94, @@ -1012,45 +1026,49 @@ def raise_parse_error(error_message, location) 2, 58, :_reduce_none, 2, 112, :_reduce_none, 2, 112, :_reduce_none, - 4, 113, :_reduce_104, - 1, 114, :_reduce_105, - 3, 114, :_reduce_106, - 0, 115, :_reduce_107, - 1, 115, :_reduce_108, - 3, 115, :_reduce_109, - 5, 115, :_reduce_110, - 7, 115, :_reduce_111, - 0, 116, :_reduce_112, + 2, 112, :_reduce_none, + 4, 113, :_reduce_105, + 1, 115, :_reduce_106, + 3, 115, :_reduce_107, + 0, 116, :_reduce_108, + 1, 116, :_reduce_109, + 3, 116, :_reduce_110, + 5, 116, :_reduce_111, + 7, 116, :_reduce_112, 0, 117, :_reduce_113, - 8, 115, :_reduce_114, - 3, 115, :_reduce_115, - 1, 100, :_reduce_116, - 1, 100, :_reduce_117, - 1, 100, :_reduce_118, - 1, 101, :_reduce_119, - 3, 101, :_reduce_120, - 2, 101, :_reduce_121, - 4, 101, :_reduce_122, + 0, 118, :_reduce_114, + 8, 116, :_reduce_115, + 3, 116, :_reduce_116, + 7, 114, :_reduce_117, + 4, 114, :_reduce_118, + 7, 114, :_reduce_119, + 1, 100, :_reduce_120, + 1, 100, :_reduce_121, + 1, 100, :_reduce_122, + 1, 101, :_reduce_123, + 3, 101, :_reduce_124, + 2, 101, :_reduce_125, + 4, 101, :_reduce_126, 0, 99, :_reduce_none, - 3, 99, :_reduce_124, + 3, 99, :_reduce_128, 1, 96, :_reduce_none, 0, 59, :_reduce_none, - 0, 118, :_reduce_127, - 3, 59, :_reduce_128, - 1, 66, :_reduce_none, - 0, 67, :_reduce_none, - 1, 67, :_reduce_none, - 1, 67, :_reduce_none, - 1, 67, :_reduce_none, - 1, 76, :_reduce_134, - 2, 76, :_reduce_135, - 1, 119, :_reduce_none, - 1, 119, :_reduce_none, - 1, 104, :_reduce_138 ] - -racc_reduce_n = 139 - -racc_shift_n = 242 + 0, 119, :_reduce_131, + 3, 59, :_reduce_132, + 1, 68, :_reduce_none, + 0, 69, :_reduce_none, + 1, 69, :_reduce_none, + 1, 69, :_reduce_none, + 1, 69, :_reduce_none, + 1, 76, :_reduce_138, + 2, 76, :_reduce_139, + 1, 120, :_reduce_none, + 1, 120, :_reduce_none, + 1, 104, :_reduce_142 ] + +racc_reduce_n = 143 + +racc_shift_n = 261 racc_token_table = { false => 0, @@ -1196,6 +1214,8 @@ def raise_parse_error(error_message, location) "bison_declaration", "\"-option@;\"", "grammar_declaration", + "rule_declaration", + "inline_declaration", "variable", "value", "params", @@ -1204,8 +1224,6 @@ def raise_parse_error(error_message, location) "@5", "@6", "symbol_declaration", - "rule_declaration", - "inline_declaration", "generic_symlist", "@7", "@8", @@ -1244,6 +1262,7 @@ def raise_parse_error(error_message, location) "token_declaration_for_precedence", "rules_or_grammar_declaration", "rules", + "parameterizing_rules", "rhs_list", "rhs", "@21", @@ -1306,19 +1325,23 @@ def _reduce_10(val, _values, result) # reduce 12 omitted -module_eval(<<'.,.,', 'parser.y', 32) - def _reduce_13(val, _values, result) +# reduce 13 omitted + +# reduce 14 omitted + +module_eval(<<'.,.,', 'parser.y', 34) + def _reduce_15(val, _values, result) @grammar.expect = val[1] result end .,., -# reduce 14 omitted +# reduce 16 omitted -# reduce 15 omitted +# reduce 17 omitted -module_eval(<<'.,.,', 'parser.y', 37) - def _reduce_16(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 39) + def _reduce_18(val, _values, result) val[1].each {|token| @grammar.lex_param = Grammar::Code::NoReferenceCode.new(type: :lex_param, token_code: token).token_code.s_value } @@ -1327,8 +1350,8 @@ def _reduce_16(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 43) - def _reduce_17(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 45) + def _reduce_19(val, _values, result) val[1].each {|token| @grammar.parse_param = Grammar::Code::NoReferenceCode.new(type: :parse_param, token_code: token).token_code.s_value } @@ -1337,79 +1360,79 @@ def _reduce_17(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 49) - def _reduce_18(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 51) + def _reduce_20(val, _values, result) begin_c_declaration("}") result end .,., -module_eval(<<'.,.,', 'parser.y', 53) - def _reduce_19(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 55) + def _reduce_21(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 57) - def _reduce_20(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 59) + def _reduce_22(val, _values, result) @grammar.add_percent_code(id: val[1], code: val[4]) result end .,., -module_eval(<<'.,.,', 'parser.y', 61) - def _reduce_21(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 63) + def _reduce_23(val, _values, result) begin_c_declaration("}") result end .,., -module_eval(<<'.,.,', 'parser.y', 65) - def _reduce_22(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 67) + def _reduce_24(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 69) - def _reduce_23(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 71) + def _reduce_25(val, _values, result) @grammar.initial_action = Grammar::Code::InitialActionCode.new(type: :initial_action, token_code: val[3]) result end .,., -module_eval(<<'.,.,', 'parser.y', 71) - def _reduce_24(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 73) + def _reduce_26(val, _values, result) @grammar.no_stdlib = true result end .,., -module_eval(<<'.,.,', 'parser.y', 75) - def _reduce_25(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 77) + def _reduce_27(val, _values, result) begin_c_declaration("}") result end .,., -module_eval(<<'.,.,', 'parser.y', 79) - def _reduce_26(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 81) + def _reduce_28(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 83) - def _reduce_27(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 85) + def _reduce_29(val, _values, result) @grammar.set_union( Grammar::Code::NoReferenceCode.new(type: :union, token_code: val[3]), val[3].line @@ -1419,10 +1442,6 @@ def _reduce_27(val, _values, result) end .,., -# reduce 28 omitted - -# reduce 29 omitted - # reduce 30 omitted module_eval(<<'.,.,', 'parser.y', 93) @@ -1992,8 +2011,10 @@ def _reduce_99(val, _values, result) # reduce 103 omitted -module_eval(<<'.,.,', 'parser.y', 400) - def _reduce_104(val, _values, result) +# reduce 104 omitted + +module_eval(<<'.,.,', 'parser.y', 401) + def _reduce_105(val, _values, result) lhs = val[0] lhs.alias_name = val[1] val[3].each do |builder| @@ -2006,8 +2027,8 @@ def _reduce_104(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 411) - def _reduce_105(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 412) + def _reduce_106(val, _values, result) builder = val[0] if !builder.line builder.line = @lexer.line - 1 @@ -2018,8 +2039,8 @@ def _reduce_105(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 419) - def _reduce_106(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 420) + def _reduce_107(val, _values, result) builder = val[2] if !builder.line builder.line = @lexer.line - 1 @@ -2030,8 +2051,8 @@ def _reduce_106(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 428) - def _reduce_107(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 429) + def _reduce_108(val, _values, result) reset_precs result = @grammar.create_rule_builder(@rule_counter, @midrule_action_counter) @@ -2039,8 +2060,8 @@ def _reduce_107(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 433) - def _reduce_108(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 434) + def _reduce_109(val, _values, result) reset_precs result = @grammar.create_rule_builder(@rule_counter, @midrule_action_counter) @@ -2048,8 +2069,8 @@ def _reduce_108(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 438) - def _reduce_109(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 439) + def _reduce_110(val, _values, result) token = val[1] token.alias_name = val[2] builder = val[0] @@ -2060,8 +2081,8 @@ def _reduce_109(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 446) - def _reduce_110(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 447) + def _reduce_111(val, _values, result) token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[2], alias_name: val[3], location: @lexer.location, args: [val[1]], lhs_tag: val[4]) builder = val[0] builder.add_rhs(token) @@ -2072,8 +2093,8 @@ def _reduce_110(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 454) - def _reduce_111(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 455) + def _reduce_112(val, _values, result) token = Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, alias_name: val[5], location: @lexer.location, args: val[3], lhs_tag: val[6]) builder = val[0] builder.add_rhs(token) @@ -2084,8 +2105,8 @@ def _reduce_111(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 462) - def _reduce_112(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 463) + def _reduce_113(val, _values, result) if @prec_seen on_action_error("multiple User_code after %prec", val[0]) if @code_after_prec @code_after_prec = true @@ -2096,16 +2117,16 @@ def _reduce_112(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 470) - def _reduce_113(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 471) + def _reduce_114(val, _values, result) end_c_declaration result end .,., -module_eval(<<'.,.,', 'parser.y', 474) - def _reduce_114(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 475) + def _reduce_115(val, _values, result) user_code = val[3] user_code.alias_name = val[6] user_code.tag = val[7] @@ -2117,8 +2138,8 @@ def _reduce_114(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 483) - def _reduce_115(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 484) + def _reduce_116(val, _values, result) sym = @grammar.find_symbol_by_id!(val[2]) @prec_seen = true builder = val[0] @@ -2129,70 +2150,97 @@ def _reduce_115(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 490) - def _reduce_116(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 493) + def _reduce_117(val, _values, result) + rule = Grammar::ParameterizingRule::Rule.new(val[0].s_value, val[2], val[6], tag: val[4]) + @grammar.add_parameterizing_rule(rule) + + result + end +.,., + +module_eval(<<'.,.,', 'parser.y', 498) + def _reduce_118(val, _values, result) + rule = Grammar::ParameterizingRule::Rule.new(val[1].s_value, [], val[3], is_inline: true) + @grammar.add_parameterizing_rule(rule) + + result + end +.,., + +module_eval(<<'.,.,', 'parser.y', 503) + def _reduce_119(val, _values, result) + rule = Grammar::ParameterizingRule::Rule.new(val[1].s_value, val[3], val[6], is_inline: true) + @grammar.add_parameterizing_rule(rule) + + result + end +.,., + +module_eval(<<'.,.,', 'parser.y', 507) + def _reduce_120(val, _values, result) result = "option" result end .,., -module_eval(<<'.,.,', 'parser.y', 491) - def _reduce_117(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 508) + def _reduce_121(val, _values, result) result = "nonempty_list" result end .,., -module_eval(<<'.,.,', 'parser.y', 492) - def _reduce_118(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 509) + def _reduce_122(val, _values, result) result = "list" result end .,., -module_eval(<<'.,.,', 'parser.y', 494) - def _reduce_119(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 511) + def _reduce_123(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 495) - def _reduce_120(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 512) + def _reduce_124(val, _values, result) result = val[0].append(val[2]) result end .,., -module_eval(<<'.,.,', 'parser.y', 496) - def _reduce_121(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 513) + def _reduce_125(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[1].s_value, location: @lexer.location, args: val[0])] result end .,., -module_eval(<<'.,.,', 'parser.y', 497) - def _reduce_122(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 514) + def _reduce_126(val, _values, result) result = [Lrama::Lexer::Token::InstantiateRule.new(s_value: val[0].s_value, location: @lexer.location, args: val[2])] result end .,., -# reduce 123 omitted +# reduce 127 omitted -module_eval(<<'.,.,', 'parser.y', 500) - def _reduce_124(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 517) + def _reduce_128(val, _values, result) result = val[1].s_value result end .,., -# reduce 125 omitted +# reduce 129 omitted -# reduce 126 omitted +# reduce 130 omitted -module_eval(<<'.,.,', 'parser.y', 507) - def _reduce_127(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 524) + def _reduce_131(val, _values, result) begin_c_declaration('\Z') @grammar.epilogue_first_lineno = @lexer.line + 1 @@ -2200,8 +2248,8 @@ def _reduce_127(val, _values, result) end .,., -module_eval(<<'.,.,', 'parser.y', 512) - def _reduce_128(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 529) + def _reduce_132(val, _values, result) end_c_declaration @grammar.epilogue = val[2].s_value @@ -2209,36 +2257,36 @@ def _reduce_128(val, _values, result) end .,., -# reduce 129 omitted +# reduce 133 omitted -# reduce 130 omitted +# reduce 134 omitted -# reduce 131 omitted +# reduce 135 omitted -# reduce 132 omitted +# reduce 136 omitted -# reduce 133 omitted +# reduce 137 omitted -module_eval(<<'.,.,', 'parser.y', 523) - def _reduce_134(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 540) + def _reduce_138(val, _values, result) result = [val[0]] result end .,., -module_eval(<<'.,.,', 'parser.y', 524) - def _reduce_135(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 541) + def _reduce_139(val, _values, result) result = val[0].append(val[1]) result end .,., -# reduce 136 omitted +# reduce 140 omitted -# reduce 137 omitted +# reduce 141 omitted -module_eval(<<'.,.,', 'parser.y', 529) - def _reduce_138(val, _values, result) +module_eval(<<'.,.,', 'parser.y', 546) + def _reduce_142(val, _values, result) result = Lrama::Lexer::Token::Ident.new(s_value: val[0]) result end diff --git a/parser.y b/parser.y index 987390bc..a5a97073 100644 --- a/parser.y +++ b/parser.y @@ -30,6 +30,8 @@ rule | bison_declarations bison_declaration ";"? bison_declaration: grammar_declaration + | rule_declaration + | inline_declaration | "%expect" INTEGER { @grammar.expect = val[1] } | "%define" variable value | "%param" params @@ -87,8 +89,6 @@ rule ) } | symbol_declaration - | rule_declaration - | inline_declaration | "%destructor" "{" { begin_c_declaration("}") @@ -394,6 +394,7 @@ rule | grammar rules_or_grammar_declaration rules_or_grammar_declaration: rules ";"? + | parameterizing_rules ";"? | grammar_declaration ";" rules: id_colon named_ref_opt ":" rhs_list @@ -488,6 +489,22 @@ rule result = builder } + parameterizing_rules: IDENTIFIER "(" rule_args ")" TAG? ":" rule_rhs_list + { + rule = Grammar::ParameterizingRule::Rule.new(val[0].s_value, val[2], val[6], tag: val[4]) + @grammar.add_parameterizing_rule(rule) + } + | "%inline" id_colon ":" rule_rhs_list + { + rule = Grammar::ParameterizingRule::Rule.new(val[1].s_value, [], val[3], is_inline: true) + @grammar.add_parameterizing_rule(rule) + } + | "%inline" IDENTIFIER "(" rule_args ")" ":" rule_rhs_list + { + rule = Grammar::ParameterizingRule::Rule.new(val[1].s_value, val[3], val[6], is_inline: true) + @grammar.add_parameterizing_rule(rule) + } + parameterizing_suffix: "?" { result = "option" } | "+" { result = "nonempty_list" } | "*" { result = "list" } diff --git a/spec/fixtures/inlining/basic.y b/spec/fixtures/inlining/basic.y index 1db03da3..8d2e7d38 100644 --- a/spec/fixtures/inlining/basic.y +++ b/spec/fixtures/inlining/basic.y @@ -29,9 +29,9 @@ expression : NUM ; -%rule %inline other_op : '%' { + 1 + } - | '&' { - 1 - } - ; +%inline other_op : '%' { + 1 + } + | '&' { - 1 - } + ; %% diff --git a/spec/fixtures/parameterizing_rules/user_defined/basic.y b/spec/fixtures/parameterizing_rules/user_defined/basic.y index fb62f5fe..e5e86452 100644 --- a/spec/fixtures/parameterizing_rules/user_defined/basic.y +++ b/spec/fixtures/parameterizing_rules/user_defined/basic.y @@ -24,9 +24,9 @@ program : defined_option(number) | defined_list(number) ; -%rule defined_list(X): /* empty */ - | defined_list(X) number - ; +defined_list(X): /* empty */ + | defined_list(X) number + ; %%