Changeset 99fbcd0c28104c6667e723930c4c81b6a53fbd9e
- Timestamp:
- 05/21/2008 10:54:31 AM
(8 months ago)
- Author:
- mitchell <mitchell@frost.(none)>
- git-committer:
- mitchell <mitchell@frost.(none)> 1211392471 -0400
- git-parent:
[6dd1cc7d44eb156c271d773629ef5105c1dad2ce]
- git-author:
- mitchell <mitchell@frost.(none)> 1211392471 -0400
- Message:
Updated PARSER_DOC to include documentation on macros.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r5474d84 |
r99fbcd0 |
|
| 20 | 20 | |
|---|
| 21 | 21 | /************************* Required for every parser *************************/ |
|---|
| | 22 | #include "ragel_parser_macros.h" |
|---|
| 22 | 23 | |
|---|
| 23 | 24 | // the name of the language |
|---|
| … | … | |
| 89 | 90 | |
|---|
| 90 | 91 | %% write init; |
|---|
| 91 | | if (count) { |
|---|
| | 92 | if (count) |
|---|
| 92 | 93 | %% write exec c_line; |
|---|
| 93 | | // no newline at EOF; get contents of last line |
|---|
| 94 | | if ((whole_line_comment || line_contains_code) && callback) { |
|---|
| 95 | | if (line_contains_code) |
|---|
| 96 | | callback(C_LANG, "lcode", cint(line_start), cint(pe)); |
|---|
| 97 | | else if (whole_line_comment) |
|---|
| 98 | | callback(C_LANG, "lcomment", cint(line_start), cint(pe)); |
|---|
| 99 | | } |
|---|
| 100 | | } |
|---|
| | 94 | |
|---|
| | 95 | // if no newline at EOF; get contents of last line |
|---|
| | 96 | process_last_line(C_LANG) |
|---|
| 101 | 97 | } |
|---|
| 102 | 98 | |
|---|
| … | … | |
| 193 | 189 | whole_line_comment, and line_start state variables must be reset. All this |
|---|
| 194 | 190 | should be done within the main action shown below. |
|---|
| | 191 | Note: For most parsers, the std_newline(lang) macro is sufficient and does |
|---|
| | 192 | everything in the main action mentioned above. The lang parameter is the |
|---|
| | 193 | [lang]_LANG string. |
|---|
| 195 | 194 | |
|---|
| 196 | 195 | Main Action Structure: |
|---|
| … | … | |
| 225 | 224 | state variables. Then set the line_start variable to be p, the current |
|---|
| 226 | 225 | Ragel buffer position. Because line_contains_code and whole_line_comment |
|---|
| 227 | | have been reset, any non- newline and non-space character in the multi- |
|---|
| 228 | | line pattern should set line_contains_code or whole_line_comment back to |
|---|
| 229 | | 1. Otherwise you would count the line as blank. |
|---|
| | 226 | have been reset, any non-newline and non-space character in the multi-line |
|---|
| | 227 | pattern should set line_contains_code or whole_line_comment back to 1. |
|---|
| | 228 | Otherwise you would count the line as blank. |
|---|
| | 229 | Note: For most parsers, the std_internal_newline(lang) macro is sufficient |
|---|
| | 230 | and does everything in the main action mentioned above. The lang parameter |
|---|
| | 231 | is the [lang]_LANG string. |
|---|
| 230 | 232 | |
|---|
| 231 | 233 | For multi-line matches, it is important to call the 'code' or 'comment' |
|---|
| 232 | 234 | actions (mentioned earlier) before an internal newline is detected so the |
|---|
| 233 | 235 | line_contains_code and whole_line_comment variables are properly set. For |
|---|
| 234 | | other entities, you can add code for setting line_contains_code and |
|---|
| 235 | | whole_line_comment inside the switch statement of the main action. See the |
|---|
| 236 | | 'code' and 'comment' actions in 'common.rl' for the appropriate code. |
|---|
| | 236 | other entities, you can use the 'code' macro inside the main action which |
|---|
| | 237 | executes the same code as the Ragel 'code' action. Other C macros are |
|---|
| | 238 | 'comment' and 'ls', the latter is typically used for the SPACE entity when |
|---|
| | 239 | defining line_start. |
|---|
| 237 | 240 | |
|---|
| 238 | 241 | Notes: |
|---|