I am a little bit confused after I found out that "e.g." is followed by a comma in American English. My confusion stems from the correct placement of this abbreviation. Consider the following sentence:
Usually, these entities are both represented in the source language, e.g., as modules or top-level declarations, and easy to distinguish from each other by the user and the compiler, e.g., as separate files or directories.
When reading this sentence, I stumble upon the commas after the "e.g."s. I could understand it if the sentence was:
Usually, these entities are both represented in the source language, as, e.g., modules or top-level declarations, and easy to distinguish from each other by the user and the compiler, as, e.g., separate files or directories.
The second version reads somewhat slower, there is more emphasis on the ".e.g." as I would like and the meaning of the second "as" might be confused to relate to the "compiler".
Is the first form correct? If so, I wonder what purpose the commas serve? Is the second version different in meaning from the first, or am I reading it wrong?