diff options
author | Paul McGuire <ptmcg@users.noreply.github.com> | 2018-12-23 21:30:40 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-23 21:30:40 -0600 |
commit | 4fba64a079016e6ea62d041f19b7eadd081341e8 (patch) | |
tree | 6c5fdae41cf8b335ff1c64f37856786523e4fd0d /examples/romanNumerals.py | |
parent | 59dfd314c23fd653271bdad37631f0497e8ad748 (diff) | |
parent | de8326d00dffdb500c02839a98330b869c2457f3 (diff) | |
download | pyparsing-git-4fba64a079016e6ea62d041f19b7eadd081341e8.tar.gz |
Merge pull request #55 from jdufresne/ws
Trim trailing white space throughout the project
Diffstat (limited to 'examples/romanNumerals.py')
-rw-r--r-- | examples/romanNumerals.py | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/examples/romanNumerals.py b/examples/romanNumerals.py index 27361f0..536fbb0 100644 --- a/examples/romanNumerals.py +++ b/examples/romanNumerals.py @@ -7,7 +7,7 @@ from pyparsing import * def romanNumeralLiteral(numeralString, value):
return Literal(numeralString).setParseAction(replaceWith(value))
-
+
one = romanNumeralLiteral("I",1)
four = romanNumeralLiteral("IV",4)
five = romanNumeralLiteral("V",5)
@@ -22,8 +22,8 @@ fivehundred = romanNumeralLiteral("D",500) ninehundred = romanNumeralLiteral("CM",900)
onethousand = romanNumeralLiteral("M",1000)
-numeral = ( onethousand | ninehundred | fivehundred | fourhundred |
- onehundred | ninety | fifty | forty | ten | nine | five |
+numeral = ( onethousand | ninehundred | fivehundred | fourhundred |
+ onehundred | ninety | fifty | forty | ten | nine | five |
four | one ).leaveWhitespace()
romanNumeral = OneOrMore(numeral).setParseAction( lambda s,l,t : sum(t) )
@@ -34,7 +34,7 @@ def makeRomanNumeral(n): n -= limit
s += c
return n,s
-
+
ret = ""
while n >= 1000: n,ret = addDigit(n,1000,"M",ret)
while n >= 900: n,ret = addDigit(n, 900,"CM",ret)
@@ -66,9 +66,3 @@ test("XIV") test("XIX")
test("MCMLXXX")
test("MMVI")
-
-
-
-
-
-
|