auto-parser


Nameauto-parser JSON
Version 0.0.0 PyPI version JSON
download
home_pagehttps://github.co.jp/
SummaryAutomaton-based Parsing Tool
upload_time2023-03-25 11:41:50
maintainer
docs_urlNone
authorle_lattelle
requires_python
licenseCC0 v1.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            下の方に日本語の説明があります


# Automaton-based Parsing [auto_parser]

This document describes a code for parsing and accepting a simple programming language using pushdown automaton transition rules. The transition rules are specified in `test_rules`.

## The parse function
The parse function takes a string, analyzes it, and performs parsing. It takes the following arguments:

target_str: The string to be analyzed
rules: A list of transition rules
init_state: The initial state
init_stack: The initial stack

The function performs parsing so that the stack has one element in the final state of the analysis and returns the result.

## Specifying transition rules
Transition rules are specified in `test_rules` in YAML format. Each transition rule is an object with the following elements:

"cond": If the current state meets this condition, this transition rule is applied.
"pop_n": The number of elements to pop from the stack.
"push_0": Specifies the value to push onto the stack.
"post_state": An object specifying the state after the transition.

【Example 1】
The following example shows one transition rule in `test_rules`:

```yaml
[
  {
    "cond": {
      "@head": [" ", "\n", "\t", ","],
      "state": "in_symbol"
    },
    "pop_n": 0,
    "post_state": {
      "state": "outer"
    }
  },
  ...
]
```

This transition rule is applied when the current `@head` is a whitespace character and the current state is `in_symbol`. This rule does not pop any elements from the stack and changes the state to `outer` after the transition.

【Example 2】
The following transition rule is an example of a rule for processing the beginning of a symbol during parsing:

```yaml
[
  {
    "cond": {
      "state": "outer"
    },
    "pop_n": 2,
    "push_0": ["@+", "@p1", ["@p0"]],
    "push_1": ["symbol", "@head"],
    "post_state": {
      "state": "in_symbol"
    }
  },
  ...
]
```

This rule is applied when the current state is outer.

Stack operations:

- First, pop two elements from the stack.
- The popped elements can be referenced with @p0 and @p1.
- Then, push two elements.
	- push_0: Create a new list by combining the popped elements. Combine @p1 followed by @p0.
	- push_1: Create a list ["symbol", "@head"] and use the current @head as-is.

Post-transition state:
After applying this transition rule, the state changes to in_symbol, indicating that the symbol is being analyzed.

## How to use

You can use this code to parse the target string by following these steps:

- Specify the target string to be analyzed as target_str.
- Specify the list of transition rules as rules.
- Specify the initial state as init_state.
- Specify the initial stack as init_stack.
- Execute the parse function and obtain the parsing result.

Here is an example of usage:

```python
res = parse(
    target_str = fies["test_input.txt"],    # The target string to be analyzed
    rules = fies["test_rules.yml"],    # The list of transition rules
	init_state = {"state": "args_start"}, # The initial state
	init_stack = [["lines"]], # The initial stack
)   
```
In the above code, `fies["test_input.txt"]` is specified as the target string to be analyzed, and `fies["test_rules.yml"]` is specified as the list of transition rules. The initial state is `args_start`, and the initial stack is `[["lines"]]`. When you execute the `parse` function, you obtain the parsing result.

## Precautions
This code expects that the final state of the stack will have one element when parsing is performed correctly. If this expectation is not met, an exception will be raised.

Also, if no suitable transition rules are found during the parsing process, an error will occur. To resolve this issue, review the transition rules or change the target string to be analyzed.

## Summary
In this document, we explained the code for parsing and accepting a simple programming language and how to specify transition rules. We also explained how to use the `parse` function and the precautions to be aware of. It is expected that this code can be used to handle various programming languages and simple tools that require parsing.

## Supplement: Examples of Transition Rules for Simple Programming Languages
Examples of concrete transition rules are given in Japanese at the end of the document in the section `## 補足: 簡単なプログラミング言語の遷移規則の例`.


# オートマトンによる構文解析 [auto_parser]

このドキュメントでは、簡単なプログラミング言語を受理してパース(構文解析)するコードについて説明します。このコードは、プッシュダウンオートマトンの遷移規則を使用しています。遷移規則は、test_rulesに指定されています。

## parse関数
parse関数は、文字列を解析し、構文解析を行います。以下の引数を受け取ります。

target_str: 解析対象の文字列
rules: 遷移規則一覧
init_state: 初期state
init_stack: 初期stack

この関数は、解析の最終状態でstackが1つの要素を持つように構文解析を行い、その結果を返します。

## 遷移規則の指定方法
遷移規則は、 `test_rules` にYAML形式で指定します。各遷移規則は、以下の要素を持つオブジェクトです。

"cond": 現在のstateがこの条件を満たす場合、この遷移規則が適用されます。
"pop_n": stackからpopする要素の数です。
"push_0": stackにpushする値を指定します。
"post_state": 遷移後のstateを指定するオブジェクトです。

【例1】
次の例は、 `test_rules` 内の1つの遷移規則を示しています。

```yaml
[
  {
    "cond": {
      "@head": [" ", "\n", "\t", ","],
      "state": "in_symbol"
    },
    "pop_n": 0,
    "post_state": {
      "state": "outer"
    }
  },
  ...
]
```

この遷移規則は、現在の `@head` が空白文字であり、現在のstateが `in_symbol` の場合に適用されます。この遷移規則は、stackから要素をpopせず、遷移後のstateを `outer` に変更します。

【例2】
以下の遷移規則は、解析中にシンボルの冒頭を処理するルールの例です。
```yaml
[
  {
    "cond": {
      "state": "outer"
    },
    "pop_n": 2,
    "push_0": ["@+", "@p1", ["@p0"]],
    "push_1": ["symbol", "@head"],
    "post_state": {
      "state": "in_symbol"
    }
  },
  ...
]
```

この遷移規則は、現在のstateがouterの場合に適用されます。

stack操作
- まず、stackから2つの要素をpopします。
- popした要素は、@p0と@p1で参照できます。
- 次に、2つの要素をpushします。
	- push_0: popした要素を結合して新たなリストを作成します。@p1に続いて@p0を結合します。
	- push_1: ["symbol", "@head"]というリストを作成し、現在の@headをそのまま使用します。

遷移後のstate
この遷移規則が適用された後、stateはin_symbolに変更されます。これは、シンボルの解析中であることを示しています。

## 使用方法
以下の手順で、このコードを使用して解析対象の文字列を構文解析できます。

- 解析対象の文字列をtarget_strとして指定します。
- 遷移規則一覧をrulesとして指定します。
- 初期stateをinit_stateとして指定します。
- 初期stackをinit_stackとして指定します。
- parse関数を実行し、構文解析結果を取得します。

以下は、使用例です。

```python
res = parse(
    target_str = fies["test_input.txt"],    # 解析対象の文字列
    rules = fies["test_rules.yml"],    # 遷移規則一覧
	init_state = {"state": "args_start"}, # 初期state
	init_stack = [["lines"]], # 初期stack
)   
```

上記のコードでは、`fies["test_input.txt"]`を解析対象の文字列として指定し、`fies["test_rules.yml"]`を遷移規則一覧として指定しています。初期stateは`args_start`であり、初期stackは`[["lines"]]`です。`parse`関数を実行すると、構文解析結果が得られます。

## 注意事項

このコードは、構文解析が正しく行われた場合にstackの最終状態が1つの要素を持つことを期待しています。この期待に反する場合、例外が発生します。

また、構文解析の過程で適合する遷移規則が見つからない場合、エラーが発生します。この問題を解決するには、遷移規則を見直すか、解析対象の文字列を変更してください。

## まとめ

このドキュメントでは、簡単なプログラミング言語を受理してパース(構文解析)するコードと、遷移規則の指定方法について説明しました。また、`parse` 関数の使い方と注意事項についても説明しました。このコードを使用して、構文解析が必要なさまざまなプログラミング言語・簡易ツールに対応できることが期待されます。


## 補足: 簡単なプログラミング言語の遷移規則の例
入力:
```c
hoge()
fuga(
	a,
	b,
	c,
)
func(a b c)
```

呼び出し方:
```python
import auto_parser

# 構文解析 [auto_parser]
res = auto_parser.parse(
	target_str = "解析対象文字列",	# 解析対象の文字列
	rules = "下記に示した遷移規則",	# 遷移規則一覧
	init_state = {"state": "args_start"},	# 初期state
	init_stack = [["lines"]],	# 初期stack
)
```

出力:
```python
[
  "lines",
  ["call", ["symbol", "h", "o", "g", "e"]],
  [
    "call",
    ["symbol", "f", "u", "g", "a"],
    ["symbol", "a"],
    ["symbol", "b"],
    ["symbol", "c"]
  ],
  [
    "call",
    ["symbol", "f", "u", "n", "c"],
    ["symbol", "a"],
    ["symbol", "b"],
    ["symbol", "c"]
  ]
]
```

遷移規則:
```yaml
[
  # symbol後の空白文字
  {
    "cond": {
      "@head": [" ", "\n", "\t", ","],
      "state": "in_symbol"
    },
    "pop_n": 0,
    "post_state": {
      "state": "outer"
    }
  },
  # 空白文字
  {
    "cond": {
      "@head": [" ", "\n", "\t", ","]
    },
    "pop_n": 0,
    "post_state": {}
  },
  # 関数のカッコ開き
  {
    "cond": {
      "@head": "("
    },
    "pop_n": 1,
    "push_0": ["call", "@p0"],
    "post_state": {
      "state": "args_start"
    }
  },
  # argなし関数のカッコ閉じ
  {
    "cond": {
      "@head": [")", "@end"],
      "state": "args_start"
    },
    "pop_n": 0,
    "post_state": {
      "state": "outer"
    }
  },
  # 関数のカッコ閉じ
  {
    "cond": {
      "@head": [")", "@end"]
    },
    "pop_n": 2,
    "push_0": ["@+", "@p1", ["@p0"]],
    "post_state": {
      "state": "outer"
    }
  },
  # 第0argのsymbol冒頭
  {
    "cond": {
      "state": "args_start"
    },
    "pop_n": 0,
    "push_0": ["symbol", "@head"],
    "post_state": {
      "state": "in_symbol"
    }
  },
  # symbol冒頭
  {
    "cond": {
      "state": "outer"
    },
    "pop_n": 2,
    "push_0": ["@+", "@p1", ["@p0"]],
    "push_1": ["symbol", "@head"],
    "post_state": {
      "state": "in_symbol"
    }
  },
  # symbol内
  {
    "cond": {
      "state": "in_symbol"
    },
    "pop_n": 1,
    "push_0": ["@+", "@p0", ["@head"]],
    "post_state": {}
  },
]
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.co.jp/",
    "name": "auto-parser",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "le_lattelle",
    "author_email": "g.tiger.ml@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/9f/49/0635cf9e7f258cd2c0e1cafcbcb78b8bea8a454f67afa5ac6e48556eeb8c/auto-parser-0.0.0.tar.gz",
    "platform": null,
    "description": "\u4e0b\u306e\u65b9\u306b\u65e5\u672c\u8a9e\u306e\u8aac\u660e\u304c\u3042\u308a\u307e\u3059\n\n\n# Automaton-based Parsing [auto_parser]\n\nThis document describes a code for parsing and accepting a simple programming language using pushdown automaton transition rules. The transition rules are specified in `test_rules`.\n\n## The parse function\nThe parse function takes a string, analyzes it, and performs parsing. It takes the following arguments:\n\ntarget_str: The string to be analyzed\nrules: A list of transition rules\ninit_state: The initial state\ninit_stack: The initial stack\n\nThe function performs parsing so that the stack has one element in the final state of the analysis and returns the result.\n\n## Specifying transition rules\nTransition rules are specified in `test_rules` in YAML format. Each transition rule is an object with the following elements:\n\n\"cond\": If the current state meets this condition, this transition rule is applied.\n\"pop_n\": The number of elements to pop from the stack.\n\"push_0\": Specifies the value to push onto the stack.\n\"post_state\": An object specifying the state after the transition.\n\n\u3010Example 1\u3011\nThe following example shows one transition rule in `test_rules`:\n\n```yaml\n[\n  {\n    \"cond\": {\n      \"@head\": [\" \", \"\\n\", \"\\t\", \",\"],\n      \"state\": \"in_symbol\"\n    },\n    \"pop_n\": 0,\n    \"post_state\": {\n      \"state\": \"outer\"\n    }\n  },\n  ...\n]\n```\n\nThis transition rule is applied when the current `@head` is a whitespace character and the current state is `in_symbol`. This rule does not pop any elements from the stack and changes the state to `outer` after the transition.\n\n\u3010Example 2\u3011\nThe following transition rule is an example of a rule for processing the beginning of a symbol during parsing:\n\n```yaml\n[\n  {\n    \"cond\": {\n      \"state\": \"outer\"\n    },\n    \"pop_n\": 2,\n    \"push_0\": [\"@+\", \"@p1\", [\"@p0\"]],\n    \"push_1\": [\"symbol\", \"@head\"],\n    \"post_state\": {\n      \"state\": \"in_symbol\"\n    }\n  },\n  ...\n]\n```\n\nThis rule is applied when the current state is outer.\n\nStack operations:\n\n- First, pop two elements from the stack.\n- The popped elements can be referenced with @p0 and @p1.\n- Then, push two elements.\n\t- push_0: Create a new list by combining the popped elements. Combine @p1 followed by @p0.\n\t- push_1: Create a list [\"symbol\", \"@head\"] and use the current @head as-is.\n\nPost-transition state:\nAfter applying this transition rule, the state changes to in_symbol, indicating that the symbol is being analyzed.\n\n## How to use\n\nYou can use this code to parse the target string by following these steps:\n\n- Specify the target string to be analyzed as target_str.\n- Specify the list of transition rules as rules.\n- Specify the initial state as init_state.\n- Specify the initial stack as init_stack.\n- Execute the parse function and obtain the parsing result.\n\nHere is an example of usage:\n\n```python\nres = parse(\n    target_str = fies[\"test_input.txt\"],    # The target string to be analyzed\n    rules = fies[\"test_rules.yml\"],    # The list of transition rules\n\tinit_state = {\"state\": \"args_start\"}, # The initial state\n\tinit_stack = [[\"lines\"]], # The initial stack\n)   \n```\nIn the above code, `fies[\"test_input.txt\"]` is specified as the target string to be analyzed, and `fies[\"test_rules.yml\"]` is specified as the list of transition rules. The initial state is `args_start`, and the initial stack is `[[\"lines\"]]`. When you execute the `parse` function, you obtain the parsing result.\n\n## Precautions\nThis code expects that the final state of the stack will have one element when parsing is performed correctly. If this expectation is not met, an exception will be raised.\n\nAlso, if no suitable transition rules are found during the parsing process, an error will occur. To resolve this issue, review the transition rules or change the target string to be analyzed.\n\n## Summary\nIn this document, we explained the code for parsing and accepting a simple programming language and how to specify transition rules. We also explained how to use the `parse` function and the precautions to be aware of. It is expected that this code can be used to handle various programming languages and simple tools that require parsing.\n\n## Supplement: Examples of Transition Rules for Simple Programming Languages\nExamples of concrete transition rules are given in Japanese at the end of the document in the section `## \u88dc\u8db3: \u7c21\u5358\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u9077\u79fb\u898f\u5247\u306e\u4f8b`.\n\n\n# \u30aa\u30fc\u30c8\u30de\u30c8\u30f3\u306b\u3088\u308b\u69cb\u6587\u89e3\u6790 [auto_parser]\n\n\u3053\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3067\u306f\u3001\u7c21\u5358\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3092\u53d7\u7406\u3057\u3066\u30d1\u30fc\u30b9\uff08\u69cb\u6587\u89e3\u6790\uff09\u3059\u308b\u30b3\u30fc\u30c9\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3001\u30d7\u30c3\u30b7\u30e5\u30c0\u30a6\u30f3\u30aa\u30fc\u30c8\u30de\u30c8\u30f3\u306e\u9077\u79fb\u898f\u5247\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002\u9077\u79fb\u898f\u5247\u306f\u3001test_rules\u306b\u6307\u5b9a\u3055\u308c\u3066\u3044\u307e\u3059\u3002\n\n## parse\u95a2\u6570\nparse\u95a2\u6570\u306f\u3001\u6587\u5b57\u5217\u3092\u89e3\u6790\u3057\u3001\u69cb\u6587\u89e3\u6790\u3092\u884c\u3044\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u5f15\u6570\u3092\u53d7\u3051\u53d6\u308a\u307e\u3059\u3002\n\ntarget_str: \u89e3\u6790\u5bfe\u8c61\u306e\u6587\u5b57\u5217\nrules: \u9077\u79fb\u898f\u5247\u4e00\u89a7\ninit_state: \u521d\u671fstate\ninit_stack: \u521d\u671fstack\n\n\u3053\u306e\u95a2\u6570\u306f\u3001\u89e3\u6790\u306e\u6700\u7d42\u72b6\u614b\u3067stack\u304c1\u3064\u306e\u8981\u7d20\u3092\u6301\u3064\u3088\u3046\u306b\u69cb\u6587\u89e3\u6790\u3092\u884c\u3044\u3001\u305d\u306e\u7d50\u679c\u3092\u8fd4\u3057\u307e\u3059\u3002\n\n## \u9077\u79fb\u898f\u5247\u306e\u6307\u5b9a\u65b9\u6cd5\n\u9077\u79fb\u898f\u5247\u306f\u3001 `test_rules` \u306bYAML\u5f62\u5f0f\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002\u5404\u9077\u79fb\u898f\u5247\u306f\u3001\u4ee5\u4e0b\u306e\u8981\u7d20\u3092\u6301\u3064\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3059\u3002\n\n\"cond\": \u73fe\u5728\u306estate\u304c\u3053\u306e\u6761\u4ef6\u3092\u6e80\u305f\u3059\u5834\u5408\u3001\u3053\u306e\u9077\u79fb\u898f\u5247\u304c\u9069\u7528\u3055\u308c\u307e\u3059\u3002\n\"pop_n\": stack\u304b\u3089pop\u3059\u308b\u8981\u7d20\u306e\u6570\u3067\u3059\u3002\n\"push_0\": stack\u306bpush\u3059\u308b\u5024\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\n\"post_state\": \u9077\u79fb\u5f8c\u306estate\u3092\u6307\u5b9a\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3059\u3002\n\n\u3010\u4f8b1\u3011\n\u6b21\u306e\u4f8b\u306f\u3001 `test_rules` \u5185\u306e1\u3064\u306e\u9077\u79fb\u898f\u5247\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002\n\n```yaml\n[\n  {\n    \"cond\": {\n      \"@head\": [\" \", \"\\n\", \"\\t\", \",\"],\n      \"state\": \"in_symbol\"\n    },\n    \"pop_n\": 0,\n    \"post_state\": {\n      \"state\": \"outer\"\n    }\n  },\n  ...\n]\n```\n\n\u3053\u306e\u9077\u79fb\u898f\u5247\u306f\u3001\u73fe\u5728\u306e `@head` \u304c\u7a7a\u767d\u6587\u5b57\u3067\u3042\u308a\u3001\u73fe\u5728\u306estate\u304c `in_symbol` \u306e\u5834\u5408\u306b\u9069\u7528\u3055\u308c\u307e\u3059\u3002\u3053\u306e\u9077\u79fb\u898f\u5247\u306f\u3001stack\u304b\u3089\u8981\u7d20\u3092pop\u305b\u305a\u3001\u9077\u79fb\u5f8c\u306estate\u3092 `outer` \u306b\u5909\u66f4\u3057\u307e\u3059\u3002\n\n\u3010\u4f8b2\u3011\n\u4ee5\u4e0b\u306e\u9077\u79fb\u898f\u5247\u306f\u3001\u89e3\u6790\u4e2d\u306b\u30b7\u30f3\u30dc\u30eb\u306e\u5192\u982d\u3092\u51e6\u7406\u3059\u308b\u30eb\u30fc\u30eb\u306e\u4f8b\u3067\u3059\u3002\n```yaml\n[\n  {\n    \"cond\": {\n      \"state\": \"outer\"\n    },\n    \"pop_n\": 2,\n    \"push_0\": [\"@+\", \"@p1\", [\"@p0\"]],\n    \"push_1\": [\"symbol\", \"@head\"],\n    \"post_state\": {\n      \"state\": \"in_symbol\"\n    }\n  },\n  ...\n]\n```\n\n\u3053\u306e\u9077\u79fb\u898f\u5247\u306f\u3001\u73fe\u5728\u306estate\u304couter\u306e\u5834\u5408\u306b\u9069\u7528\u3055\u308c\u307e\u3059\u3002\n\nstack\u64cd\u4f5c\n- \u307e\u305a\u3001stack\u304b\u30892\u3064\u306e\u8981\u7d20\u3092pop\u3057\u307e\u3059\u3002\n- pop\u3057\u305f\u8981\u7d20\u306f\u3001@p0\u3068@p1\u3067\u53c2\u7167\u3067\u304d\u307e\u3059\u3002\n- \u6b21\u306b\u30012\u3064\u306e\u8981\u7d20\u3092push\u3057\u307e\u3059\u3002\n\t- push_0: pop\u3057\u305f\u8981\u7d20\u3092\u7d50\u5408\u3057\u3066\u65b0\u305f\u306a\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002@p1\u306b\u7d9a\u3044\u3066@p0\u3092\u7d50\u5408\u3057\u307e\u3059\u3002\n\t- push_1: [\"symbol\", \"@head\"]\u3068\u3044\u3046\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u3001\u73fe\u5728\u306e@head\u3092\u305d\u306e\u307e\u307e\u4f7f\u7528\u3057\u307e\u3059\u3002\n\n\u9077\u79fb\u5f8c\u306estate\n\u3053\u306e\u9077\u79fb\u898f\u5247\u304c\u9069\u7528\u3055\u308c\u305f\u5f8c\u3001state\u306fin_symbol\u306b\u5909\u66f4\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u30b7\u30f3\u30dc\u30eb\u306e\u89e3\u6790\u4e2d\u3067\u3042\u308b\u3053\u3068\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002\n\n## \u4f7f\u7528\u65b9\u6cd5\n\u4ee5\u4e0b\u306e\u624b\u9806\u3067\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u7528\u3057\u3066\u89e3\u6790\u5bfe\u8c61\u306e\u6587\u5b57\u5217\u3092\u69cb\u6587\u89e3\u6790\u3067\u304d\u307e\u3059\u3002\n\n- \u89e3\u6790\u5bfe\u8c61\u306e\u6587\u5b57\u5217\u3092target_str\u3068\u3057\u3066\u6307\u5b9a\u3057\u307e\u3059\u3002\n- \u9077\u79fb\u898f\u5247\u4e00\u89a7\u3092rules\u3068\u3057\u3066\u6307\u5b9a\u3057\u307e\u3059\u3002\n- \u521d\u671fstate\u3092init_state\u3068\u3057\u3066\u6307\u5b9a\u3057\u307e\u3059\u3002\n- \u521d\u671fstack\u3092init_stack\u3068\u3057\u3066\u6307\u5b9a\u3057\u307e\u3059\u3002\n- parse\u95a2\u6570\u3092\u5b9f\u884c\u3057\u3001\u69cb\u6587\u89e3\u6790\u7d50\u679c\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002\n\n\u4ee5\u4e0b\u306f\u3001\u4f7f\u7528\u4f8b\u3067\u3059\u3002\n\n```python\nres = parse(\n    target_str = fies[\"test_input.txt\"],    # \u89e3\u6790\u5bfe\u8c61\u306e\u6587\u5b57\u5217\n    rules = fies[\"test_rules.yml\"],    # \u9077\u79fb\u898f\u5247\u4e00\u89a7\n\tinit_state = {\"state\": \"args_start\"}, # \u521d\u671fstate\n\tinit_stack = [[\"lines\"]], # \u521d\u671fstack\n)   \n```\n\n\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001`fies[\"test_input.txt\"]`\u3092\u89e3\u6790\u5bfe\u8c61\u306e\u6587\u5b57\u5217\u3068\u3057\u3066\u6307\u5b9a\u3057\u3001`fies[\"test_rules.yml\"]`\u3092\u9077\u79fb\u898f\u5247\u4e00\u89a7\u3068\u3057\u3066\u6307\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002\u521d\u671fstate\u306f`args_start`\u3067\u3042\u308a\u3001\u521d\u671fstack\u306f`[[\"lines\"]]`\u3067\u3059\u3002`parse`\u95a2\u6570\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u69cb\u6587\u89e3\u6790\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059\u3002\n\n## \u6ce8\u610f\u4e8b\u9805\n\n\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3001\u69cb\u6587\u89e3\u6790\u304c\u6b63\u3057\u304f\u884c\u308f\u308c\u305f\u5834\u5408\u306bstack\u306e\u6700\u7d42\u72b6\u614b\u304c1\u3064\u306e\u8981\u7d20\u3092\u6301\u3064\u3053\u3068\u3092\u671f\u5f85\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u671f\u5f85\u306b\u53cd\u3059\u308b\u5834\u5408\u3001\u4f8b\u5916\u304c\u767a\u751f\u3057\u307e\u3059\u3002\n\n\u307e\u305f\u3001\u69cb\u6587\u89e3\u6790\u306e\u904e\u7a0b\u3067\u9069\u5408\u3059\u308b\u9077\u79fb\u898f\u5247\u304c\u898b\u3064\u304b\u3089\u306a\u3044\u5834\u5408\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002\u3053\u306e\u554f\u984c\u3092\u89e3\u6c7a\u3059\u308b\u306b\u306f\u3001\u9077\u79fb\u898f\u5247\u3092\u898b\u76f4\u3059\u304b\u3001\u89e3\u6790\u5bfe\u8c61\u306e\u6587\u5b57\u5217\u3092\u5909\u66f4\u3057\u3066\u304f\u3060\u3055\u3044\u3002\n\n## \u307e\u3068\u3081\n\n\u3053\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3067\u306f\u3001\u7c21\u5358\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3092\u53d7\u7406\u3057\u3066\u30d1\u30fc\u30b9\uff08\u69cb\u6587\u89e3\u6790\uff09\u3059\u308b\u30b3\u30fc\u30c9\u3068\u3001\u9077\u79fb\u898f\u5247\u306e\u6307\u5b9a\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u305f\u3002\u307e\u305f\u3001`parse` \u95a2\u6570\u306e\u4f7f\u3044\u65b9\u3068\u6ce8\u610f\u4e8b\u9805\u306b\u3064\u3044\u3066\u3082\u8aac\u660e\u3057\u307e\u3057\u305f\u3002\u3053\u306e\u30b3\u30fc\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001\u69cb\u6587\u89e3\u6790\u304c\u5fc5\u8981\u306a\u3055\u307e\u3056\u307e\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u30fb\u7c21\u6613\u30c4\u30fc\u30eb\u306b\u5bfe\u5fdc\u3067\u304d\u308b\u3053\u3068\u304c\u671f\u5f85\u3055\u308c\u307e\u3059\u3002\n\n\n## \u88dc\u8db3: \u7c21\u5358\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306e\u9077\u79fb\u898f\u5247\u306e\u4f8b\n\u5165\u529b:\n```c\nhoge()\nfuga(\n\ta,\n\tb,\n\tc,\n)\nfunc(a b c)\n```\n\n\u547c\u3073\u51fa\u3057\u65b9:\n```python\nimport auto_parser\n\n# \u69cb\u6587\u89e3\u6790 [auto_parser]\nres = auto_parser.parse(\n\ttarget_str = \"\u89e3\u6790\u5bfe\u8c61\u6587\u5b57\u5217\",\t# \u89e3\u6790\u5bfe\u8c61\u306e\u6587\u5b57\u5217\n\trules = \"\u4e0b\u8a18\u306b\u793a\u3057\u305f\u9077\u79fb\u898f\u5247\",\t# \u9077\u79fb\u898f\u5247\u4e00\u89a7\n\tinit_state = {\"state\": \"args_start\"},\t# \u521d\u671fstate\n\tinit_stack = [[\"lines\"]],\t# \u521d\u671fstack\n)\n```\n\n\u51fa\u529b:\n```python\n[\n  \"lines\",\n  [\"call\", [\"symbol\", \"h\", \"o\", \"g\", \"e\"]],\n  [\n    \"call\",\n    [\"symbol\", \"f\", \"u\", \"g\", \"a\"],\n    [\"symbol\", \"a\"],\n    [\"symbol\", \"b\"],\n    [\"symbol\", \"c\"]\n  ],\n  [\n    \"call\",\n    [\"symbol\", \"f\", \"u\", \"n\", \"c\"],\n    [\"symbol\", \"a\"],\n    [\"symbol\", \"b\"],\n    [\"symbol\", \"c\"]\n  ]\n]\n```\n\n\u9077\u79fb\u898f\u5247:\n```yaml\n[\n  # symbol\u5f8c\u306e\u7a7a\u767d\u6587\u5b57\n  {\n    \"cond\": {\n      \"@head\": [\" \", \"\\n\", \"\\t\", \",\"],\n      \"state\": \"in_symbol\"\n    },\n    \"pop_n\": 0,\n    \"post_state\": {\n      \"state\": \"outer\"\n    }\n  },\n  # \u7a7a\u767d\u6587\u5b57\n  {\n    \"cond\": {\n      \"@head\": [\" \", \"\\n\", \"\\t\", \",\"]\n    },\n    \"pop_n\": 0,\n    \"post_state\": {}\n  },\n  # \u95a2\u6570\u306e\u30ab\u30c3\u30b3\u958b\u304d\n  {\n    \"cond\": {\n      \"@head\": \"(\"\n    },\n    \"pop_n\": 1,\n    \"push_0\": [\"call\", \"@p0\"],\n    \"post_state\": {\n      \"state\": \"args_start\"\n    }\n  },\n  # arg\u306a\u3057\u95a2\u6570\u306e\u30ab\u30c3\u30b3\u9589\u3058\n  {\n    \"cond\": {\n      \"@head\": [\")\", \"@end\"],\n      \"state\": \"args_start\"\n    },\n    \"pop_n\": 0,\n    \"post_state\": {\n      \"state\": \"outer\"\n    }\n  },\n  # \u95a2\u6570\u306e\u30ab\u30c3\u30b3\u9589\u3058\n  {\n    \"cond\": {\n      \"@head\": [\")\", \"@end\"]\n    },\n    \"pop_n\": 2,\n    \"push_0\": [\"@+\", \"@p1\", [\"@p0\"]],\n    \"post_state\": {\n      \"state\": \"outer\"\n    }\n  },\n  # \u7b2c0arg\u306esymbol\u5192\u982d\n  {\n    \"cond\": {\n      \"state\": \"args_start\"\n    },\n    \"pop_n\": 0,\n    \"push_0\": [\"symbol\", \"@head\"],\n    \"post_state\": {\n      \"state\": \"in_symbol\"\n    }\n  },\n  # symbol\u5192\u982d\n  {\n    \"cond\": {\n      \"state\": \"outer\"\n    },\n    \"pop_n\": 2,\n    \"push_0\": [\"@+\", \"@p1\", [\"@p0\"]],\n    \"push_1\": [\"symbol\", \"@head\"],\n    \"post_state\": {\n      \"state\": \"in_symbol\"\n    }\n  },\n  # symbol\u5185\n  {\n    \"cond\": {\n      \"state\": \"in_symbol\"\n    },\n    \"pop_n\": 1,\n    \"push_0\": [\"@+\", \"@p0\", [\"@head\"]],\n    \"post_state\": {}\n  },\n]\n```\n\n",
    "bugtrack_url": null,
    "license": "CC0 v1.0",
    "summary": "Automaton-based Parsing Tool",
    "version": "0.0.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "25e1a46743c27ae65a9680f6ac5fbf8a6a88eb088369e722171bafbb54aa3768",
                "md5": "93ee9e2c2c2ddd7063d01b483f9ceb17",
                "sha256": "8ec48e297d457fc1220940e2ce689cd940e40ba95c2a7995c32fd6dda6db197a"
            },
            "downloads": -1,
            "filename": "auto_parser-0.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "93ee9e2c2c2ddd7063d01b483f9ceb17",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7083,
            "upload_time": "2023-03-25T11:41:47",
            "upload_time_iso_8601": "2023-03-25T11:41:47.672087Z",
            "url": "https://files.pythonhosted.org/packages/25/e1/a46743c27ae65a9680f6ac5fbf8a6a88eb088369e722171bafbb54aa3768/auto_parser-0.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9f490635cf9e7f258cd2c0e1cafcbcb78b8bea8a454f67afa5ac6e48556eeb8c",
                "md5": "4823e0ff957aceb82aed8d194c598c0a",
                "sha256": "94e4448dad3165e213cc112249f27a38f64905e578e125dcf81867c1ba14f1b9"
            },
            "downloads": -1,
            "filename": "auto-parser-0.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4823e0ff957aceb82aed8d194c598c0a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8361,
            "upload_time": "2023-03-25T11:41:50",
            "upload_time_iso_8601": "2023-03-25T11:41:50.011580Z",
            "url": "https://files.pythonhosted.org/packages/9f/49/0635cf9e7f258cd2c0e1cafcbcb78b8bea8a454f67afa5ac6e48556eeb8c/auto-parser-0.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-25 11:41:50",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "auto-parser"
}
        
Elapsed time: 0.04931s