Show
Ignore:
Timestamp:
04/06/08 04:24:28 (9 months ago)
Author:
oren
Message:

Version 0.9 - compatible with the April 06, 2008 draft.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/YamlReference/Text/Yaml/Reference.hs

    r5 r6  
    2828    -- For testing: 
    2929    Context, 
    30     Style, 
    3130    Chomp, 
    3231    tokenizer, 
    3332    tokenizerWithN, 
    3433    tokenizerWithC, 
    35     tokenizerWithS, 
    3634    tokenizerWithT, 
    3735    tokenizerWithNC, 
    38     tokenizerWithNS, 
    3936    tokenizerWithNT, 
    4037    tokenizerNames, 
     
    651648infix  3 ! 
    652649infix  3 ?! 
     650infix  3 <? 
     651infix  3 >? 
    653652infixl 3 - 
    654653infixr 2 & 
     
    676675decision ^ parser = choice decision (match parser) 
    677676 
    678 -- | @parser ! decision@ commits to /decision/ after successfully matching the 
    679 -- /parser/. 
     677-- | @parser ! decision@ commits to /decision/ (in an option) after 
     678-- successfully matching the /parser/. 
    680679(!) :: (Match match result) => match -> String -> Pattern 
    681680parser ! decision = parser & commit decision 
    682681 
    683 -- | @parser ?! decision@ commits to /decision/ if the current position matches 
    684 -- /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. 
    685684(?!) :: (Match match result) => match -> String -> Pattern 
    686685parser ?! 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 
    687697 
    688698-- | @parser - rejected@ matches /parser/, except if /rejected/ matches at this 
     
    758768                                                     rState = (reply|>rState) { sDecision = parentDecision } } 
    759769          in reply' 
     770 
     771-- | @prev parser@ succeeds if /parser/ matches at the previous character. It 
     772-- does not consume any input. 
     773prev :: (Match match result) => match -> Parser result 
     774prev 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 
    760782 
    761783-- | @peek parser@ succeeds if /parser/ matches at this point, but does not 
     
    971993 
    972994-- | Production context. 
    973 data Context = BlockOut     -- ^ Outside block mapping. 
    974              | BlockIn      -- ^ Inside block mapping. 
     995data Context = BlockOut     -- ^ Outside block sequence.. 
     996             | BlockIn      -- ^ Inside block sequence.. 
    975997             | FlowOut      -- ^ Outside flow collection. 
    976998             | FlowIn       -- ^ Inside flow collection. 
     
    9981020                        "flow_key"  -> FlowKey 
    9991021                        _           -> 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 where 
    1010   show style = case style of 
    1011                     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 where 
    1019   readsPrec _ text = [ ((r word), tail) | (word, tail) <- lex text ] 
    1020     where r word = case word of 
    1021                         "plain"   -> Plain 
    1022                         "double"  -> Double 
    1023                         "single"  -> Single 
    1024                         "literal" -> Literal 
    1025                         "folded"  -> Folded 
    1026                         _         -> error $ "unknown style: " ++ word 
    10271022 
    10281023-- | Chomp method. 
     
    11411136           $ PAT(b_char) 
    11421137           $ PAT(b_generic) 
    1143            $ PAT(b_ignored_any) 
    1144            $ PAT(b_ignored_generic) 
    11451138           $ PAT(b_l_folded_as_space) 
    11461139           $ PAT(b_line_feed) 
    11471140           $ PAT(b_line_separator) 
    11481141           $ PAT(b_next_line) 
     1142           $ PAT(b_non_content_any) 
     1143           $ PAT(b_non_content_generic) 
    11491144           $ PAT(b_normalized) 
    11501145           $ PAT(b_paragraph_separator) 
     
    11601155           $ PAT(c_double_quote) 
    11611156           $ PAT(c_escape) 
    1162            $ PAT(c_flow_indicator) 
    11631157           $ PAT(c_folded) 
    11641158           $ PAT(c_indicator) 
     
    11711165           $ PAT(c_nb_comment_text) 
    11721166           $ PAT(c_non_specific_tag) 
    1173            $ PAT(c_ns_alias) 
     1167           $ PAT(c_ns_alias_node) 
    11741168           $ PAT(c_ns_anchor_property) 
     1169           $ PAT(c_ns_esc_char) 
    11751170           $ PAT(c_ns_local_tag_prefix) 
    1176            $ PAT(c_ns_property) 
    11771171           $ PAT(c_ns_shorthand_tag) 
    11781172           $ PAT(c_ns_tag_property) 
     
    11911185           $ PAT(c_verbatim_tag) 
    11921186           $ PAT(e_node) 
    1193            $ PAT(e_no_document) 
    11941187           $ PAT(e_scalar) 
    11951188           $ PAT(l_comment) 
     
    12061199           $ PAT(nb_char) 
    12071200           $ PAT(nb_double_char) 
     1201           $ PAT(nb_double_one_line) 
     1202           $ PAT(nb_ns_double_in_line) 
     1203           $ PAT(nb_ns_single_in_line) 
    12081204           $ PAT(nb_single_char) 
     1205           $ PAT(nb_single_one_line) 
    12091206           $ PAT(ns_anchor_char) 
    12101207           $ PAT(ns_anchor_name) 
     
    12221219           $ PAT(ns_esc_bell) 
    12231220           $ PAT(ns_esc_carriage_return) 
    1224            $ PAT(ns_esc_char) 
    12251221           $ PAT(ns_esc_double_quote) 
    12261222           $ PAT(ns_esc_escape) 
     
    12511247           $ PAT(ns_yaml_version) 
    12521248           $ PAT(s_b_comment) 
    1253            $ PAT(s_b_double_escaped) 
    12541249           $ PAT(s_l_comments) 
    1255            $ PAT(s_ns_double_chars) 
    1256            $ PAT(s_ns_single_chars) 
    12571250           $ PAT(s_separate_in_line) 
    12581251           $ PAT(s_space) 
     
    12721265-- tokenizer (that takes an /n/ argument). 
    12731266tokenizersWithN :: Map.Map String (Int -> Tokenizer) 
    1274 tokenizersWithN = PAR(c_indentation_indicator) "m" 
    1275                 $ PAR(count_spaces) "m" 
     1267tokenizersWithN = PAR(c_b_block_header) "(m,t)" 
    12761268                $ PAC(detect_collection_indentation) "m" 
    12771269                $ PAC(detect_scalar_indentation) "m" 
    1278                 $ PAT(b_l_literal_next) 
     1270                $ PAR(c_indentation_indicator) "m" 
     1271                $ PAR(count_spaces) "m" 
    12791272                $ PAT(b_l_spaced) 
     1273                $ PAT(b_nb_literal_next) 
    12801274                $ PAT(c_l_block_map_explicit_entry) 
    12811275                $ PAT(c_l_block_map_explicit_key) 
     
    12881282                $ PAT(l__block_sequence) 
    12891283                $ PAT(l_keep_empty) 
     1284                $ PAT(l_nb_diff_lines) 
    12901285                $ PAT(l_nb_folded_lines) 
    1291                 $ PAT(l_nb_literal_chars) 
     1286                $ PAT(l_nb_literal_text) 
     1287                $ PAT(l_nb_same_lines) 
    12921288                $ 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) 
    12961289                $ PAT(l_strip_empty) 
    12971290                $ PAT(l_trail_comments) 
     1291                $ PAT(nb_double_multi_line) 
     1292                $ PAT(nb_single_multi_line) 
    12981293                $ PAT(ns_l_block_map_entry) 
    12991294                $ PAT(ns_l_block_map_implicit_entry) 
    13001295                $ PAT(ns_l_in_line_mapping) 
    13011296                $ 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) 
    13051299                $ PAT(s_indent) 
    13061300                $ PAT(s_indent_le) 
    13071301                $ PAT(s_indent_lt) 
    13081302                $ PAT(s_l_double_any) 
     1303                $ PAT(s_l_double_escaped) 
    13091304                $ PAT(s_l_flow_folded) 
    13101305                $ PAT(s_l__flow_in_block) 
    13111306                $ PAT(s_nb_folded_text) 
    13121307                $ 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) 
    13151310                $ PAT(s_separate_lines) 
    1316                 $ PAT(s_single_multi) 
    13171311                $ Map.empty 
    13181312  where pat name pattern     = Map.insert (pName name) (\ n -> patternTokenizer     (match   $ pattern n)) 
     
    13321326-- tokenizer (that takes a /c/ argument). 
    13331327tokenizersWithC :: Map.Map String (Context -> Tokenizer) 
    1334 tokenizersWithC = PAT(nb_plain_char) 
     1328tokenizersWithC = PAT(nb_ns_plain_in_line) 
     1329                $ PAT(nb_plain_char) 
    13351330                $ PAT(ns_plain_char) 
    13361331                $ PAT(ns_plain_first) 
     1332                $ PAT(ns_plain_one_line) 
    13371333                $ PAT(ns_plain_safe) 
    1338                 $ PAT(ns_plain_single) 
    1339                 $ PAT(s_ns_plain_chars) 
    13401334                $ Map.empty 
    13411335  where pat name pattern = Map.insert (pName name) (\ c -> patternTokenizer (match $ pattern c)) 
     
    13501344    Nothing        -> Nothing 
    13511345 
    1352 -- | @tokenizersWithS@ returns a mapping from a production name to a production 
    1353 -- tokenizer (that takes a /s/ argument). 
    1354 tokenizersWithS :: Map.Map String (Style -> Tokenizer) 
    1355 tokenizersWithS = PAT(c_style_indicator) 
    1356                 $ Map.empty 
    1357   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@ if 
    1361 -- it isn't known. 
    1362 tokenizerWithS :: String -> Style -> Maybe Tokenizer 
    1363 tokenizerWithS name s = 
    1364   case Map.lookup name tokenizersWithS of 
    1365     Just tokenizer -> Just $ tokenizer s 
    1366     Nothing        -> Nothing 
    1367  
    13681346-- | @tokenizersWithT@ returns a mapping from a production name to a production 
    13691347-- tokenizer (that takes a /t/ argument). 
     
    13851363-- production tokenizer (that requires /n/ and /c/ arguments). 
    13861364tokenizersWithNC :: Map.Map String (Int -> Context -> Tokenizer) 
    1387 tokenizersWithNC = PAT(c_double_quoted) 
     1365tokenizersWithNC = PAT(b_l_folded_any) 
     1366                 $ PAT(b_l_folded_specific) 
     1367                 $ PAT(b_l_folded_trimmed) 
     1368                 $ PAT(c_double_quoted) 
    13881369                 $ PAT(c_flow_json_content) 
    13891370                 $ PAT(c_flow_json_node) 
     
    13911372                 $ PAT(c_flow_sequence) 
    13921373                 $ PAT(c_ns_flow_map_adjacent_value) 
     1374                 $ PAT(c_ns_flow_map_empty_key_entry) 
    13931375                 $ PAT(c_ns_flow_map_json_key_entry) 
    13941376                 $ PAT(c_ns_flow_map_separate_value) 
     
    13961378                 $ PAT(c_ns_properties) 
    13971379                 $ PAT(c_single_quoted) 
     1380                 $ PAT(l_empty) 
    13981381                 $ PAT(nb_double_text) 
    13991382                 $ PAT(nb_single_text) 
    14001383                 $ PAT(ns_flow_content) 
    1401                  $ PAT(ns_flow_map_empty_key_entry) 
    14021384                 $ PAT(ns_flow_map_entry) 
    14031385                 $ PAT(ns_flow_map_explicit_entry) 
     
    14121394                 $ PAT(ns_flow_yaml_node) 
    14131395                 $ PAT(ns_plain) 
    1414                  $ PAT(ns_plain_multi) 
     1396                 $ PAT(ns_plain_multi_line) 
    14151397                 $ PAT(ns_s_flow_map_entries) 
    14161398                 $ PAT(ns_s_flow_seq_entries) 
     
    14201402                 $ PAT(s_l__block_node) 
    14211403                 $ PAT(s_l__block_scalar) 
    1422                  $ PAT(s_ns_plain_next) 
     1404                 $ PAT(s_line_prefix) 
     1405                 $ PAT(s_ns_plain_next_line) 
    14231406                 $ PAT(s_separate) 
    14241407                 $ Map.empty 
     
    14341417    Nothing        -> Nothing 
    14351418 
    1436 -- | @tokenizersWithNS@ returns a mapping from a production name to a production 
    1437 -- 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.empty 
    1446   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/ and 
    1450 -- /s/ arguments) with the specified /name/ to a simple 'Tokenizer', or 
    1451 -- @Nothing@ if it isn't known. 
    1452 tokenizerWithNS :: String -> Int -> Style -> Maybe Tokenizer 
    1453 tokenizerWithNS name n s = 
    1454   case Map.lookup name tokenizersWithNS of 
    1455     Just tokenizer -> Just $ tokenizer n s 
    1456     Nothing        -> Nothing 
    1457  
    14581419-- | @tokenizersWithNT@ returns a mapping from a production name to a 
    14591420-- production tokenizer (that requires /n/ and /t/ arguments). 
     
    14791440              ++ (Map.keys tokenizersWithN) 
    14801441              ++ (Map.keys tokenizersWithC) 
    1481               ++ (Map.keys tokenizersWithS) 
    14821442              ++ (Map.keys tokenizersWithT) 
    14831443              ++ (Map.keys tokenizersWithNC) 
    1484               ++ (Map.keys tokenizersWithNS) 
    14851444              ++ (Map.keys tokenizersWithNT) 
    14861445