Skip to content

Conversation

@joemphilips
Copy link
Contributor

Original PR is #684

This creates NBitcoin.Scripting.Parser namespace, and puts Monadic Parser combinator for internal usage.
It does not affect the library's public AP,I nor it has tests. Tests will be done in following PRs.

The API almost completely follows those of Sprache, the biggest difference is that it is generalized against its input type. (Sprache only allows string as an input, but this one will take arbitrary IEnumerable<T> for input.) This is crucial for Miniscript decompilation.

This might be a good candidate for using Span<T> as an input type to improve the speed. But I didn't want to do an early optimization so I didn't.

@joemphilips joemphilips force-pushed the prepare_parser branch 2 times, most recently from c9c9e21 to 54b1b2c Compare May 22, 2019 06:05
@NicolasDorier
Copy link
Collaborator

Awesome, I suggest putting all those classes internal?


namespace NBitcoin.Scripting.Parser
{
public interface IInput<out T>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should be internal ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I would suggest to inherit from IEnumerator<out T> and remove Advance/GetCurrent/GetNext.
Then just make methods returning IInput<out T> before implement IEnumerable<T> and return IInput<T> .

The nice thing is that people can use foreach then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I wonder why this didn't come up to my mind...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been trying to inherit from IEnumerator. But it is not working well :(
It is because that Input for Parser combinator must be immutable. (Advance() will create another instance each time it proceeds)
IEnumerator is only for mutable object.
I think inheriting from IEnumerable and delegate GetEnuemrator call to underlying Source object is enough.

@joemphilips joemphilips force-pushed the prepare_parser branch 3 times, most recently from 2fc36c9 to 493ec7f Compare May 23, 2019 06:44
@knocte
Copy link
Contributor

knocte commented May 23, 2019

IEnumerator is only for mutable object.

Not sure I agree. You could create a specific Enumerator class for this type which is mutable without making your type mutable.

@joemphilips
Copy link
Contributor Author

Not sure I agree. You could create a specific Enumerator class for this type which is mutable without making your type mutable.

You mean make my class inherit from IEnumerable<T> instead of IEnumerator<T> right? That's what I have done here.

@NicolasDorier
Copy link
Collaborator

@joemphilips if my suggestion is not really used and does not make the code more visible, then you can just roll it back.

{
return from nothing in Return<char, string>("")
// dummy so that CultureInfo.CurrentCulture is evaluated later
from dot in String((ci ?? CultureInfo.CurrentCulture).NumberFormat.NumberDecimalSeparator).Text()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no, never use CurrentCulture!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've drop the support for culture-aware decimal.
now it uses InvariantCulture only.

@NicolasDorier
Copy link
Collaborator

Oh actually it is used in the test, seems better.

@NicolasDorier
Copy link
Collaborator

Tests failing rebasing on top of master should fix it

@joemphilips
Copy link
Contributor Author

joemphilips commented May 25, 2019

Rebased but not fixed.

It seems that some parts of codes are using obsolete PubKey.GetAddress

BIP38\BitcoinConfirmationCode.cs(125,58): warning CS0618: 'PubKey.GetAddress(Network)' is obsolete: 'Use GetAddress(ScriptPubKeyType.Legacy, network) instead' [C:\projects\nbitcoin\NBitcoin\NBitcoin.csproj]
BIP38\BitcoinEncryptedSecret.cs(39,49): warning CS0618: 'PubKey.GetAddress(Network)' is obsolete: 'Use GetAddress(ScriptPubKeyType.Legacy, network) instead' [C:\projects\nbitcoin\NBitcoin\NBitcoin.csproj]
BIP38\BitcoinEncryptedSecret.cs(94,49): warning CS0618: 'PubKey.GetAddress(Network)' is obsolete: 'Use GetAddress(ScriptPubKeyType.Legacy, network) instead' [C:\projects\nbitcoin\NBitcoin\NBitcoin.csproj]
BIP38\BitcoinEncryptedSecret.cs(202,27): warning CS0618: 'PubKey.GetAddress(Network)' is obsolete: 'Use GetAddress(ScriptPubKeyType.Legacy, network) instead' [C:\projects\nbitcoin\NBitcoin\NBitcoin.csproj]
BIP38\BitcoinPassphraseCode.cs(236,27): warning CS0618: 'PubKey.GetAddress(Network)' is obsolete: 'Use GetAddress(ScriptPubKeyType.Legacy, network) instead' [C:\projects\nbitcoin\NBitcoin\NBitcoin.csproj]
BIP38\BitcoinConfirmationCode.cs(125,58): warning CS0618: 'PubKey.GetAddress(Network)' is obsolete: 'Use GetAddress(ScriptPubKeyType.Legacy, network) instead' [C:\projects\nbitcoin\NBitcoin\NBitcoin.csproj]
BIP38\BitcoinEncryptedSecret.cs(39,49): warning CS0618: 'PubKey.GetAddress(Network)' is obsolete: 'Use GetAddress(ScriptPubKeyType.Legacy, network) instead' [C:\projects\nbitcoin\NBitcoin\NBitcoin.csproj]
BIP38\BitcoinEncryptedSecret.cs(94,49): warning CS0618: 'PubKey.GetAddress(Network)' is obsolete: 'Use GetAddress(ScriptPubKeyType.Legacy, network) instead' [C:\projects\nbitcoin\NBitcoin\NBitcoin.csproj]
BIP38\BitcoinEncryptedSecret.cs(202,27): warning CS0618: 'PubKey.GetAddress(Network)' is obsolete: 'Use GetAddress(ScriptPubKeyType.Legacy, network) instead' [C:\projects\nbitcoin\NBitcoin\NBitcoin.csproj]
BIP38\BitcoinPassphraseCode.cs(236,27): warning CS0618: 'PubKey.GetAddress(Network)' is obsolete: 'Use GetAddress(ScriptPubKeyType.Legacy, network) instead' 

Should I fix on my side?

@NicolasDorier
Copy link
Collaborator

Yes you can fix... but so strange, on master the build is passing!

* Since in netstandard1.3, string-as-enumerable should be treated bit differently.
@NicolasDorier NicolasDorier merged commit 7531e26 into MetacoSA:master May 27, 2019
@joemphilips joemphilips deleted the prepare_parser branch May 27, 2019 09:58
@NicolasDorier
Copy link
Collaborator

What should I review and merge in priority after @joemphilips ?

@joemphilips
Copy link
Contributor Author

I want you to take a look for #696 since the spec is well formalized than #695 , and it has some changes to an existing objects.

But honestly, I myself am not in hurry so please take your time. @NicolasDorier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants