Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[enhance] compiler, syntax: parser, xml_parser look like match

  • Loading branch information...
commit e6a69f4301220cf920869f86457479a0a1b89577 1 parent 9a8aa72
@BourgerieQuentin BourgerieQuentin authored
View
10 opalang/js_syntax/opa_parser.trx
@@ -884,18 +884,22 @@ match_case <- (Opa_lexer.CASE / match_sep)
match_end_case <- (match_case $ / match_default_case $ / rbrace $)
-match_prod <- ( ((=deco(block_inner)):e &match_end_case {{e}}) / (expr:e &match_end_case {{e}}))
+match_expr <- (((=deco(block_inner)):e &match_end_case {{e}}) / (expr:e &match_end_case {{e}}))
-match_rule <- pattern:p colon match_prod:e
+match_prod <- match_right_separator match_expr:e {{e}}
+
+match_rule <- pattern:p match_prod:e
{{(p, e)}}
match_default_case <- Opa_lexer.DEFAULT $
-match_rule_default <- (=deco(match_default_case)):d colon match_prod:e
+match_rule_default <- (=deco(match_default_case)):d match_prod:e
{{(PatAny, snd d), e}}
match_sep <- Opa_lexer.BAR
+match_right_separator <- (colon / rarrow)
+
(* TODO REMOVE?*)
match_end <- (Opa_lexer.END $ / (=exact_ident("|_")) $)? (* use by xml_parser *)
View
11 opalang/js_syntax/trx.trx
@@ -32,10 +32,15 @@ deco_ml_identifier <- Opa_parser.deco_ml_identifier
{6 Main grammar}
*)
+lbrace <- Opa_lexer.lbrace $
+rbrace <- Opa_lexer.rbrace $
+
;Expression = deco(Expression_aux)
-Expression_aux <- Opa_lexer.BAR? ParserSeq:e (Opa_lexer.BAR ParserSeq:e {{e}})*:l {{ Trx_ast.Expr (e::l) }}
+Expression_aux <-
+ (Opa_parser.match_case ParserSeq:e {{e}})+:l
+ {{ Trx_ast.Expr l }}
-ExpressionAsFunction <- Opa_lexer.PARSER Expression:expr Opa_lexer.END? {{ expr }}
+ExpressionAsFunction <- Opa_lexer.PARSER lbrace Expression:expr rbrace {{ expr }}
Item = deco(Item_aux)
Item_aux <-
@@ -49,7 +54,7 @@ Item_aux <-
ParserSeq = deco(ParserSeq_aux)
ParserSeq_aux <- pos:pos Item+:items ParserCode?:pc {{ {Trx_ast.seq_items=items; Trx_ast.seq_code=pc} }}
-ParserCode <- Opa_lexer.rarrow Opa_parser.expr:e {{ e }}
+ParserCode <- Opa_parser.match_prod:e {{ e }}
SubruleName <- ml_identifier:v EQUAL {{ v }}
View
12 opalang/js_syntax/xml_parser.trx
@@ -25,23 +25,27 @@
}}
spacing <- Xml.spacing;
+lbrace <- Opa_lexer.lbrace $
+rbrace <- Opa_lexer.rbrace $
let deco rule = (=Opa_lexer.deco(rule));
let careful_deco rule = (=Opa_lexer.careful_deco(rule));
let exact_ident rule = (=Opa_parser.exact_ident(rule));
/** xml parser **/
-xml_parser <- (=Opa_lexer.exact_ident("xml_parser")) spacing xml_parser_no_keyword:v {{ v }}
+xml_parser <-
+ / (=Opa_lexer.exact_ident("xml_parser")) lbrace spacing xml_parser_no_keyword:v rbrace
+ {{ v }}
;deco_xml_parser_no_keyword = deco xml_parser_no_keyword;
xml_parser_no_keyword <-
- Opa_lexer.BAR? xml_rule:v (Opa_lexer.BAR xml_rule:v {{v}})*:l
- Opa_parser.match_end {{ (xml_parser (v::l : _ xml_parser) : (_,_) expr_node) }}
+ / (Opa_parser.match_case xml_rule:v {{v}})+:l
+ {{ (xml_parser (l : _ xml_parser) : (_,_) expr_node) }}
trx_parser <- Opa_lexer.PARSER? Trx.Item+:l (*Trx.ParserSeq:e*) {{ l }}
/** xml parser rule **/
-xml_rule <- spacing xml_named_pattern+:pl Opa_lexer.rarrow Opa_parser.expr:e {{ ((pl,e) : _ xml_rule) }}
+xml_rule <- spacing xml_named_pattern+:pl Opa_parser.match_prod:e {{ ((pl,e) : _ xml_rule) }}
ident_except_parser <- !("parser" Opa_lexer.end_of_ident_nosp) Opa_lexer.ml_identifier:i {{ i }}

0 comments on commit e6a69f4

Please sign in to comment.
Something went wrong with that request. Please try again.