1

ツリートップでパーサーを作成して、いくつかのラテックス コマンドを HTML マークアップに解析しようとしています。以下では、生成されたコードでデッドスピンが発生します。ソースコードをビルドしttてステップスルーしましたが、根本的な問題が何であるかを実際には解明していません (_nt_paragraph でスピンするだけです)。

Test input: "\emph{hey} and some more text."

grammar Latex
  rule document
    (paragraph)* {
      def content
        [:document, elements.map { |e| e.content }]
      end
    }
  end

  # Example: There aren't the \emph{droids you're looking for} \n\n. 
  rule paragraph
    ( text / tag )* eop {
      def content
        [:paragraph, elements.map { |e| e.content } ]
      end
    }
  end

  rule text
    ( !( tag_start / eop) . )* {
      def content
        [:text, text_value ]
      end
    }
  end

  # Example: \tag{inner_text}
  rule tag
    "\\emph{" inner_text '}' {
      def content
        [:tag, inner_text.content]
      end
    }
  end 

  # Example: \emph{inner_text}
  rule inner_text
    ( !'}' . )* {
      def content
        [:inner_text, text_value]
      end
    }
  end

  # End of paragraph.
  rule eop
    newline 2.. {
      def content
        [:newline, text_value]
      end
    }
  end

  rule newline
    "\n"
  end

  # You know, what starts a tag
  rule tag_start
    "\\"
  end

end
4

1 に答える 1

0

好奇心旺盛な人のために、ツリートップの開発グーグルグループのクリフォードがこれを理解しました。

問題は段落とテキストにありました。

テキストは0文字以上であり、段落内に0文字以上ある可能性があるため、最初の\ nの前に無限の長さの0文字があり、パーサーがデッドスピンしていました。修正は、テキストを次のように調整することでした。

( !( tag_start / eop) . )+

そのため、一致させるには少なくとも1つの文字が必要です。

于 2013-01-23T22:23:40.703 に答える