Commit 196a6213 authored by John van Groningen's avatar John van Groningen

add parsing of maybe just none (?,?#,?^,?Just,?#Just,?^Just,?|Just,?None,?#None,?^None,?|None)

parent f5bff41a
......@@ -3617,8 +3617,12 @@ where
<=< adjust_predef_symbols PD_ListClass PD_UTSListClass mod_index STE_Class
| mod_index==cs_predef_symbols.[PD_StdStrictMaybes].pds_def
= cs
<=< adjust_predef_symbols PD_just PD_from_just_u mod_index STE_Member
<=< adjust_predef_symbols PD_nothing PD_nothing_u mod_index STE_DclFunction
<=< adjustPredefSymbol PD_just_u mod_index STE_Member
<=< adjustPredefSymbol PD_just mod_index STE_Member
<=< adjustPredefSymbol PD_from_just_u mod_index STE_Member
<=< adjustPredefSymbol PD_from_just mod_index STE_Member
<=< adjustPredefSymbol PD_nothing_u mod_index STE_DclFunction
<=< adjustPredefSymbol PD_nothing mod_index STE_DclFunction
<=< adjust_predef_symbols PD_MaybeClass PD_UMaybeClass mod_index STE_Class
| mod_index==cs_predef_symbols.[PD_StdDynamic].pds_def
= cs
......
......@@ -3231,6 +3231,10 @@ trySimpleTypeT CurlyOpenToken attr pState
trySimpleTypeT StringTypeToken attr pState
# type = makeStringType
= (ParseOk, {at_attribute = attr, at_type = type}, pState)
trySimpleTypeT (MaybeIdentToken maybe_token) attr pState
| maybe_token>=8
#! maybe_type_ident = predefined_idents.[PD_MaybeType+(maybe_token bitand 7)]
= (ParseOk,{at_attribute=attr,at_type=TA (MakeNewTypeSymbIdent maybe_type_ident 0) []},pState)
trySimpleTypeT (QualifiedIdentToken module_name ident_name) attr pState
| not (isLowerCaseName ident_name)
# (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Type pState
......@@ -3629,6 +3633,12 @@ where
(pattern_args,pState) = parse_wild_cards pState
pattern = if (isEmpty pattern_args) (PE_Ident id) (PE_List [PE_Ident id:pattern_args])
-> matches_expression exp pattern pState
MaybeIdentToken maybe_token
| maybe_token<8
#! just_or_none_ident = predefined_idents.[PD_JustSymbol+maybe_token]
# (pattern_args,pState) = parse_wild_cards pState
pattern = if (pattern_args=:[]) (PE_Ident just_or_none_ident) (PE_List [PE_Ident just_or_none_ident:pattern_args])
-> matches_expression exp pattern pState
// to do: qualified ident
_
# (succ, pattern, pState) = trySimplePatternWithoutDefinitionsT token pState
......@@ -3774,6 +3784,10 @@ trySimplePatternT (CharToken char) pState
= (True, PE_Basic (BVC char), pState)
trySimplePatternT (RealToken real) pState
= (True, PE_Basic (BVR real), pState)
trySimplePatternT (MaybeIdentToken maybe_token) pState
| maybe_token<8
#! just_or_none_ident = predefined_idents.[PD_JustSymbol+maybe_token]
= (True,PE_Ident just_or_none_ident,pState)
trySimplePatternT (QualifiedIdentToken module_name ident_name) pState
| not (isLowerCaseName ident_name)
# (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Expression pState
......@@ -3898,6 +3912,13 @@ trySimpleExpressionT (CharToken char) pState
= (True, PE_Basic (BVC char), pState)
trySimpleExpressionT (RealToken real) pState
= (True, PE_Basic (BVR real), pState)
trySimpleExpressionT (MaybeIdentToken maybe_token) pState
| maybe_token<8
| maybe_token<4
#! just_or_none_ident = predefined_idents.[PD_JustSymbol+maybe_token]
= (True,PE_Ident just_or_none_ident,pState)
#! just_or_none_ident = predefined_idents.[PD_just_u+(maybe_token bitand 3)]
= (True,PE_Ident just_or_none_ident,pState)
trySimpleExpressionT (QualifiedIdentToken module_name ident_name) pState
# (module_id, pState) = stringToQualifiedModuleIdent module_name ident_name IC_Expression pState
= (True, PE_QualifiedIdent module_id ident_name, pState)
......
......@@ -47,6 +47,7 @@ PD_StrictArrayType :== 41
PD_UnboxedArrayType :== 42
PD_PackedArrayType :== 43
// same order as in MaybeIdentToken
PD_MaybeType :== 44
PD_StrictMaybeType :== 45
PD_UnboxedMaybeType :== 46
......@@ -77,13 +78,14 @@ PD_OverloadedNilSymbol :== 62
PD_Arity2TupleSymbol :== 63
PD_Arity32TupleSymbol :== 93
// same order as in MaybeIdentToken
PD_JustSymbol :== 94
PD_StrictJustSymbol :== 95
PD_UnboxedJustSymbol :== 96
PD_OverloadedJustSymbol :== 97
PD_NothingSymbol :== 98
PD_StrictNothingSymbol :== 99
PD_UnboxedNothingSymbol :== 100
PD_NothingSymbol :== 95
PD_StrictJustSymbol :== 96
PD_StrictNothingSymbol :== 97
PD_UnboxedJustSymbol :== 98
PD_UnboxedNothingSymbol :== 99
PD_OverloadedJustSymbol :== 100
PD_OverloadedNothingSymbol :== 101
PD_UnitConsSymbol :== 102
......@@ -158,13 +160,14 @@ PD_UTSListClass :== 174
// StdStrictMaybes
PD_StdStrictMaybes:==175
PD_just:==176
PD_from_just:==177
PD_just_u:==178
PD_from_just_u:==179
// same order as in MaybeIdentToken
PD_just_u:==176
PD_nothing_u:==177
PD_just:==178
PD_nothing:==179
PD_nothing:==180
PD_nothing_u:==181
PD_from_just_u:==180
PD_from_just:==181
PD_MaybeClass :== 182
PD_UMaybeClass :== 183
......
......@@ -384,7 +384,7 @@ where
<<- (local_predefined_idents, IC_Class, PD_ListClass)
<<- (local_predefined_idents, IC_Class, PD_UListClass)
<<- (local_predefined_idents, IC_Class, PD_UTSListClass)
# hash_table = put_predefined_idents_in_hash_table PD_just PD_nothing_u IC_Expression local_predefined_idents hash_table
# hash_table = put_predefined_idents_in_hash_table PD_just_u PD_from_just IC_Expression local_predefined_idents hash_table
<<- (local_predefined_idents, IC_Class, PD_MaybeClass)
<<- (local_predefined_idents, IC_Class, PD_UMaybeClass)
<<- (local_predefined_idents, IC_Expression, PD_SmallerFun)
......@@ -529,8 +529,8 @@ buildPredefinedModule support_dynamics pre_def_symbols
array_and_unit_type_defs
= [array_def,strict_def,unboxed_def,packed_def,maybe_def,strict_maybe_def,unboxed_maybe_def,overloaded_maybe_def,unit_type_def]
cons_defs = [just_def,strict_just_def,unboxed_just_def,overloaded_just_def,
nothing_def,strict_nothing_def,unboxed_nothing_def,overloaded_nothing_def,unit_cons_def]
cons_defs = [just_def,nothing_def,strict_just_def,strict_nothing_def,
unboxed_just_def,unboxed_nothing_def,overloaded_just_def,overloaded_nothing_def,unit_cons_def]
(type_defs, cons_defs, pre_def_symbols)
= add_tuple_defs pre_mod_ident MaxTupleArity array_and_unit_type_defs cons_defs pre_def_symbols
......
......@@ -20,6 +20,7 @@ instance <<< FilePosition
= IdentToken !.String // an identifier
| UnderscoreIdentToken !.String// an identifier that starts with a '_'
| QualifiedIdentToken !String !.String // a qualified identifier
| MaybeIdentToken !Int
| IntToken !.String // an integer
| RealToken !.String // a real
| StringToken !.String // a string
......@@ -111,6 +112,18 @@ instance <<< FilePosition
| ExistsToken // E.
| ForAllToken // A.
LazyJustToken :== 0
LazyNoneToken :== 1
StrictJustToken :== 2
StrictNoneToken :== 3
UnboxedJustToken :== 4
UnboxedNoneToken :== 5
OverloadedJustToken :== 6
OverloadedNoneToken :== 7
LazyMaybeToken :== 8
StrictMaybeToken :== 9
UnboxedMaybeToken :== 10
:: ScanContext
= GeneralContext
| TypeContext
......
......@@ -109,6 +109,7 @@ ScanOptionNoNewOffsideForSeqLetBit:==4;
= IdentToken ! .String // an identifier
| UnderscoreIdentToken !.String// an identifier that starts with a '_'
| QualifiedIdentToken !String !.String // a qualified identifier
| MaybeIdentToken !Int
| IntToken !.String // an integer
| RealToken !.String // a real
| StringToken !.String // a string
......@@ -200,6 +201,18 @@ ScanOptionNoNewOffsideForSeqLetBit:==4;
| ExistsToken // E.
| ForAllToken // A.
LazyJustToken :== 0
LazyNoneToken :== 1
StrictJustToken :== 2
StrictNoneToken :== 3
UnboxedJustToken :== 4
UnboxedNoneToken :== 5
OverloadedJustToken :== 6
OverloadedNoneToken :== 7
LazyMaybeToken :== 8
StrictMaybeToken :== 9
UnboxedMaybeToken :== 10
:: ScanContext
= GeneralContext
| TypeContext
......@@ -732,7 +745,8 @@ Scan c0=:':' input co
= (ColonToken, charBack input)
Scan '\'' input co = ScanChar input
Scan c0=:'\"' input co = ScanString 0 [c0] input
Scan '?' input co
= ScanQuestionMark input co
Scan 'E' input TypeContext
# (eof,c1,input) = ReadNormalChar input
| eof = (IdentToken "E", input)
......@@ -750,6 +764,84 @@ Scan c input co
| isSpecialChar c = ScanOperator 0 input [c] co
= (ErrorToken ScanErrIllegal, input)
ScanQuestionMark :: !Input !ScanContext -> (!Token, !Input)
ScanQuestionMark input=:{inp_stream=OldLine i line stream,inp_pos,inp_filename,inp_tabsize} co=:FunctionContext
| i+3>size line
= ScanOperator 0 input ['?'] co
| line.[i]=='J' && line.[i+1]=='u' && line.[i+2]=='s' && line.[i+3]=='t'
&& (i+4==size line || not (IsIdentChar line.[i+4] FunctionContext))
# inp_pos & fp_col = inp_pos.fp_col + 4
input = {inp_stream = OldLine (i+4) line stream, inp_pos = inp_pos,
inp_filename = inp_filename, inp_tabsize = inp_tabsize}
= (MaybeIdentToken StrictJustToken, input)
| line.[i]=='N' && line.[i+1]=='o' && line.[i+2]=='n' && line.[i+3]=='e'
&& (i+4==size line || not (IsIdentChar line.[i+4] FunctionContext))
# inp_pos & fp_col = inp_pos.fp_col + 4
input = {inp_stream = OldLine (i+4) line stream, inp_pos = inp_pos,
inp_filename = inp_filename, inp_tabsize = inp_tabsize}
= (MaybeIdentToken StrictNoneToken, input)
| i+4>size line
= ScanOperator 0 input ['?'] co
| line.[i]=='#'
| line.[i+1]=='J' && line.[i+2]=='u' && line.[i+3]=='s' && line.[i+4]=='t'
&& (i+5==size line || not (IsIdentChar line.[i+5] FunctionContext))
# inp_pos & fp_col = inp_pos.fp_col + 5
input = {inp_stream = OldLine (i+5) line stream, inp_pos = inp_pos,
inp_filename = inp_filename, inp_tabsize = inp_tabsize}
= (MaybeIdentToken UnboxedJustToken, input)
| line.[i+1]=='N' && line.[i+2]=='o' && line.[i+3]=='n' && line.[i+4]=='e'
&& (i+5==size line || not (IsIdentChar line.[i+5] FunctionContext))
# inp_pos & fp_col = inp_pos.fp_col + 5
input = {inp_stream = OldLine (i+5) line stream, inp_pos = inp_pos,
inp_filename = inp_filename, inp_tabsize = inp_tabsize}
= (MaybeIdentToken UnboxedNoneToken, input)
= ScanOperator 0 input ['?'] co
| line.[i]=='|'
| line.[i+1]=='J' && line.[i+2]=='u' && line.[i+3]=='s' && line.[i+4]=='t'
&& (i+5==size line || not (IsIdentChar line.[i+5] FunctionContext))
# inp_pos & fp_col = inp_pos.fp_col + 5
input = {inp_stream = OldLine (i+5) line stream, inp_pos = inp_pos,
inp_filename = inp_filename, inp_tabsize = inp_tabsize}
= (MaybeIdentToken OverloadedJustToken, input)
| line.[i+1]=='N' && line.[i+2]=='o' && line.[i+3]=='n' && line.[i+4]=='e'
&& (i+5==size line || not (IsIdentChar line.[i+5] FunctionContext))
# inp_pos & fp_col = inp_pos.fp_col + 5
input = {inp_stream = OldLine (i+5) line stream, inp_pos = inp_pos,
inp_filename = inp_filename, inp_tabsize = inp_tabsize}
= (MaybeIdentToken OverloadedNoneToken, input)
= ScanOperator 0 input ['?'] co
| line.[i]=='^'
| line.[i+1]=='J' && line.[i+2]=='u' && line.[i+3]=='s' && line.[i+4]=='t'
&& (i+5==size line || not (IsIdentChar line.[i+5] FunctionContext))
# inp_pos & fp_col = inp_pos.fp_col + 5
input = {inp_stream = OldLine (i+5) line stream, inp_pos = inp_pos,
inp_filename = inp_filename, inp_tabsize = inp_tabsize}
= (MaybeIdentToken LazyJustToken, input)
| line.[i+1]=='N' && line.[i+2]=='o' && line.[i+3]=='n' && line.[i+4]=='e'
&& (i+5==size line || not (IsIdentChar line.[i+5] FunctionContext))
# inp_pos & fp_col = inp_pos.fp_col + 5
input = {inp_stream = OldLine (i+5) line stream, inp_pos = inp_pos,
inp_filename = inp_filename, inp_tabsize = inp_tabsize}
= (MaybeIdentToken LazyNoneToken, input)
= ScanOperator 0 input ['?'] co
= ScanOperator 0 input ['?'] co
ScanQuestionMark input=:{inp_stream=OldLine i line stream,inp_pos,inp_filename,inp_tabsize} co=:TypeContext
| i==size line || not (isSpecialChar line.[i])
= (MaybeIdentToken StrictMaybeToken, input)
| line.[i]=='#' && (i+1==size line || not (isSpecialChar line.[i+1]))
# inp_pos & fp_col = inp_pos.fp_col + 1
input = {inp_stream = OldLine (i+1) line stream, inp_pos = inp_pos,
inp_filename = inp_filename, inp_tabsize = inp_tabsize}
= (MaybeIdentToken UnboxedMaybeToken, input)
| line.[i]=='^' && (i+1==size line || not (isSpecialChar line.[i+1]))
# inp_pos & fp_col = inp_pos.fp_col + 1
input = {inp_stream = OldLine (i+1) line stream, inp_pos = inp_pos,
inp_filename = inp_filename, inp_tabsize = inp_tabsize}
= (MaybeIdentToken LazyMaybeToken, input)
= ScanOperator 0 input ['?'] co
ScanQuestionMark input co
= ScanOperator 0 input ['?'] co
possibleKeyToken :: !Token ![Char] !ScanContext !Input -> (!Token, !Input)
possibleKeyToken token reversedPrefix context input
# (eof, c, input) = ReadNormalChar input
......@@ -1530,8 +1622,6 @@ GetPreviousChar input=:{inp_stream=OldLine i line stream}
GetPreviousChar input
= (NewLineChar,input)
qw s :== "\"" + s + "\""
instance <<< Token
where
(<<<) f t = f <<< (toString t)
......@@ -1544,10 +1634,20 @@ instance <<< FilePosition
where
(<<<) f {fp_line,fp_col} = f <<< fp_line <<< ";" <<< fp_col
maybeIdentString LazyJustToken = "?^Just"
maybeIdentString LazyNoneToken = "?^None"
maybeIdentString StrictJustToken = "?Just"
maybeIdentString StrictNoneToken = "?None"
maybeIdentString UnboxedJustToken = "?#Just"
maybeIdentString UnboxedNoneToken = "?#None"
maybeIdentString OverloadedJustToken = "?|Just"
maybeIdentString OverloadedNoneToken = "?|None"
instance toString Token
where
toString (IdentToken id) = id // qw id
toString (UnderscoreIdentToken id) = id // qw id
toString (IdentToken id) = id
toString (MaybeIdentToken id) = maybeIdentString id
toString (UnderscoreIdentToken id) = id
toString (IntToken id) = id
toString (RealToken id) = id
toString (StringToken id) = id
......@@ -1658,6 +1758,7 @@ where
equal_args_of_tokens (LetToken l1) (LetToken l2) = l1 == l2
equal_args_of_tokens (SeqLetToken l1) (SeqLetToken l2) = l1 == l2
equal_args_of_tokens (ErrorToken id1) (ErrorToken id2) = id1 == id2
equal_args_of_tokens (MaybeIdentToken id1) (MaybeIdentToken id2) = id1 == id2
equal_args_of_tokens (QualifiedIdentToken module_name1 ident_name1) (QualifiedIdentToken module_name2 ident_name2)
= ident_name1==ident_name2 && module_name1==module_name2
equal_args_of_tokens _ _ = True
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment