Changeset 6 for trunk/YamlReference/Text/Yaml/Reference.hs
- Timestamp:
- 04/06/08 04:24:28 (9 months ago)
- Files:
-
- 1 modified
-
trunk/YamlReference/Text/Yaml/Reference.hs (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/YamlReference/Text/Yaml/Reference.hs
r5 r6 28 28 -- For testing: 29 29 Context, 30 Style,31 30 Chomp, 32 31 tokenizer, 33 32 tokenizerWithN, 34 33 tokenizerWithC, 35 tokenizerWithS,36 34 tokenizerWithT, 37 35 tokenizerWithNC, 38 tokenizerWithNS,39 36 tokenizerWithNT, 40 37 tokenizerNames, … … 651 648 infix 3 ! 652 649 infix 3 ?! 650 infix 3 <? 651 infix 3 >? 653 652 infixl 3 - 654 653 infixr 2 & … … 676 675 decision ^ parser = choice decision (match parser) 677 676 678 -- | @parser ! decision@ commits to /decision/ after successfully matching the679 -- /parser/.677 -- | @parser ! decision@ commits to /decision/ (in an option) after 678 -- successfully matching the /parser/. 680 679 (!) :: (Match match result) => match -> String -> Pattern 681 680 parser ! decision = parser & commit decision 682 681 683 -- | @parser ?! decision@ commits to /decision/ if the current position matches684 -- /parser/, without consuming any characters.682 -- | @parser ?! decision@ commits to /decision/ (in an option) if the current 683 -- position matches /parser/, without consuming any characters. 685 684 (?!) :: (Match match result) => match -> String -> Pattern 686 685 parser ?! decision = peek parser & commit decision 686 687 -- | @lookbehind <?@ matches the current point without consuming any 688 -- characters, if the previous character matches the lookbehind parser (single 689 -- character negative lookbehind) 690 (<?) :: (Match match result) => match -> Parser result 691 (<?) lookbehind = prev lookbehind 692 693 -- | @lookahead >?@ matches the current point without consuming any characters 694 -- if it matches the lookahead parser (positive lookahead) 695 (>?) :: (Match match result) => match -> Parser result 696 (>?) lookahead = peek lookahead 687 697 688 698 -- | @parser - rejected@ matches /parser/, except if /rejected/ matches at this … … 758 768 rState = (reply|>rState) { sDecision = parentDecision } } 759 769 in reply' 770 771 -- | @prev parser@ succeeds if /parser/ matches at the previous character. It 772 -- does not consume any input. 773 prev :: (Match match result) => match -> Parser result 774 prev parser = Parser $ \ state -> 775 prevParser state (match parser) state { sIsPeek = True, sChars = state|>sLast : state|>sChars } 776 where prevParser point (Parser parser) state = 777 let reply = parser state 778 in case reply|>rResult of 779 Failed message -> failReply point message 780 Result value -> returnReply point value 781 More parser' -> prevParser point parser' $ reply|>rState 760 782 761 783 -- | @peek parser@ succeeds if /parser/ matches at this point, but does not … … 971 993 972 994 -- | Production context. 973 data Context = BlockOut -- ^ Outside block mapping.974 | BlockIn -- ^ Inside block mapping.995 data Context = BlockOut -- ^ Outside block sequence.. 996 | BlockIn -- ^ Inside block sequence.. 975 997 | FlowOut -- ^ Outside flow collection. 976 998 | FlowIn -- ^ Inside flow collection. … … 998 1020 "flow_key" -> FlowKey 999 1021 _ -> error $ "unknown context: " ++ word 1000 1001 -- | Scalar style.1002 data Style = Plain -- ^ Plain scalar.1003 | Double -- ^ Double quoted.1004 | Single -- ^ Single quoted.1005 | Literal -- ^ Literal block.1006 | Folded -- ^ Folded block.1007 1008 -- | @show style@ converts a 'Style' to a 'String'.1009 instance Show Style where1010 show style = case style of1011 Plain -> "plain"1012 Double -> "double"1013 Single -> "single"1014 Literal -> "literal"1015 Folded -> "folded"1016 1017 -- | @read style@ converts a 'String' to a 'Style'.1018 instance Read Style where1019 readsPrec _ text = [ ((r word), tail) | (word, tail) <- lex text ]1020 where r word = case word of1021 "plain" -> Plain1022 "double" -> Double1023 "single" -> Single1024 "literal" -> Literal1025 "folded" -> Folded1026 _ -> error $ "unknown style: " ++ word1027 1022 1028 1023 -- | Chomp method. … … 1141 1136 $ PAT(b_char) 1142 1137 $ PAT(b_generic) 1143 $ PAT(b_ignored_any)1144 $ PAT(b_ignored_generic)1145 1138 $ PAT(b_l_folded_as_space) 1146 1139 $ PAT(b_line_feed) 1147 1140 $ PAT(b_line_separator) 1148 1141 $ PAT(b_next_line) 1142 $ PAT(b_non_content_any) 1143 $ PAT(b_non_content_generic) 1149 1144 $ PAT(b_normalized) 1150 1145 $ PAT(b_paragraph_separator) … … 1160 1155 $ PAT(c_double_quote) 1161 1156 $ PAT(c_escape) 1162 $ PAT(c_flow_indicator)1163 1157 $ PAT(c_folded) 1164 1158 $ PAT(c_indicator) … … 1171 1165 $ PAT(c_nb_comment_text) 1172 1166 $ PAT(c_non_specific_tag) 1173 $ PAT(c_ns_alias )1167 $ PAT(c_ns_alias_node) 1174 1168 $ PAT(c_ns_anchor_property) 1169 $ PAT(c_ns_esc_char) 1175 1170 $ PAT(c_ns_local_tag_prefix) 1176 $ PAT(c_ns_property)1177 1171 $ PAT(c_ns_shorthand_tag) 1178 1172 $ PAT(c_ns_tag_property) … … 1191 1185 $ PAT(c_verbatim_tag) 1192 1186 $ PAT(e_node) 1193 $ PAT(e_no_document)1194 1187 $ PAT(e_scalar) 1195 1188 $ PAT(l_comment) … … 1206 1199 $ PAT(nb_char) 1207 1200 $ PAT(nb_double_char) 1201 $ PAT(nb_double_one_line) 1202 $ PAT(nb_ns_double_in_line) 1203 $ PAT(nb_ns_single_in_line) 1208 1204 $ PAT(nb_single_char) 1205 $ PAT(nb_single_one_line) 1209 1206 $ PAT(ns_anchor_char) 1210 1207 $ PAT(ns_anchor_name) … … 1222 1219 $ PAT(ns_esc_bell) 1223 1220 $ PAT(ns_esc_carriage_return) 1224 $ PAT(ns_esc_char)1225 1221 $ PAT(ns_esc_double_quote) 1226 1222 $ PAT(ns_esc_escape) … … 1251 1247 $ PAT(ns_yaml_version) 1252 1248 $ PAT(s_b_comment) 1253 $ PAT(s_b_double_escaped)1254 1249 $ PAT(s_l_comments) 1255 $ PAT(s_ns_double_chars)1256 $ PAT(s_ns_single_chars)1257 1250 $ PAT(s_separate_in_line) 1258 1251 $ PAT(s_space) … … 1272 1265 -- tokenizer (that takes an /n/ argument). 1273 1266 tokenizersWithN :: Map.Map String (Int -> Tokenizer) 1274 tokenizersWithN = PAR(c_indentation_indicator) "m" 1275 $ PAR(count_spaces) "m" 1267 tokenizersWithN = PAR(c_b_block_header) "(m,t)" 1276 1268 $ PAC(detect_collection_indentation) "m" 1277 1269 $ PAC(detect_scalar_indentation) "m" 1278 $ PAT(b_l_literal_next) 1270 $ PAR(c_indentation_indicator) "m" 1271 $ PAR(count_spaces) "m" 1279 1272 $ PAT(b_l_spaced) 1273 $ PAT(b_nb_literal_next) 1280 1274 $ PAT(c_l_block_map_explicit_entry) 1281 1275 $ PAT(c_l_block_map_explicit_key) … … 1288 1282 $ PAT(l__block_sequence) 1289 1283 $ PAT(l_keep_empty) 1284 $ PAT(l_nb_diff_lines) 1290 1285 $ PAT(l_nb_folded_lines) 1291 $ PAT(l_nb_literal_chars) 1286 $ PAT(l_nb_literal_text) 1287 $ PAT(l_nb_same_lines) 1292 1288 $ PAT(l_nb_spaced_lines) 1293 $ PAT(l_nb_start_with_any)1294 $ PAT(l_nb_start_with_folded)1295 $ PAT(l_nb_start_with_spaced)1296 1289 $ PAT(l_strip_empty) 1297 1290 $ PAT(l_trail_comments) 1291 $ PAT(nb_double_multi_line) 1292 $ PAT(nb_single_multi_line) 1298 1293 $ PAT(ns_l_block_map_entry) 1299 1294 $ PAT(ns_l_block_map_implicit_entry) 1300 1295 $ PAT(ns_l_in_line_mapping) 1301 1296 $ PAT(ns_l_in_line_sequence) 1302 $ PAT(s_double_multi) 1303 $ PAT(s_ignored_prefix_block) 1304 $ PAT(s_ignored_prefix_flow) 1297 $ PAT(s_block_line_prefix) 1298 $ PAT(s_flow_line_prefix) 1305 1299 $ PAT(s_indent) 1306 1300 $ PAT(s_indent_le) 1307 1301 $ PAT(s_indent_lt) 1308 1302 $ PAT(s_l_double_any) 1303 $ PAT(s_l_double_escaped) 1309 1304 $ PAT(s_l_flow_folded) 1310 1305 $ PAT(s_l__flow_in_block) 1311 1306 $ PAT(s_nb_folded_text) 1312 1307 $ PAT(s_nb_spaced_text) 1313 $ PAT(s_ns_double_next )1314 $ PAT(s_ns_single_next )1308 $ PAT(s_ns_double_next_line) 1309 $ PAT(s_ns_single_next_line) 1315 1310 $ PAT(s_separate_lines) 1316 $ PAT(s_single_multi)1317 1311 $ Map.empty 1318 1312 where pat name pattern = Map.insert (pName name) (\ n -> patternTokenizer (match $ pattern n)) … … 1332 1326 -- tokenizer (that takes a /c/ argument). 1333 1327 tokenizersWithC :: Map.Map String (Context -> Tokenizer) 1334 tokenizersWithC = PAT(nb_plain_char) 1328 tokenizersWithC = PAT(nb_ns_plain_in_line) 1329 $ PAT(nb_plain_char) 1335 1330 $ PAT(ns_plain_char) 1336 1331 $ PAT(ns_plain_first) 1332 $ PAT(ns_plain_one_line) 1337 1333 $ PAT(ns_plain_safe) 1338 $ PAT(ns_plain_single)1339 $ PAT(s_ns_plain_chars)1340 1334 $ Map.empty 1341 1335 where pat name pattern = Map.insert (pName name) (\ c -> patternTokenizer (match $ pattern c)) … … 1350 1344 Nothing -> Nothing 1351 1345 1352 -- | @tokenizersWithS@ returns a mapping from a production name to a production1353 -- tokenizer (that takes a /s/ argument).1354 tokenizersWithS :: Map.Map String (Style -> Tokenizer)1355 tokenizersWithS = PAT(c_style_indicator)1356 $ Map.empty1357 where pat name pattern = Map.insert (pName name) (\ s -> patternTokenizer (match $ pattern s))1358 1359 -- | @tokenizerWithS name s@ converts the production (that requires an /s/1360 -- argument) with the specified /name/ to a simple 'Tokenizer', or @Nothing@ if1361 -- it isn't known.1362 tokenizerWithS :: String -> Style -> Maybe Tokenizer1363 tokenizerWithS name s =1364 case Map.lookup name tokenizersWithS of1365 Just tokenizer -> Just $ tokenizer s1366 Nothing -> Nothing1367 1368 1346 -- | @tokenizersWithT@ returns a mapping from a production name to a production 1369 1347 -- tokenizer (that takes a /t/ argument). … … 1385 1363 -- production tokenizer (that requires /n/ and /c/ arguments). 1386 1364 tokenizersWithNC :: Map.Map String (Int -> Context -> Tokenizer) 1387 tokenizersWithNC = PAT(c_double_quoted) 1365 tokenizersWithNC = PAT(b_l_folded_any) 1366 $ PAT(b_l_folded_specific) 1367 $ PAT(b_l_folded_trimmed) 1368 $ PAT(c_double_quoted) 1388 1369 $ PAT(c_flow_json_content) 1389 1370 $ PAT(c_flow_json_node) … … 1391 1372 $ PAT(c_flow_sequence) 1392 1373 $ PAT(c_ns_flow_map_adjacent_value) 1374 $ PAT(c_ns_flow_map_empty_key_entry) 1393 1375 $ PAT(c_ns_flow_map_json_key_entry) 1394 1376 $ PAT(c_ns_flow_map_separate_value) … … 1396 1378 $ PAT(c_ns_properties) 1397 1379 $ PAT(c_single_quoted) 1380 $ PAT(l_empty) 1398 1381 $ PAT(nb_double_text) 1399 1382 $ PAT(nb_single_text) 1400 1383 $ PAT(ns_flow_content) 1401 $ PAT(ns_flow_map_empty_key_entry)1402 1384 $ PAT(ns_flow_map_entry) 1403 1385 $ PAT(ns_flow_map_explicit_entry) … … 1412 1394 $ PAT(ns_flow_yaml_node) 1413 1395 $ PAT(ns_plain) 1414 $ PAT(ns_plain_multi )1396 $ PAT(ns_plain_multi_line) 1415 1397 $ PAT(ns_s_flow_map_entries) 1416 1398 $ PAT(ns_s_flow_seq_entries) … … 1420 1402 $ PAT(s_l__block_node) 1421 1403 $ PAT(s_l__block_scalar) 1422 $ PAT(s_ns_plain_next) 1404 $ PAT(s_line_prefix) 1405 $ PAT(s_ns_plain_next_line) 1423 1406 $ PAT(s_separate) 1424 1407 $ Map.empty … … 1434 1417 Nothing -> Nothing 1435 1418 1436 -- | @tokenizersWithNS@ returns a mapping from a production name to a production1437 -- tokenizer (that requires /n/ and /s/ arguments).1438 tokenizersWithNS :: Map.Map String (Int -> Style -> Tokenizer)1439 tokenizersWithNS = PAR(c_b__block_header) "(m,t)"1440 $ PAT(b_l_folded_any)1441 $ PAT(b_l_folded_specific)1442 $ PAT(b_l_folded_trimmed)1443 $ PAT(l_empty)1444 $ PAT(s_ignored_prefix)1445 $ Map.empty1446 where pat name pattern = Map.insert (pName name) (\ n s -> patternTokenizer (match $ pattern n s))1447 par name parser what = Map.insert (pName name) (\ n s -> parserTokenizer what (match $ parser n s))1448 1449 -- | @tokenizerWithNS name n s@ converts the production (that requires /n/ and1450 -- /s/ arguments) with the specified /name/ to a simple 'Tokenizer', or1451 -- @Nothing@ if it isn't known.1452 tokenizerWithNS :: String -> Int -> Style -> Maybe Tokenizer1453 tokenizerWithNS name n s =1454 case Map.lookup name tokenizersWithNS of1455 Just tokenizer -> Just $ tokenizer n s1456 Nothing -> Nothing1457 1458 1419 -- | @tokenizersWithNT@ returns a mapping from a production name to a 1459 1420 -- production tokenizer (that requires /n/ and /t/ arguments). … … 1479 1440 ++ (Map.keys tokenizersWithN) 1480 1441 ++ (Map.keys tokenizersWithC) 1481 ++ (Map.keys tokenizersWithS)1482 1442 ++ (Map.keys tokenizersWithT) 1483 1443 ++ (Map.keys tokenizersWithNC) 1484 ++ (Map.keys tokenizersWithNS)1485 1444 ++ (Map.keys tokenizersWithNT) 1486 1445
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)