# frozen_string_literal: true require_relative "helper" module Plurimath class UnicodeMath module ParsingRules module Masked include Helper rule(:rect) { rect_symbols >> space? >> bracketed_masked_value(:rect) } rule(:sqrt) { (sqrt_symbols.as(:root_symbol) >> (exp_script | operand).as(:first_value)).as(:root) } rule(:qdrt) { (qdrt_symbols.as(:root_symbol) >> (exp_script | operand).as(:first_value)).as(:root) } rule(:cbrt) { (cbrt_symbols.as(:root_symbol) >> (exp_script | operand).as(:first_value)).as(:root) } rule(:color) { color_symbols >> space? >> bracketed_masked_value(:color) } rule(:phant) { phantom_symbols >> space? >> bracketed_masked_value(:phantom) } rule(:backcolor) { backcolor_symbols >> space? >> bracketed_masked_value(:backcolor) } rule(:cbrt_symbols) { str("∛") | str("\\cbrt") } rule(:qdrt_symbols) { str("∜") | str("\\cbrt") } rule(:rect_symbols) { str("▭") | str("\\rect") } rule(:sqrt_symbols) { str("√") | str("\\sqrt") | str("\\surd") } rule(:root_symbols) { str("⒭") | str("√") | str("\\root") | str("\\surd") } rule(:arg_function) do str("ⓐ").as(:arg) >> str("(") >> a_ascii.as(:arg_arguments).maybe >> space? >> expression.as(:first_value).maybe >> str(")") | str("ⓐ").as(:arg) >> a_ascii.as(:arg_arguments).maybe >> space? >> expression.as(:first_value).maybe end rule(:color_symbols) { str("✎") | str("\\color") } rule(:phantom_symbols) { str("⟡") | str("\\phantom") } rule(:monospace_fonts) { (str("ᅲ") >> str("(") >> match["^\)"].repeat(0).as(:monospace_value) >> str(")")).as(:monospace) } rule(:backcolor_symbols) { str("☁") | str("\\backcolor") } rule(:masked_recursive_value) { (space? >> expression | exp_bracket | exp_script).as(:expr) >> masked_recursive_value.as(:func_expr).maybe } rule(:root_invisible_character?) { (str("\\naryand").absent? >> invisible_unicode).maybe } rule(:nthrt) do (sqrt_symbols >> str("(") >> masked_recursive_value.as(:first_value) >> str("&") >> masked_recursive_value.as(:second_value) >> str(")")).as(:root) end rule(:binary_root) do root_symbols >> space? >> masked_recursive_value.as(:root_first_value) >> space? >> root_invisible_character? >> space? >> masked_recursive_value.as(:root_second_value) end rule(:intent_function) do str("ⓘ").as(:intent) >> str("(").as(:open_paren) >> parsing_text.as(:intent_arguments).maybe >> space? >> expression.as(:first_value).maybe >> str(")").as(:close_paren) | str("ⓘ").as(:intent) >> expression.as(:intent_expr) end def masked_value(func_name) match["^&"].repeat(1).as(:"#{func_name}_value") >> str("&") >> masked_recursive_value.as(:first_value) end def bracketed_masked_value(func_name) str("(") >> (masked_value(func_name).as(func_name)) >> str(")") end end end end end